Merge pull request #239 from hecrj/avoid-moving-winit-event

Convert `WindowEvent` from a reference in `iced_winit`
This commit is contained in:
Héctor Ramón 2020-03-28 13:40:50 +01:00 committed by GitHub
commit ebc9d275a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 14 deletions

View File

@ -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,
) { ) {

View File

@ -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,
) { ) {

View File

@ -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))