add window::Id to Event and Action
This commit is contained in:
parent
974cc6b6f5
commit
0ad53a3d5c
11 changed files with 99 additions and 78 deletions
|
|
@ -10,6 +10,7 @@ use crate::{Event, Point, Position};
|
|||
|
||||
/// Converts a winit window event into an iced event.
|
||||
pub fn window_event(
|
||||
id: window::Id,
|
||||
event: &winit::event::WindowEvent<'_>,
|
||||
scale_factor: f64,
|
||||
modifiers: winit::event::ModifiersState,
|
||||
|
|
@ -20,21 +21,27 @@ pub fn window_event(
|
|||
WindowEvent::Resized(new_size) => {
|
||||
let logical_size = new_size.to_logical(scale_factor);
|
||||
|
||||
Some(Event::Window(window::Event::Resized {
|
||||
width: logical_size.width,
|
||||
height: logical_size.height,
|
||||
}))
|
||||
Some(Event::Window(
|
||||
id,
|
||||
window::Event::Resized {
|
||||
width: logical_size.width,
|
||||
height: logical_size.height,
|
||||
},
|
||||
))
|
||||
}
|
||||
WindowEvent::ScaleFactorChanged { new_inner_size, .. } => {
|
||||
let logical_size = new_inner_size.to_logical(scale_factor);
|
||||
|
||||
Some(Event::Window(window::Event::Resized {
|
||||
width: logical_size.width,
|
||||
height: logical_size.height,
|
||||
}))
|
||||
Some(Event::Window(
|
||||
id,
|
||||
window::Event::Resized {
|
||||
width: logical_size.width,
|
||||
height: logical_size.height,
|
||||
},
|
||||
))
|
||||
}
|
||||
WindowEvent::CloseRequested => {
|
||||
Some(Event::Window(window::Event::CloseRequested))
|
||||
Some(Event::Window(id, window::Event::CloseRequested))
|
||||
}
|
||||
WindowEvent::CursorMoved { position, .. } => {
|
||||
let position = position.to_logical::<f64>(scale_factor);
|
||||
|
|
@ -112,19 +119,22 @@ pub fn window_event(
|
|||
WindowEvent::ModifiersChanged(new_modifiers) => Some(Event::Keyboard(
|
||||
keyboard::Event::ModifiersChanged(self::modifiers(*new_modifiers)),
|
||||
)),
|
||||
WindowEvent::Focused(focused) => Some(Event::Window(if *focused {
|
||||
window::Event::Focused
|
||||
} else {
|
||||
window::Event::Unfocused
|
||||
})),
|
||||
WindowEvent::Focused(focused) => Some(Event::Window(
|
||||
id,
|
||||
if *focused {
|
||||
window::Event::Focused
|
||||
} else {
|
||||
window::Event::Unfocused
|
||||
},
|
||||
)),
|
||||
WindowEvent::HoveredFile(path) => {
|
||||
Some(Event::Window(window::Event::FileHovered(path.clone())))
|
||||
Some(Event::Window(id, window::Event::FileHovered(path.clone())))
|
||||
}
|
||||
WindowEvent::DroppedFile(path) => {
|
||||
Some(Event::Window(window::Event::FileDropped(path.clone())))
|
||||
Some(Event::Window(id, window::Event::FileDropped(path.clone())))
|
||||
}
|
||||
WindowEvent::HoveredFileCancelled => {
|
||||
Some(Event::Window(window::Event::FilesHoveredLeft))
|
||||
Some(Event::Window(id, window::Event::FilesHoveredLeft))
|
||||
}
|
||||
WindowEvent::Touch(touch) => {
|
||||
Some(Event::Touch(touch_event(*touch, scale_factor)))
|
||||
|
|
@ -133,7 +143,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(id, window::Event::Moved { x, y }))
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue