diff options
author | 2020-03-19 12:17:16 +0100 | |
---|---|---|
committer | 2020-03-19 12:17:16 +0100 | |
commit | d3572e1b819ff4d40de4f39f48eab71b9d0d4d5e (patch) | |
tree | 80d635749e4941004055f16a7ca5c35e11f3caa9 /winit | |
parent | e19a07d40049f40f36d879a498fab4ce63778b27 (diff) | |
download | iced-d3572e1b819ff4d40de4f39f48eab71b9d0d4d5e.tar.gz iced-d3572e1b819ff4d40de4f39f48eab71b9d0d4d5e.tar.bz2 iced-d3572e1b819ff4d40de4f39f48eab71b9d0d4d5e.zip |
Turn `Touch` into a struct and add finger id
Diffstat (limited to 'winit')
-rw-r--r-- | winit/src/conversion.rs | 51 |
1 files changed, 23 insertions, 28 deletions
diff --git a/winit/src/conversion.rs b/winit/src/conversion.rs index 2fc76c9d..1d008d05 100644 --- a/winit/src/conversion.rs +++ b/winit/src/conversion.rs @@ -5,9 +5,9 @@ use crate::{ input::{ keyboard::{self, KeyCode, ModifiersState}, - mouse, touch, ButtonState, + mouse, touch, ButtonState, Touch, }, - window, Event, Mode, MouseCursor, + window, Event, Mode, MouseCursor, Point, }; /// Converts a winit window event into an iced event. @@ -31,8 +31,7 @@ pub fn window_event( let position = position.to_logical::<f64>(scale_factor); Some(Event::Mouse(mouse::Event::CursorMoved { - x: position.x as f32, - y: position.y as f32, + position: Point::new(position.x as f32, position.y as f32), })) } WindowEvent::MouseInput { button, state, .. } => { @@ -84,9 +83,7 @@ pub fn window_event( WindowEvent::HoveredFileCancelled => { Some(Event::Window(window::Event::FilesHoveredLeft)) } - WindowEvent::Touch(touch) => { - Some(Event::Touch(touch_event(touch))) - } + WindowEvent::Touch(touch) => Some(Event::Touch(touch_event(touch))), _ => None, } } @@ -162,6 +159,25 @@ pub fn modifiers_state( } } +/// Converts a `Touch` from [`winit`] to an [`iced_native`] touch event. +/// +/// [`winit`]: https://github.com/rust-windowing/winit +/// [`iced_native`]: https://github.com/hecrj/iced/tree/master/native +pub fn touch_event(touch: winit::event::Touch) -> Touch { + let phase = match touch.phase { + winit::event::TouchPhase::Started => touch::Phase::Started, + winit::event::TouchPhase::Moved => touch::Phase::Moved, + winit::event::TouchPhase::Ended => touch::Phase::Ended, + winit::event::TouchPhase::Cancelled => touch::Phase::Canceled, + }; + + Touch { + finger: touch::Finger(touch.id), + position: Point::new(touch.location.x as f32, touch.location.y as f32), + phase, + } +} + /// Converts a `VirtualKeyCode` from [`winit`] to an [`iced_native`] key code. /// /// [`winit`]: https://github.com/rust-windowing/winit @@ -345,24 +361,3 @@ pub(crate) fn is_private_use_character(c: char) -> bool { _ => false, } } -pub(crate) fn touch_event(touch: winit::event::Touch) -> touch::Touch { - let location = touch.location; - match touch.phase { - winit::event::TouchPhase::Started => touch::Touch::Started { - x: location.x as f32, - y: location.y as f32, - }, - winit::event::TouchPhase::Ended => touch::Touch::Ended { - x: location.x as f32, - y: location.y as f32, - }, - winit::event::TouchPhase::Moved => touch::Touch::Moved { - x: location.x as f32, - y: location.y as f32, - }, - winit::event::TouchPhase::Cancelled => touch::Touch::Cancelled { - x: location.x as f32, - y: location.y as f32, - }, - } -} |