diff options
author | tcmal <me@aria.rip> | 2024-08-25 17:44:21 +0100 |
---|---|---|
committer | tcmal <me@aria.rip> | 2024-08-25 17:44:21 +0100 |
commit | 5ad62fff05064a6a025a9b947ebab05ed7770e6c (patch) | |
tree | fe7a61a8c4910f99df878682edfaf2963a9aca59 /stockton-render/src/window.rs | |
parent | 412d09b7ce9afcb812b748a08621ad9ca70a7966 (diff) |
feat(render): handle window resize and close events again
Diffstat (limited to 'stockton-render/src/window.rs')
-rw-r--r-- | stockton-render/src/window.rs | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/stockton-render/src/window.rs b/stockton-render/src/window.rs index ab19a6a..6c4cecd 100644 --- a/stockton-render/src/window.rs +++ b/stockton-render/src/window.rs @@ -18,18 +18,40 @@ use crate::Renderer; use winit::event::Event as WinitEvent; +use winit::event::WindowEvent as WinitWindowEvent; +use winit::event_loop::ControlFlow; -pub struct WindowEvent {} +#[derive(Debug, Clone, Copy)] +pub enum WindowEvent { + SizeChanged, + CloseRequested, +} impl WindowEvent { - pub fn from(_winit_event: &WinitEvent<()>) -> WindowEvent { + pub fn from(winit_event: &WinitEvent<()>) -> Option<WindowEvent> { // TODO - WindowEvent {} + match winit_event { + WinitEvent::WindowEvent { event, .. } => match event { + WinitWindowEvent::CloseRequested => Some(WindowEvent::CloseRequested), + WinitWindowEvent::Resized(_) => Some(WindowEvent::SizeChanged), + _ => None, + }, + _ => None, + } } } #[system] /// A system to process the window events sent to renderer by the winit event loop. -pub fn process_window_events(#[resource] _renderer: &mut Renderer<'static>) { - println!("processing window events..."); +pub fn process_window_events(#[resource] renderer: &mut Renderer<'static>) { + while let Ok(event) = renderer.window_events.try_recv() { + match event { + WindowEvent::SizeChanged => renderer.resize(), + WindowEvent::CloseRequested => { + let mut flow = renderer.update_control_flow.write().unwrap(); + // TODO: Let everything know this is our last frame + *flow = ControlFlow::Exit; + } + }; + } } |