Merge pull request #84 from hecrj/fix/event-processing

Process events only when necessary
This commit is contained in:
Héctor Ramón 2019-12-01 03:33:40 +01:00 committed by GitHub
commit 805c5ad0cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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);
}