From 826bc374b1a2d3758432dc10663f0fbeed459383 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 28 Nov 2019 21:05:17 +0100 Subject: Process events only when necessary Additionally, this also fixes a bug where the old size was being used for layouting after a resize. --- winit/src/application.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'winit/src/application.rs') 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 = 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); } -- cgit From f0a857ddde7cf4739c1acde57e8df502e983a254 Mon Sep 17 00:00:00 2001 From: hatoo Date: Sat, 30 Nov 2019 20:38:32 +0900 Subject: Add `decorations` to Setting --- winit/src/application.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'winit/src/application.rs') diff --git a/winit/src/application.rs b/winit/src/application.rs index 1042b412..2a0e56b7 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -105,6 +105,7 @@ pub trait Application: Sized { height: f64::from(height), }) .with_resizable(settings.window.resizable) + .with_decorations(settings.window.decorations) .build(&event_loop) .expect("Open window"); -- cgit From 5077f1dc6a6aca5ab84dd89296fb70489393cf57 Mon Sep 17 00:00:00 2001 From: hatoo Date: Sat, 30 Nov 2019 21:32:46 +0900 Subject: Add platform specific settings --- winit/src/application.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'winit/src/application.rs') diff --git a/winit/src/application.rs b/winit/src/application.rs index 2a0e56b7..a75d57af 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -98,6 +98,7 @@ pub trait Application: Sized { let (width, height) = settings.window.size; + #[cfg(not(target_os = "windows"))] let window = WindowBuilder::new() .with_title(&title) .with_inner_size(winit::dpi::LogicalSize { @@ -109,6 +110,26 @@ pub trait Application: Sized { .build(&event_loop) .expect("Open window"); + #[cfg(target_os = "windows")] + let window = { + use winit::platform::windows::WindowBuilderExtWindows; + + let mut window_builder = WindowBuilder::new() + .with_title(&title) + .with_inner_size(winit::dpi::LogicalSize { + width: f64::from(width), + height: f64::from(height), + }) + .with_resizable(settings.window.resizable) + .with_decorations(settings.window.decorations); + + if let Some(parent) = settings.window.platform_specific.parent { + window_builder = window_builder.with_parent_window(parent); + } + + window_builder.build(&event_loop).expect("Open window") + }; + let dpi = window.hidpi_factor(); let mut size = window.inner_size(); let mut new_size: Option = None; -- cgit From 7756081fdbc93aee3f5d11fbd14e3d9f2cbefe57 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 3 Dec 2019 07:20:22 +0100 Subject: Refactor window creation in `iced_winit` --- winit/src/application.rs | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) (limited to 'winit/src/application.rs') diff --git a/winit/src/application.rs b/winit/src/application.rs index a75d57af..00625052 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -96,25 +96,12 @@ pub trait Application: Sized { let mut title = application.title(); - let (width, height) = settings.window.size; - - #[cfg(not(target_os = "windows"))] - let window = WindowBuilder::new() - .with_title(&title) - .with_inner_size(winit::dpi::LogicalSize { - width: f64::from(width), - height: f64::from(height), - }) - .with_resizable(settings.window.resizable) - .with_decorations(settings.window.decorations) - .build(&event_loop) - .expect("Open window"); - - #[cfg(target_os = "windows")] let window = { - use winit::platform::windows::WindowBuilderExtWindows; + let mut window_builder = WindowBuilder::new(); - let mut window_builder = WindowBuilder::new() + let (width, height) = settings.window.size; + + window_builder = window_builder .with_title(&title) .with_inner_size(winit::dpi::LogicalSize { width: f64::from(width), @@ -123,8 +110,13 @@ pub trait Application: Sized { .with_resizable(settings.window.resizable) .with_decorations(settings.window.decorations); - if let Some(parent) = settings.window.platform_specific.parent { - window_builder = window_builder.with_parent_window(parent); + #[cfg(target_os = "windows")] + { + use winit::platform::windows::WindowBuilderExtWindows; + + if let Some(parent) = settings.window.platform_specific.parent { + window_builder = window_builder.with_parent_window(parent); + } } window_builder.build(&event_loop).expect("Open window") -- cgit