diff options
| author | Valentin Popov <valentin@popov.link> | 2026-06-25 06:51:35 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-06-25 10:45:39 +0300 |
| commit | e3c74485f1d3d2aff94de2a12486cf34c4bce0ed (patch) | |
| tree | 21d154715e8a4ca4918bcffc6a2a592833fd27ac | |
| parent | ad21704bccc68c5def0145a733207b249fd82570 (diff) | |
| download | fparkan-e3c74485f1d3d2aff94de2a12486cf34c4bce0ed.tar.xz fparkan-e3c74485f1d3d2aff94de2a12486cf34c4bce0ed.zip | |
feat(platform-winit): bridge native window events
| -rw-r--r-- | adapters/fparkan-platform-winit/src/lib.rs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/adapters/fparkan-platform-winit/src/lib.rs b/adapters/fparkan-platform-winit/src/lib.rs index 729ccb6..19de207 100644 --- a/adapters/fparkan-platform-winit/src/lib.rs +++ b/adapters/fparkan-platform-winit/src/lib.rs @@ -300,6 +300,27 @@ impl WinitWindow { self.apply_event(event); } } + + /// Applies one native `winit` window event to the cached window descriptor state. + pub fn apply_window_event(&mut self, event: &WindowEvent) { + match event { + WindowEvent::Resized(size) => { + self.width = size.width; + self.height = size.height; + self.minimized = size.width == 0 || size.height == 0; + } + WindowEvent::Focused(focused) => { + self.focused = *focused; + } + WindowEvent::Occluded(occluded) => { + self.occluded = *occluded; + } + WindowEvent::ScaleFactorChanged { scale_factor, .. } => { + self.scale = *scale_factor; + } + _ => {} + } + } } impl WindowPort for WinitWindow { @@ -528,6 +549,28 @@ mod tests { assert!(window.is_minimized()); assert!(window.is_occluded()); } + + #[test] + fn window_descriptor_applies_native_window_events() { + let mut window = WinitWindow::synthetic(640, 360); + + window.apply_window_event(&WindowEvent::Resized(winit::dpi::PhysicalSize::new( + 0u32, 720u32, + ))); + window.apply_window_event(&WindowEvent::Focused(false)); + window.apply_window_event(&WindowEvent::Occluded(true)); + + assert_eq!( + window.drawable_size(), + PhysicalSize { + width: 0, + height: 720, + } + ); + assert!(!window.has_focus()); + assert!(window.is_minimized()); + assert!(window.is_occluded()); + } } // SAFETY: no unsafe usage in this crate. |
