diff options
Diffstat (limited to 'examples/integration/src/main.rs')
| -rw-r--r-- | examples/integration/src/main.rs | 34 | 
1 files changed, 23 insertions, 11 deletions
| diff --git a/examples/integration/src/main.rs b/examples/integration/src/main.rs index db8b4366..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;                      } -                      _ => {}                  } @@ -119,16 +124,23 @@ pub fn main() {                  }              }              Event::MainEventsCleared => { -                // We update iced -                let _ = state.update( -                    None, -                    viewport.logical_size(), -                    &mut renderer, -                    &mut debug, -                ); +                // If there are events pending +                if !state.is_queue_empty() { +                    // We update iced +                    let _ = state.update( +                        viewport.logical_size(), +                        conversion::cursor_position( +                            cursor_position, +                            viewport.scale_factor(), +                        ), +                        None, +                        &mut renderer, +                        &mut debug, +                    ); -                // and request a redraw -                window.request_redraw(); +                    // and request a redraw +                    window.request_redraw(); +                }              }              Event::RedrawRequested(_) => {                  if resized { | 
