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. --- glutin/src/application.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'glutin/src/application.rs') 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( }; 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( 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( 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( // 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( context.window(), scale_factor, control_flow, + &mut cursor_position, &mut modifiers, &mut viewport, &mut resized, -- cgit