From f30a666dc81fdc85d225dc83f1a33e32d5dccbd2 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 23 Jun 2020 06:44:34 +0200 Subject: Decouple `cursor_position` from `Cache` Instead, we ask explicitly for it in the different `update` and `draw` methods. This way, the runtime can derive the logical position of the cursor from the source of truth. --- winit/src/conversion.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'winit/src/conversion.rs') diff --git a/winit/src/conversion.rs b/winit/src/conversion.rs index b887db6e..80727bd8 100644 --- a/winit/src/conversion.rs +++ b/winit/src/conversion.rs @@ -4,7 +4,7 @@ //! [`iced_native`]: https://github.com/hecrj/iced/tree/master/native use crate::{ keyboard::{self, KeyCode, ModifiersState}, - mouse, window, Event, Mode, + mouse, window, Event, Mode, Point, }; /// Converts a winit window event into an iced event. @@ -174,6 +174,16 @@ pub fn modifiers_state( } } +/// Converts a physical cursor position to a logical `Point`. +pub fn cursor_position( + position: winit::dpi::PhysicalPosition, + scale_factor: f64, +) -> Point { + let logical_position = position.to_logical(scale_factor); + + Point::new(logical_position.x, logical_position.y) +} + /// Converts a `VirtualKeyCode` from [`winit`] to an [`iced_native`] key code. /// /// [`winit`]: https://github.com/rust-windowing/winit -- cgit