diff options
author | 2019-11-28 21:05:17 +0100 | |
---|---|---|
committer | 2019-11-28 21:05:17 +0100 | |
commit | 826bc374b1a2d3758432dc10663f0fbeed459383 (patch) | |
tree | f6aa3fca977afea1d8f6b66e72f2914e22195f97 /winit/src | |
parent | 811d8b90d71c26100f0933217f5474e090fbf17c (diff) | |
download | iced-826bc374b1a2d3758432dc10663f0fbeed459383.tar.gz iced-826bc374b1a2d3758432dc10663f0fbeed459383.tar.bz2 iced-826bc374b1a2d3758432dc10663f0fbeed459383.zip |
Process events only when necessary
Additionally, this also fixes a bug where the old size was being used
for layouting after a resize.
Diffstat (limited to 'winit/src')
-rw-r--r-- | winit/src/application.rs | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/winit/src/application.rs b/winit/src/application.rs index 1042b412..fb40156a 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -110,7 +110,7 @@ pub trait Application: Sized { let dpi = window.hidpi_factor(); let mut size = window.inner_size(); - let mut new_size: Option<winit::dpi::LogicalSize> = None; + let mut resized = false; let mut renderer = Self::Renderer::new(); @@ -143,6 +143,11 @@ pub trait Application: Sized { event_loop.run(move |event, _, control_flow| match event { event::Event::MainEventsCleared => { + if events.is_empty() && external_messages.is_empty() && !resized + { + return; + } + // TODO: We should be able to keep a user interface alive // between events once we remove state references. // @@ -217,9 +222,9 @@ pub trait Application: Sized { event::Event::RedrawRequested(_) => { debug.render_started(); - if let Some(new_size) = new_size.take() { + if resized { let dpi = window.hidpi_factor(); - let (width, height) = to_physical(new_size, dpi); + let (width, height) = to_physical(size, dpi); target.resize( width, @@ -228,7 +233,7 @@ pub trait Application: Sized { &renderer, ); - size = new_size; + resized = false; } let new_mouse_cursor = @@ -320,8 +325,9 @@ pub trait Application: Sized { WindowEvent::CloseRequested => { *control_flow = ControlFlow::Exit; } - WindowEvent::Resized(size) => { - new_size = Some(size.into()); + WindowEvent::Resized(new_size) => { + size = new_size; + resized = true; log::debug!("Resized: {:?}", new_size); } |