diff options
author | 2020-12-15 06:58:15 +0100 | |
---|---|---|
committer | 2020-12-15 06:58:15 +0100 | |
commit | 277ae74d6817ee6192b5f7a44de19dcbdf8d58f7 (patch) | |
tree | 64d2f7683e9b465b4e85d8e12a5f01f354654fe1 /winit | |
parent | 70164f68a6cfca6f7c86cb5cb46e7b2b1f08cf2c (diff) | |
download | iced-277ae74d6817ee6192b5f7a44de19dcbdf8d58f7.tar.gz iced-277ae74d6817ee6192b5f7a44de19dcbdf8d58f7.tar.bz2 iced-277ae74d6817ee6192b5f7a44de19dcbdf8d58f7.zip |
Produce logical coordinates for `touch::Event`
Diffstat (limited to 'winit')
-rw-r--r-- | winit/src/conversion.rs | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/winit/src/conversion.rs b/winit/src/conversion.rs index 7a6ab2de..f073c474 100644 --- a/winit/src/conversion.rs +++ b/winit/src/conversion.rs @@ -118,7 +118,9 @@ 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, scale_factor))) + } _ => None, } } @@ -207,9 +209,16 @@ pub fn cursor_position( /// /// [`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::Event { +pub fn touch_event( + touch: winit::event::Touch, + scale_factor: f64, +) -> touch::Event { let id = touch::Finger(touch.id); - let position = Point::new(touch.location.x as f32, touch.location.y as f32); + let position = { + let location = touch.location.to_logical::<f64>(scale_factor); + + Point::new(location.x as f32, location.y as f32) + }; match touch.phase { winit::event::TouchPhase::Started => { |