diff --git a/src/core/app.rs b/src/core/app.rs index ecf566d..5566c16 100644 --- a/src/core/app.rs +++ b/src/core/app.rs @@ -89,18 +89,16 @@ impl App { Event::WindowEvent { ref event, window_id, - } if window_id == self.render_ctx.window.id() => match event { - WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit, - WindowEvent::Resized(physical_size) => { - self.render_ctx.resize(*physical_size); + } if window_id == self.render_ctx.window.id() + && !self.render_ctx.handle_window_event(event) => + { + match event { + WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit, + _ => { + camera_controller.process_events(event); + } } - WindowEvent::ScaleFactorChanged { new_inner_size, .. } => { - self.render_ctx.resize(**new_inner_size); - } - _ => { - camera_controller.process_events(event); - } - }, + } Event::MainEventsCleared => { self.render_ctx.window.request_redraw(); } diff --git a/src/gfx/context.rs b/src/gfx/context.rs index 3e8b6c6..e1582ed 100644 --- a/src/gfx/context.rs +++ b/src/gfx/context.rs @@ -1,4 +1,4 @@ -use winit::{dpi::PhysicalSize, window::Window}; +use winit::{dpi::PhysicalSize, event::WindowEvent, window::Window}; pub struct Context { pub window: Window, @@ -77,4 +77,18 @@ impl Context { self.surface.configure(&self.device, &self.surface_config); } } + + pub fn handle_window_event(&mut self, event: &WindowEvent) -> bool { + match event { + WindowEvent::Resized(physical_size) => { + self.resize(*physical_size); + true + } + WindowEvent::ScaleFactorChanged { new_inner_size, .. } => { + self.resize(**new_inner_size); + true + } + _ => false, + } + } }