Skip to content

Commit a3d9cf2

Browse files
authored
Merge pull request #2505 from iced-rs/window-resize-events
Add `resize_events` subscription to `window` module
2 parents 1eabd38 + a108b2e commit a3d9cf2

3 files changed

Lines changed: 16 additions & 15 deletions

File tree

core/src/window/event.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,10 @@ pub enum Event {
2323
Closed,
2424

2525
/// A window was moved.
26-
Moved {
27-
/// The new logical x location of the window
28-
x: i32,
29-
/// The new logical y location of the window
30-
y: i32,
31-
},
26+
Moved(Point),
3227

3328
/// A window was resized.
34-
Resized {
35-
/// The new logical width of the window
36-
width: u32,
37-
/// The new logical height of the window
38-
height: u32,
39-
},
29+
Resized(Size),
4030

4131
/// A window redraw was requested.
4232
///

runtime/src/window.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,17 @@ pub fn close_events() -> Subscription<Id> {
194194
})
195195
}
196196

197+
/// Subscribes to all [`Event::Resized`] occurrences in the running application.
198+
pub fn resize_events() -> Subscription<(Id, Size)> {
199+
event::listen_with(|event, _status, id| {
200+
if let crate::core::Event::Window(Event::Resized(size)) = event {
201+
Some((id, size))
202+
} else {
203+
None
204+
}
205+
})
206+
}
207+
197208
/// Subscribes to all [`Event::CloseRequested`] occurences in the running application.
198209
pub fn close_requests() -> Subscription<Id> {
199210
event::listen_with(|event, _status, id| {

winit/src/conversion.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ pub fn window_event(
132132
WindowEvent::Resized(new_size) => {
133133
let logical_size = new_size.to_logical(scale_factor);
134134

135-
Some(Event::Window(window::Event::Resized {
135+
Some(Event::Window(window::Event::Resized(Size {
136136
width: logical_size.width,
137137
height: logical_size.height,
138-
}))
138+
})))
139139
}
140140
WindowEvent::CloseRequested => {
141141
Some(Event::Window(window::Event::CloseRequested))
@@ -277,7 +277,7 @@ pub fn window_event(
277277
let winit::dpi::LogicalPosition { x, y } =
278278
position.to_logical(scale_factor);
279279

280-
Some(Event::Window(window::Event::Moved { x, y }))
280+
Some(Event::Window(window::Event::Moved(Point::new(x, y))))
281281
}
282282
_ => None,
283283
}

0 commit comments

Comments
 (0)