Move more event handling to the render context
This commit is contained in:
parent
9a4bd5d1a0
commit
2a6bee18a6
|
@ -84,24 +84,15 @@ impl App {
|
|||
let mut cumulative_dt = 0.0;
|
||||
let mut frames_accumulated = 0.0;
|
||||
let mut last_render_time = Instant::now();
|
||||
self.event_loop
|
||||
.run(move |event, _, control_flow| match event {
|
||||
self.event_loop.run(move |event, _, control_flow| {
|
||||
if !self.render_ctx.handle_window_event(&event, control_flow) {
|
||||
match event {
|
||||
Event::WindowEvent {
|
||||
ref event,
|
||||
window_id,
|
||||
} if window_id == self.render_ctx.window.id()
|
||||
&& !self.render_ctx.handle_window_event(event) =>
|
||||
{
|
||||
match event {
|
||||
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
|
||||
_ => {
|
||||
} if window_id == self.render_ctx.window.id() => {
|
||||
camera_controller.process_events(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
Event::MainEventsCleared => {
|
||||
self.render_ctx.window.request_redraw();
|
||||
}
|
||||
Event::RedrawRequested(_) => {
|
||||
let now = Instant::now();
|
||||
let dt = now - last_render_time;
|
||||
|
@ -129,6 +120,8 @@ impl App {
|
|||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
use winit::{dpi::PhysicalSize, event::WindowEvent, window::Window};
|
||||
use winit::{
|
||||
dpi::PhysicalSize,
|
||||
event::{Event, WindowEvent},
|
||||
event_loop::ControlFlow,
|
||||
window::Window,
|
||||
};
|
||||
|
||||
pub struct Context {
|
||||
pub window: Window,
|
||||
|
@ -78,8 +83,20 @@ impl Context {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn handle_window_event(&mut self, event: &WindowEvent) -> bool {
|
||||
pub fn handle_window_event(
|
||||
&mut self,
|
||||
event: &Event<()>,
|
||||
control_flow: &mut ControlFlow,
|
||||
) -> bool {
|
||||
match event {
|
||||
Event::WindowEvent {
|
||||
ref event,
|
||||
window_id,
|
||||
} if *window_id == self.window.id() => match event {
|
||||
WindowEvent::CloseRequested => {
|
||||
*control_flow = ControlFlow::Exit;
|
||||
true
|
||||
}
|
||||
WindowEvent::Resized(physical_size) => {
|
||||
self.resize(*physical_size);
|
||||
true
|
||||
|
@ -89,6 +106,12 @@ impl Context {
|
|||
true
|
||||
}
|
||||
_ => false,
|
||||
},
|
||||
Event::MainEventsCleared => {
|
||||
self.window.request_redraw();
|
||||
true
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue