Move some of the window event handling to the render context
This commit is contained in:
parent
7fd3897964
commit
9a4bd5d1a0
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue