Skip to content

Commit 244d44c

Browse files
committed
Fix RustBoy screensize bug on mobile devices in web.
1 parent a4b2f4d commit 244d44c

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

index.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<html lang="en">
33
<head>
44
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
56
<title>Gameboy Emulator</title>
67
<style>
78
body {
@@ -14,6 +15,12 @@
1415
font-family: sans-serif;
1516
}
1617

18+
#screen-container canvas {
19+
width: 100%;
20+
height: 100%;
21+
image-rendering: pixelated;
22+
}
23+
1724
.gameboy-container {
1825
position: relative;
1926
width: 313px;

src/lib.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use input::{handle_key_pressed_event, handle_key_released_event};
3232
use ppu::RenderTask;
3333
use timer::TimerInfo;
3434

35+
use winit::dpi::LogicalSize;
3536
use winit::event_loop::EventLoopWindowTarget;
3637
use winit::{
3738
dpi::PhysicalSize,
@@ -40,7 +41,6 @@ use winit::{
4041
keyboard::{KeyCode, PhysicalKey},
4142
window::WindowBuilder,
4243
};
43-
4444
// Export main parts of the RustBoy
4545
pub use cpu::CPU;
4646
pub use input::Joypad;
@@ -155,7 +155,13 @@ pub async fn run(
155155
}
156156

157157
let event_loop = EventLoop::new().unwrap();
158-
let window = WindowBuilder::new().build(&event_loop).unwrap();
158+
let window = WindowBuilder::new()
159+
.with_inner_size(LogicalSize::new(
160+
ORIGINAL_SCREEN_WIDTH,
161+
ORIGINAL_SCREEN_HEIGHT,
162+
))
163+
.build(&event_loop)
164+
.unwrap();
159165
window.set_title("RustBoy");
160166

161167
// Add a canvas to the HTML document
@@ -172,11 +178,6 @@ pub async fn run(
172178
})
173179
.expect("Failed to append canvas");
174180
}
175-
// Force a resize event to trigger initial configuration
176-
let _ = window.request_inner_size(PhysicalSize::new(
177-
ORIGINAL_SCREEN_WIDTH,
178-
ORIGINAL_SCREEN_HEIGHT,
179-
));
180181

181182
let mut state = State::new(&window).await;
182183
let mut surface_configured = false;

0 commit comments

Comments
 (0)