From e23e93218c3b67a00637ea7a3a190c9b28379665 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Fri, 27 Mar 2020 22:02:23 +0100 Subject: [PATCH] Convert `WindowEvent` from a reference in `iced_winit` --- examples/integration/src/main.rs | 2 +- winit/src/application.rs | 2 +- winit/src/conversion.rs | 24 ++++++++++++------------ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/examples/integration/src/main.rs b/examples/integration/src/main.rs index 2cb89ffc..1c544449 100644 --- a/examples/integration/src/main.rs +++ b/examples/integration/src/main.rs @@ -85,7 +85,7 @@ pub fn main() { // Map window event to iced event if let Some(event) = iced_winit::conversion::window_event( - event, + &event, window.scale_factor(), modifiers, ) { diff --git a/winit/src/application.rs b/winit/src/application.rs index 891b8f12..a647a1b6 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -378,7 +378,7 @@ pub trait Application: Sized { } if let Some(event) = conversion::window_event( - window_event, + &window_event, size.scale_factor(), modifiers, ) { diff --git a/winit/src/conversion.rs b/winit/src/conversion.rs index 74852876..debaf535 100644 --- a/winit/src/conversion.rs +++ b/winit/src/conversion.rs @@ -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 //! [`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. pub fn window_event( - event: winit::event::WindowEvent<'_>, + event: &winit::event::WindowEvent<'_>, scale_factor: f64, modifiers: winit::event::ModifiersState, ) -> Option { @@ -37,16 +37,16 @@ pub fn window_event( } WindowEvent::MouseInput { button, state, .. } => { Some(Event::Mouse(mouse::Event::Input { - button: mouse_button(button), - state: button_state(state), + button: mouse_button(*button), + state: button_state(*state), })) } WindowEvent::MouseWheel { delta, .. } => match delta { winit::event::MouseScrollDelta::LineDelta(delta_x, delta_y) => { Some(Event::Mouse(mouse::Event::WheelScrolled { delta: mouse::ScrollDelta::Lines { - x: delta_x, - y: delta_y, + x: *delta_x, + y: *delta_y, }, })) } @@ -59,8 +59,8 @@ pub fn window_event( })) } }, - WindowEvent::ReceivedCharacter(c) if !is_private_use_character(c) => { - Some(Event::Keyboard(keyboard::Event::CharacterReceived(c))) + WindowEvent::ReceivedCharacter(c) if !is_private_use_character(*c) => { + Some(Event::Keyboard(keyboard::Event::CharacterReceived(*c))) } WindowEvent::KeyboardInput { input: @@ -71,15 +71,15 @@ pub fn window_event( }, .. } => Some(Event::Keyboard(keyboard::Event::Input { - key_code: key_code(virtual_keycode), - state: button_state(state), + key_code: key_code(*virtual_keycode), + state: button_state(*state), modifiers: modifiers_state(modifiers), })), WindowEvent::HoveredFile(path) => { - Some(Event::Window(window::Event::FileHovered(path))) + Some(Event::Window(window::Event::FileHovered(path.clone()))) } WindowEvent::DroppedFile(path) => { - Some(Event::Window(window::Event::FileDropped(path))) + Some(Event::Window(window::Event::FileDropped(path.clone()))) } WindowEvent::HoveredFileCancelled => { Some(Event::Window(window::Event::FilesHoveredLeft))