Move some of the window event handling to the render context

This commit is contained in:
Jarrod Doyle 2023-10-20 11:24:44 +01:00
parent 7fd3897964
commit 9a4bd5d1a0
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
2 changed files with 24 additions and 12 deletions

View File

@ -89,18 +89,16 @@ impl App {
Event::WindowEvent {
ref event,
window_id,
} if window_id == self.render_ctx.window.id() => match event {
} if window_id == self.render_ctx.window.id()
&& !self.render_ctx.handle_window_event(event) =>
{
match event {
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
WindowEvent::Resized(physical_size) => {
self.render_ctx.resize(*physical_size);
}
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();
}

View File

@ -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,
}
}
}