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.
This commit is contained in:
Héctor Ramón Jiménez 2020-06-23 06:44:34 +02:00
parent bbdf558bd7
commit f30a666dc8
6 changed files with 90 additions and 36 deletions

View file

@ -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