Convert WindowEvent
from a reference in iced_winit
This commit is contained in:
parent
4d3afe2f0c
commit
e23e93218c
@ -85,7 +85,7 @@ pub fn main() {
|
|||||||
|
|
||||||
// Map window event to iced event
|
// Map window event to iced event
|
||||||
if let Some(event) = iced_winit::conversion::window_event(
|
if let Some(event) = iced_winit::conversion::window_event(
|
||||||
event,
|
&event,
|
||||||
window.scale_factor(),
|
window.scale_factor(),
|
||||||
modifiers,
|
modifiers,
|
||||||
) {
|
) {
|
||||||
|
@ -378,7 +378,7 @@ pub trait Application: Sized {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let Some(event) = conversion::window_event(
|
if let Some(event) = conversion::window_event(
|
||||||
window_event,
|
&window_event,
|
||||||
size.scale_factor(),
|
size.scale_factor(),
|
||||||
modifiers,
|
modifiers,
|
||||||
) {
|
) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
//! Convert [`winit`] types to [`iced_native`] types, and viceversa.
|
//! Convert [`winit`] types into [`iced_native`] types, and viceversa.
|
||||||
//!
|
//!
|
||||||
//! [`winit`]: https://github.com/rust-windowing/winit
|
//! [`winit`]: https://github.com/rust-windowing/winit
|
||||||
//! [`iced_native`]: https://github.com/hecrj/iced/tree/master/native
|
//! [`iced_native`]: https://github.com/hecrj/iced/tree/master/native
|
||||||
@ -12,7 +12,7 @@ use crate::{
|
|||||||
|
|
||||||
/// Converts a winit window event into an iced event.
|
/// Converts a winit window event into an iced event.
|
||||||
pub fn window_event(
|
pub fn window_event(
|
||||||
event: winit::event::WindowEvent<'_>,
|
event: &winit::event::WindowEvent<'_>,
|
||||||
scale_factor: f64,
|
scale_factor: f64,
|
||||||
modifiers: winit::event::ModifiersState,
|
modifiers: winit::event::ModifiersState,
|
||||||
) -> Option<Event> {
|
) -> Option<Event> {
|
||||||
@ -37,16 +37,16 @@ pub fn window_event(
|
|||||||
}
|
}
|
||||||
WindowEvent::MouseInput { button, state, .. } => {
|
WindowEvent::MouseInput { button, state, .. } => {
|
||||||
Some(Event::Mouse(mouse::Event::Input {
|
Some(Event::Mouse(mouse::Event::Input {
|
||||||
button: mouse_button(button),
|
button: mouse_button(*button),
|
||||||
state: button_state(state),
|
state: button_state(*state),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
WindowEvent::MouseWheel { delta, .. } => match delta {
|
WindowEvent::MouseWheel { delta, .. } => match delta {
|
||||||
winit::event::MouseScrollDelta::LineDelta(delta_x, delta_y) => {
|
winit::event::MouseScrollDelta::LineDelta(delta_x, delta_y) => {
|
||||||
Some(Event::Mouse(mouse::Event::WheelScrolled {
|
Some(Event::Mouse(mouse::Event::WheelScrolled {
|
||||||
delta: mouse::ScrollDelta::Lines {
|
delta: mouse::ScrollDelta::Lines {
|
||||||
x: delta_x,
|
x: *delta_x,
|
||||||
y: delta_y,
|
y: *delta_y,
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
@ -59,8 +59,8 @@ pub fn window_event(
|
|||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
WindowEvent::ReceivedCharacter(c) if !is_private_use_character(c) => {
|
WindowEvent::ReceivedCharacter(c) if !is_private_use_character(*c) => {
|
||||||
Some(Event::Keyboard(keyboard::Event::CharacterReceived(c)))
|
Some(Event::Keyboard(keyboard::Event::CharacterReceived(*c)))
|
||||||
}
|
}
|
||||||
WindowEvent::KeyboardInput {
|
WindowEvent::KeyboardInput {
|
||||||
input:
|
input:
|
||||||
@ -71,15 +71,15 @@ pub fn window_event(
|
|||||||
},
|
},
|
||||||
..
|
..
|
||||||
} => Some(Event::Keyboard(keyboard::Event::Input {
|
} => Some(Event::Keyboard(keyboard::Event::Input {
|
||||||
key_code: key_code(virtual_keycode),
|
key_code: key_code(*virtual_keycode),
|
||||||
state: button_state(state),
|
state: button_state(*state),
|
||||||
modifiers: modifiers_state(modifiers),
|
modifiers: modifiers_state(modifiers),
|
||||||
})),
|
})),
|
||||||
WindowEvent::HoveredFile(path) => {
|
WindowEvent::HoveredFile(path) => {
|
||||||
Some(Event::Window(window::Event::FileHovered(path)))
|
Some(Event::Window(window::Event::FileHovered(path.clone())))
|
||||||
}
|
}
|
||||||
WindowEvent::DroppedFile(path) => {
|
WindowEvent::DroppedFile(path) => {
|
||||||
Some(Event::Window(window::Event::FileDropped(path)))
|
Some(Event::Window(window::Event::FileDropped(path.clone())))
|
||||||
}
|
}
|
||||||
WindowEvent::HoveredFileCancelled => {
|
WindowEvent::HoveredFileCancelled => {
|
||||||
Some(Event::Window(window::Event::FilesHoveredLeft))
|
Some(Event::Window(window::Event::FilesHoveredLeft))
|
||||||
|
Loading…
Reference in New Issue
Block a user