diff options
| author | Valentin Popov <valentin@popov.link> | 2026-06-25 06:49:19 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-06-25 10:45:39 +0300 |
| commit | ad21704bccc68c5def0145a733207b249fd82570 (patch) | |
| tree | f4a2abcadb05e982bf1c30c1699340a3f3184a6e | |
| parent | 95391a05c6bf1a8ab32d3decef5c49c69ecf258f (diff) | |
| download | fparkan-ad21704bccc68c5def0145a733207b249fd82570.tar.xz fparkan-ad21704bccc68c5def0145a733207b249fd82570.zip | |
feat(platform-winit): apply lifecycle state updates
| -rw-r--r-- | adapters/fparkan-platform-winit/src/lib.rs | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/adapters/fparkan-platform-winit/src/lib.rs b/adapters/fparkan-platform-winit/src/lib.rs index d11b523..729ccb6 100644 --- a/adapters/fparkan-platform-winit/src/lib.rs +++ b/adapters/fparkan-platform-winit/src/lib.rs @@ -265,6 +265,41 @@ impl WinitWindow { pub const fn default_render_request() -> RenderRequest { RenderRequest::conservative() } + + /// Applies one platform event to the cached window descriptor state. + pub fn apply_event(&mut self, event: &PlatformEvent) { + match event { + PlatformEvent::Resize { width, height } => { + self.width = *width; + self.height = *height; + } + PlatformEvent::DpiChanged { scale } => { + self.scale = *scale; + } + PlatformEvent::FocusChanged { focused } => { + self.focused = *focused; + } + PlatformEvent::Minimized { minimized } => { + self.minimized = *minimized; + } + PlatformEvent::Occluded { occluded } => { + self.occluded = *occluded; + } + PlatformEvent::Suspended + | PlatformEvent::Resumed + | PlatformEvent::QuitRequested + | PlatformEvent::KeyboardInput { .. } + | PlatformEvent::MouseInput { .. } + | PlatformEvent::CursorMoved { .. } => {} + } + } + + /// Applies a sequence of platform events to the cached window descriptor state. + pub fn apply_events<'a>(&mut self, events: impl IntoIterator<Item = &'a PlatformEvent>) { + for event in events { + self.apply_event(event); + } + } } impl WindowPort for WinitWindow { @@ -464,6 +499,35 @@ mod tests { assert!(events.contains(&PlatformEvent::Minimized { minimized: false })); Ok(()) } + + #[test] + fn window_descriptor_applies_lifecycle_and_resize_events() { + let mut window = WinitWindow::synthetic(640, 360); + let events = [ + PlatformEvent::Resize { + width: 1280, + height: 720, + }, + PlatformEvent::DpiChanged { scale: 2.0 }, + PlatformEvent::FocusChanged { focused: false }, + PlatformEvent::Minimized { minimized: true }, + PlatformEvent::Occluded { occluded: true }, + ]; + + window.apply_events(events.iter()); + + assert_eq!( + window.drawable_size(), + PhysicalSize { + width: 1280, + height: 720, + } + ); + assert_eq!(window.dpi_scale(), 2.0); + assert!(!window.has_focus()); + assert!(window.is_minimized()); + assert!(window.is_occluded()); + } } // SAFETY: no unsafe usage in this crate. |
