diff options
author | 2020-06-23 06:44:34 +0200 | |
---|---|---|
committer | 2020-06-23 06:44:34 +0200 | |
commit | f30a666dc81fdc85d225dc83f1a33e32d5dccbd2 (patch) | |
tree | 579f3a0e8a050447c208282305c3de98f52f694e /examples | |
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 'examples')
-rw-r--r-- | examples/integration/src/main.rs | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/examples/integration/src/main.rs b/examples/integration/src/main.rs index 4c4b6d84..33d4c361 100644 --- a/examples/integration/src/main.rs +++ b/examples/integration/src/main.rs @@ -5,9 +5,10 @@ use controls::Controls; use scene::Scene; use iced_wgpu::{wgpu, Backend, Renderer, Settings, Viewport}; -use iced_winit::{futures, program, winit, Debug, Size}; +use iced_winit::{conversion, futures, program, winit, Debug, Size}; use winit::{ + dpi::PhysicalPosition, event::{Event, ModifiersState, WindowEvent}, event_loop::{ControlFlow, EventLoop}, }; @@ -24,6 +25,7 @@ pub fn main() { Size::new(physical_size.width, physical_size.height), window.scale_factor(), ); + let mut cursor_position = PhysicalPosition::new(-1.0, -1.0); let mut modifiers = ModifiersState::default(); // Initialize wgpu @@ -79,6 +81,7 @@ pub fn main() { let mut state = program::State::new( controls, viewport.logical_size(), + conversion::cursor_position(cursor_position, viewport.scale_factor()), &mut renderer, &mut debug, ); @@ -91,6 +94,9 @@ pub fn main() { match event { Event::WindowEvent { event, .. } => { match event { + WindowEvent::CursorMoved { position, .. } => { + cursor_position = position; + } WindowEvent::ModifiersChanged(new_modifiers) => { modifiers = new_modifiers; } @@ -105,7 +111,6 @@ pub fn main() { WindowEvent::CloseRequested => { *control_flow = ControlFlow::Exit; } - _ => {} } @@ -123,8 +128,12 @@ pub fn main() { if !state.is_queue_empty() { // We update iced let _ = state.update( - None, viewport.logical_size(), + conversion::cursor_position( + cursor_position, + viewport.scale_factor(), + ), + None, &mut renderer, &mut debug, ); |