diff options
author | 2020-06-23 06:44:34 +0200 | |
---|---|---|
committer | 2020-06-23 06:44:34 +0200 | |
commit | f30a666dc81fdc85d225dc83f1a33e32d5dccbd2 (patch) | |
tree | 579f3a0e8a050447c208282305c3de98f52f694e /glutin | |
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 'glutin')
-rw-r--r-- | glutin/src/application.rs | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/glutin/src/application.rs b/glutin/src/application.rs index 93877734..3be9b65f 100644 --- a/glutin/src/application.rs +++ b/glutin/src/application.rs @@ -70,6 +70,7 @@ pub fn run<A, E, C>( }; let clipboard = Clipboard::new(&context.window()); + let mut cursor_position = glutin::dpi::PhysicalPosition::new(-1.0, -1.0); let mut mouse_interaction = mouse::Interaction::default(); let mut modifiers = glutin::event::ModifiersState::default(); @@ -90,6 +91,7 @@ pub fn run<A, E, C>( let mut state = program::State::new( application, viewport.logical_size(), + conversion::cursor_position(cursor_position, viewport.scale_factor()), &mut renderer, &mut debug, ); @@ -103,8 +105,12 @@ pub fn run<A, E, C>( let command = runtime.enter(|| { state.update( - clipboard.as_ref().map(|c| c as _), viewport.logical_size(), + conversion::cursor_position( + cursor_position, + viewport.scale_factor(), + ), + clipboard.as_ref().map(|c| c as _), &mut renderer, &mut debug, ) @@ -159,11 +165,14 @@ pub fn run<A, E, C>( // The queue is empty, therefore this will never produce // a `Command`. // - // TODO: Properly queue `WindowResized` and `CursorMoved` - // events. + // TODO: Properly queue `WindowResized` let _ = state.update( - clipboard.as_ref().map(|c| c as _), viewport.logical_size(), + conversion::cursor_position( + cursor_position, + viewport.scale_factor(), + ), + clipboard.as_ref().map(|c| c as _), &mut renderer, &mut debug, ); @@ -225,6 +234,7 @@ pub fn run<A, E, C>( context.window(), scale_factor, control_flow, + &mut cursor_position, &mut modifiers, &mut viewport, &mut resized, |