Skip to content

Commit d7d0d3c

Browse files
alejandradealejandrade
andauthored
Configurations that allow user to control the screen size for the game. (#25)
* Configurations that allow user to control the screen size for the game. * fix formatting issues * mutable error * brought back allow unused mut --------- Co-authored-by: alejandrade <alejandrade+noreply@users.noreply.github.com>
1 parent 70c224f commit d7d0d3c

2 files changed

Lines changed: 34 additions & 5 deletions

File tree

crates/egor_app/src/lib.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@ use crate::{input::Input, time::FrameTimer};
1515

1616
pub struct AppConfig {
1717
pub title: String,
18+
pub width: u32,
19+
pub height: u32,
20+
pub resizable: bool,
1821
}
1922

2023
impl Default for AppConfig {
2124
fn default() -> Self {
2225
Self {
2326
title: "Egor App".to_string(),
27+
width: 800,
28+
height: 600,
29+
resizable: true,
2430
}
2531
}
2632
}
@@ -66,15 +72,21 @@ impl<R, H: AppHandler<R> + 'static> ApplicationHandler<(R, H)> for AppRunner<R,
6672
// Called when window is ready; initializes the resource async (wasm) or sync (native)
6773
if let Some(proxy) = self.proxy.take() {
6874
let win_attrs = {
75+
use winit::dpi::PhysicalSize;
76+
77+
#[allow(unused_mut)]
78+
let mut attrs = Window::default_attributes()
79+
.with_title(&self.config.title)
80+
.with_inner_size(PhysicalSize::new(self.config.width, self.config.height))
81+
.with_resizable(self.config.resizable);
82+
6983
#[cfg(target_arch = "wasm32")]
7084
{
7185
use winit::platform::web::WindowAttributesExtWebSys;
72-
Window::default_attributes()
73-
.with_title(&self.config.title)
74-
.with_append(true)
86+
attrs = attrs.with_append(true);
7587
}
76-
#[cfg(not(target_arch = "wasm32"))]
77-
Window::default_attributes().with_title(&self.config.title)
88+
89+
attrs
7890
};
7991
let window = Arc::new(event_loop.create_window(win_attrs).unwrap());
8092
self.window = Some(window.clone());

crates/egor_glue/src/app.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,23 @@ impl App {
4747
self
4848
}
4949

50+
/// Set window size (width, height in pixels)
51+
pub fn screen_size(mut self, width: u32, height: u32) -> Self {
52+
if let Some(c) = self.config.as_mut() {
53+
c.width = width;
54+
c.height = height;
55+
}
56+
self
57+
}
58+
59+
/// Enable or disable window resizing (defaults to true)
60+
pub fn resizable(mut self, resizable: bool) -> Self {
61+
if let Some(c) = self.config.as_mut() {
62+
c.resizable = resizable;
63+
}
64+
self
65+
}
66+
5067
/// Enable or disable vsync
5168
pub fn vsync(mut self, enabled: bool) -> Self {
5269
self.vsync = enabled;

0 commit comments

Comments
 (0)