diff options
author | 2020-06-23 06:44:34 +0200 | |
---|---|---|
committer | 2020-06-23 06:44:34 +0200 | |
commit | f30a666dc81fdc85d225dc83f1a33e32d5dccbd2 (patch) | |
tree | 579f3a0e8a050447c208282305c3de98f52f694e /winit/src/conversion.rs | |
parent | bbdf558bd7eb3abbf69c922b34075360cd5f12c5 (diff) | |
download | iced-f30a666dc81fdc85d225dc83f1a33e32d5dccbd2.tar.gz iced-f30a666dc81fdc85d225dc83f1a33e32d5dccbd2.tar.bz2 iced-f30a666dc81fdc85d225dc83f1a33e32d5dccbd2.zip |
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.
Diffstat (limited to '')
-rw-r--r-- | winit/src/conversion.rs | 12 |
1 files changed, 11 insertions, 1 deletions
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<f64>, + 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 |