summaryrefslogtreecommitdiffstats
path: root/examples/integration/src/main.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-07-08 11:44:40 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-07-08 11:44:40 +0200
commitf3dfaa2c43bad16fc91660b2b73cb9173549e7ec (patch)
tree353365f4dd1e3136bc651ac8c1572f62fff1304b /examples/integration/src/main.rs
parent072ec69d53d2708d8fd1693151bcec7305efccf8 (diff)
parent5c4f5ae5ecb36703a95cafb2cd58692529c9466d (diff)
downloadiced-f3dfaa2c43bad16fc91660b2b73cb9173549e7ec.tar.gz
iced-f3dfaa2c43bad16fc91660b2b73cb9173549e7ec.tar.bz2
iced-f3dfaa2c43bad16fc91660b2b73cb9173549e7ec.zip
Merge branch 'master' into feature/pane-grid-titlebar
Diffstat (limited to 'examples/integration/src/main.rs')
-rw-r--r--examples/integration/src/main.rs34
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 {