diff options
Diffstat (limited to '')
| -rw-r--r-- | examples/integration/src/controls.rs | 39 | ||||
| -rw-r--r-- | examples/integration/src/main.rs | 34 | 
2 files changed, 47 insertions, 26 deletions
| diff --git a/examples/integration/src/controls.rs b/examples/integration/src/controls.rs index e6e74995..824f9f53 100644 --- a/examples/integration/src/controls.rs +++ b/examples/integration/src/controls.rs @@ -48,24 +48,33 @@ impl Program for Controls {          let sliders = Row::new()              .width(Length::Units(500))              .spacing(20) -            .push(Slider::new(r, 0.0..=1.0, background_color.r, move |r| { -                Message::BackgroundColorChanged(Color { -                    r, -                    ..background_color +            .push( +                Slider::new(r, 0.0..=1.0, background_color.r, move |r| { +                    Message::BackgroundColorChanged(Color { +                        r, +                        ..background_color +                    })                  }) -            })) -            .push(Slider::new(g, 0.0..=1.0, background_color.g, move |g| { -                Message::BackgroundColorChanged(Color { -                    g, -                    ..background_color +                .step(0.01), +            ) +            .push( +                Slider::new(g, 0.0..=1.0, background_color.g, move |g| { +                    Message::BackgroundColorChanged(Color { +                        g, +                        ..background_color +                    })                  }) -            })) -            .push(Slider::new(b, 0.0..=1.0, background_color.b, move |b| { -                Message::BackgroundColorChanged(Color { -                    b, -                    ..background_color +                .step(0.01), +            ) +            .push( +                Slider::new(b, 0.0..=1.0, background_color.b, move |b| { +                    Message::BackgroundColorChanged(Color { +                        b, +                        ..background_color +                    })                  }) -            })); +                .step(0.01), +            );          Row::new()              .width(Length::Fill) 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 { | 
