summaryrefslogtreecommitdiffstats
path: root/winit
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-12-15 06:13:19 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-12-15 06:13:19 +0100
commit09110a93b06ae33af6870b4aded8637748cecace (patch)
tree64f4d9a4dde51ef44ea47f94c2079e5346df4c6c /winit
parenta42b3c6998274e75fd10f5ff3cecbdb37b9e3895 (diff)
parent36bdc0be1a0f959c84c18286b85c1ab51be330e6 (diff)
downloadiced-09110a93b06ae33af6870b4aded8637748cecace.tar.gz
iced-09110a93b06ae33af6870b4aded8637748cecace.tar.bz2
iced-09110a93b06ae33af6870b4aded8637748cecace.zip
Merge branch 'ios-support-wip' into feature/touch-support
Diffstat (limited to 'winit')
-rw-r--r--winit/src/conversion.rs27
1 files changed, 24 insertions, 3 deletions
diff --git a/winit/src/conversion.rs b/winit/src/conversion.rs
index 138bc64d..e6fc4b96 100644
--- a/winit/src/conversion.rs
+++ b/winit/src/conversion.rs
@@ -4,7 +4,9 @@
//! [`iced_native`]: https://github.com/hecrj/iced/tree/master/native
use crate::{
keyboard::{self, KeyCode, Modifiers},
- mouse, window, Event, Mode, Point,
+ mouse,
+ touch::{self, Touch},
+ window, Event, Mode, Point,
};
/// Converts a winit window event into an iced event.
@@ -36,8 +38,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::CursorEntered { .. } => {
@@ -118,6 +119,7 @@ pub fn window_event(
WindowEvent::HoveredFileCancelled => {
Some(Event::Window(window::Event::FilesHoveredLeft))
}
+ WindowEvent::Touch(touch) => Some(Event::Touch(touch_event(*touch))),
_ => None,
}
}
@@ -200,6 +202,25 @@ pub fn cursor_position(
Point::new(logical_position.x, logical_position.y)
}
+/// 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