diff options
author | 2024-07-13 12:53:06 +0200 | |
---|---|---|
committer | 2024-07-13 12:53:06 +0200 | |
commit | a108b2eebe210c774d07e436be5d73293dfea9eb (patch) | |
tree | 6adfe63a00c1a8757060a25888cdd3f8070a8ece | |
parent | 1eabd3821928f47451363f7bca3757701182a4c1 (diff) | |
download | iced-a108b2eebe210c774d07e436be5d73293dfea9eb.tar.gz iced-a108b2eebe210c774d07e436be5d73293dfea9eb.tar.bz2 iced-a108b2eebe210c774d07e436be5d73293dfea9eb.zip |
Add `resize_events` subscription to `window` module
-rw-r--r-- | core/src/window/event.rs | 14 | ||||
-rw-r--r-- | runtime/src/window.rs | 11 | ||||
-rw-r--r-- | winit/src/conversion.rs | 6 |
3 files changed, 16 insertions, 15 deletions
diff --git a/core/src/window/event.rs b/core/src/window/event.rs index a14d127f..c9532e0d 100644 --- a/core/src/window/event.rs +++ b/core/src/window/event.rs @@ -23,20 +23,10 @@ pub enum Event { Closed, /// A window was moved. - Moved { - /// The new logical x location of the window - x: i32, - /// The new logical y location of the window - y: i32, - }, + Moved(Point), /// A window was resized. - Resized { - /// The new logical width of the window - width: u32, - /// The new logical height of the window - height: u32, - }, + Resized(Size), /// A window redraw was requested. /// diff --git a/runtime/src/window.rs b/runtime/src/window.rs index 815827d1..ee03f84f 100644 --- a/runtime/src/window.rs +++ b/runtime/src/window.rs @@ -194,6 +194,17 @@ pub fn close_events() -> Subscription<Id> { }) } +/// Subscribes to all [`Event::Resized`] occurrences in the running application. +pub fn resize_events() -> Subscription<(Id, Size)> { + event::listen_with(|event, _status, id| { + if let crate::core::Event::Window(Event::Resized(size)) = event { + Some((id, size)) + } else { + None + } + }) +} + /// Subscribes to all [`Event::CloseRequested`] occurences in the running application. pub fn close_requests() -> Subscription<Id> { event::listen_with(|event, _status, id| { diff --git a/winit/src/conversion.rs b/winit/src/conversion.rs index 0ed10c88..e88ff84d 100644 --- a/winit/src/conversion.rs +++ b/winit/src/conversion.rs @@ -132,10 +132,10 @@ pub fn window_event( WindowEvent::Resized(new_size) => { let logical_size = new_size.to_logical(scale_factor); - Some(Event::Window(window::Event::Resized { + Some(Event::Window(window::Event::Resized(Size { width: logical_size.width, height: logical_size.height, - })) + }))) } WindowEvent::CloseRequested => { Some(Event::Window(window::Event::CloseRequested)) @@ -277,7 +277,7 @@ pub fn window_event( let winit::dpi::LogicalPosition { x, y } = position.to_logical(scale_factor); - Some(Event::Window(window::Event::Moved { x, y })) + Some(Event::Window(window::Event::Moved(Point::new(x, y)))) } _ => None, } |