diff options
| author | LLLL Colonq <llll@colonq> | 2025-02-17 17:37:07 -0500 |
|---|---|---|
| committer | LLLL Colonq <llll@colonq> | 2025-02-17 17:37:07 -0500 |
| commit | 3c56138527b9b6baa6a6b23733cd54b4d281170f (patch) | |
| tree | ffd68c93f5455f47ef31b37a2395b5bf1d3336a2 /src/context.rs | |
| parent | f5d5478c0ca8e0a512c17206e78e077e7aac1e58 (diff) | |
NORESIZE option
Diffstat (limited to 'src/context.rs')
| -rw-r--r-- | src/context.rs | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/src/context.rs b/src/context.rs index 502bbdb..2171053 100644 --- a/src/context.rs +++ b/src/context.rs @@ -17,6 +17,7 @@ extern { pub struct Context { pub render_width: f32, pub render_height: f32, + pub resize: bool, pub glfw: std::cell::RefCell<glfw::Glfw>, pub window: std::cell::RefCell<glfw::PWindow>, pub gl: glow::Context, @@ -29,6 +30,7 @@ pub struct Context { pub struct Context { pub render_width: f32, pub render_height: f32, + pub resize: bool, pub window: winit::window::Window, pub gl: glow::Context, pub emptyvao: glow::VertexArray, @@ -50,12 +52,13 @@ impl Context { } #[cfg(not(target_arch = "wasm32"))] - pub fn new(glfw: std::cell::RefCell<glfw::Glfw>, window: std::cell::RefCell<glfw::PWindow>, gl: glow::Context, render_width: f32, render_height: f32) -> Self { + pub fn new(glfw: std::cell::RefCell<glfw::Glfw>, window: std::cell::RefCell<glfw::PWindow>, gl: glow::Context, render_width: f32, render_height: f32, resize: bool) -> Self { let emptyvao = unsafe { gl.create_vertex_array().expect("failed to initialize vao") }; let ret = Self { render_width, render_height, + resize, glfw, window, gl, emptyvao, @@ -66,7 +69,7 @@ impl Context { } #[cfg(target_arch = "wasm32")] - pub fn new(window: winit::window::Window, gl: glow::Context, render_width: f32, render_height: f32) -> Self { + pub fn new(window: winit::window::Window, gl: glow::Context, render_width: f32, render_height: f32, resize: bool) -> Self { let emptyvao = unsafe { gl.create_vertex_array().expect("failed to initialize vao") }; @@ -76,6 +79,7 @@ impl Context { let ret = Self { render_width, render_height, + resize, window, gl, emptyvao, @@ -107,24 +111,26 @@ impl Context { #[cfg(target_arch = "wasm32")] pub fn maximize_canvas(&self) { - web_sys::window() - .and_then(|win| win.document()) - .and_then(|doc| { - let inner_size = { - let browser_window = doc.default_view() - .or_else(web_sys::window) - .unwrap(); - winit::dpi::PhysicalSize::new( - browser_window.inner_width().unwrap().as_f64().unwrap(), - browser_window.inner_height().unwrap().as_f64().unwrap(), - ) - }; - self.window.canvas().unwrap().set_width(inner_size.width as _); - self.window.canvas().unwrap().set_height(inner_size.height as _); - let _ = self.window.request_inner_size(inner_size); - Some(()) - }) - .expect("failed to resize canvas"); + if self.resize { + web_sys::window() + .and_then(|win| win.document()) + .and_then(|doc| { + let inner_size = { + let browser_window = doc.default_view() + .or_else(web_sys::window) + .unwrap(); + winit::dpi::PhysicalSize::new( + browser_window.inner_width().unwrap().as_f64().unwrap(), + browser_window.inner_height().unwrap().as_f64().unwrap(), + ) + }; + self.window.canvas().unwrap().set_width(inner_size.width as _); + self.window.canvas().unwrap().set_height(inner_size.height as _); + let _ = self.window.request_inner_size(inner_size); + Some(()) + }) + .expect("failed to resize canvas"); + } } #[cfg(target_arch = "wasm32")] |
