Skip to content

Commit d4eb6f4

Browse files
committed
Make webpage prettier
1 parent 003c447 commit d4eb6f4

4 files changed

Lines changed: 77 additions & 9 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ The app also runs in the web using WASM.
1919
- [Binjgb - A Game Boy emulator implemented in C with good trace
2020
logging for comparing logs instruction by instruction](https://github.com/binji/binjgb)
2121

22+
- [Image Source for GameBoy Image](https://commons.wikimedia.org/wiki/File:Gameboy.svg)
23+
2224
## How to Start
2325

2426
TBD

gameboy.png

164 KB
Loading

index.html

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,82 @@
44
<meta charset="utf-8">
55
<title>Gameboy Emulator</title>
66
<style>
7-
canvas {
8-
background-color: black;
7+
body {
8+
margin: 0;
9+
padding: 20px;
10+
display: flex;
11+
flex-direction: column;
12+
align-items: center;
13+
background-color: #2c2c2c;
14+
font-family: sans-serif;
15+
}
16+
17+
.gameboy-container {
18+
position: relative;
19+
width: 313px;
20+
height: 515px;
21+
z-index: 2;
22+
}
23+
24+
.screen-container {
25+
position: absolute;
26+
top: 13%;
27+
left: 24%;
28+
width: 160px;
29+
height: 144px;
30+
image-rendering: pixelated;
31+
z-index: 2;
32+
}
33+
34+
.gameboy-frame {
35+
position: absolute;
36+
top: 0;
37+
left: 0;
38+
width: 100%;
39+
height: 100%;
40+
z-index: -1;
41+
pointer-events: none;
42+
}
43+
44+
.file-input-label {
45+
margin: 20px 0;
46+
padding: 10px 20px;
47+
background-color: #4CAF50;
48+
color: white;
49+
border-radius: 5px;
50+
cursor: pointer;
51+
transition: background-color 0.3s;
52+
}
53+
54+
.file-input-label:hover {
55+
background-color: #45a049;
56+
}
57+
58+
#rom-input {
59+
display: none;
60+
}
61+
62+
h1 {
63+
color: #fff;
64+
text-shadow: 2px 2px #000;
65+
margin-bottom: 30px;
966
}
1067
</style>
1168
</head>
1269
<body id="emulator-body">
70+
<h1>RustBoy 🦀</h1>
71+
72+
<label class="file-input-label" for="rom-input">
73+
Load ROM
74+
</label>
1375
<input type="file" id="rom-input"/>
14-
<canvas id="screen" width="160" height="144"></canvas>
76+
77+
<div class="gameboy-container" id="gameboy-container">
78+
<img src="gameboy.png" class="gameboy-frame" alt="GameBoy Frame">
79+
<div class="screen-container" id="screen-container">
80+
</div>
81+
</div>
82+
1583
<script type="module">
1684
import initSync, {run} from './pkg/rustboy.js';
1785

@@ -21,13 +89,13 @@
2189

2290
const romInput = document.getElementById("rom-input");
2391
romInput.addEventListener("change", (event) => {
92+
console.log("Loading ROM...");
2493
const file = event.target.files[0];
2594
if (!file) return;
2695

2796
const reader = new FileReader();
2897
reader.onload = async () => {
2998
const arrayBuffer = reader.result;
30-
// Convert ArrayBuffer to Uint8Array so it can be passed to wasm.
3199
const romData = new Uint8Array(arrayBuffer);
32100
await run(
33101
false, // headless
@@ -47,4 +115,4 @@
47115
main();
48116
</script>
49117
</body>
50-
</html>
118+
</html>

src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,15 +187,13 @@ pub async fn run(
187187
// Add a canvas to the HTML document
188188
#[cfg(target_arch = "wasm32")]
189189
{
190-
// Winit prevents sizing with CSS, so we have to set
191-
// the size manually when on web.
192190
use winit::platform::web::WindowExtWebSys;
193191
let canvas = window.canvas().expect("Canvas not found");
194-
canvas.style().set_css_text("width: 160px; height: 144px;"); // Enforce size
195192
web_sys::window()
196193
.and_then(|win| win.document())
197194
.and_then(|doc| {
198-
let dst = doc.get_element_by_id("emulator-body")?;
195+
// Target the container div instead of the body
196+
let dst = doc.get_element_by_id("screen-container")?;
199197
dst.append_child(&web_sys::Element::from(canvas)).ok()
200198
})
201199
.expect("Failed to append canvas");

0 commit comments

Comments
 (0)