From 80a8a574712f1652c7311554ad358c5bc15d5515 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 26 Nov 2019 15:33:38 +0100 Subject: Stop loading a mono font just for the debug view --- winit/src/debug/basic.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'winit') diff --git a/winit/src/debug/basic.rs b/winit/src/debug/basic.rs index 67c6d8a2..c9da392c 100644 --- a/winit/src/debug/basic.rs +++ b/winit/src/debug/basic.rs @@ -146,7 +146,7 @@ impl Debug { let mut lines = Vec::new(); fn key_value(key: &str, value: T) -> String { - format!("{: <30} {:?}", key, value) + format!("{} {:?}", key, value) } lines.push(format!( -- cgit 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') 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 + winit/src/settings.rs | 4 ++++ 2 files changed, 5 insertions(+) (limited to 'winit') 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"); diff --git a/winit/src/settings.rs b/winit/src/settings.rs index d257ecd8..503b9dea 100644 --- a/winit/src/settings.rs +++ b/winit/src/settings.rs @@ -17,6 +17,9 @@ pub struct Window { /// Whether the window should be resizable or not. pub resizable: bool, + + /// Whether the window should have a border, a title bar, etc. + pub decorations: bool, } impl Default for Window { @@ -24,6 +27,7 @@ impl Default for Window { Window { size: (1024, 768), resizable: true, + decorations: true, } } } -- 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/Cargo.toml | 3 +++ winit/src/application.rs | 21 +++++++++++++++++ winit/src/settings.rs | 33 --------------------------- winit/src/settings/mod.rs | 47 +++++++++++++++++++++++++++++++++++++++ winit/src/settings/not_windows.rs | 6 +++++ winit/src/settings/windows.rs | 9 ++++++++ 6 files changed, 86 insertions(+), 33 deletions(-) delete mode 100644 winit/src/settings.rs create mode 100644 winit/src/settings/mod.rs create mode 100644 winit/src/settings/not_windows.rs create mode 100644 winit/src/settings/windows.rs (limited to 'winit') diff --git a/winit/Cargo.toml b/winit/Cargo.toml index 2a33255d..bc739c6d 100644 --- a/winit/Cargo.toml +++ b/winit/Cargo.toml @@ -15,3 +15,6 @@ iced_native = { version = "0.1.0-alpha", path = "../native" } winit = { version = "0.20.0-alpha3", git = "https://github.com/rust-windowing/winit", rev = "709808eb4e69044705fcb214bcc30556db761405"} futures = { version = "0.3", features = ["thread-pool"] } log = "0.4" + +[target.'cfg(target_os = "windows")'.dependencies.winapi] +version = "0.3.6" \ No newline at end of file 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; diff --git a/winit/src/settings.rs b/winit/src/settings.rs deleted file mode 100644 index 503b9dea..00000000 --- a/winit/src/settings.rs +++ /dev/null @@ -1,33 +0,0 @@ -//! Configure your application. - -/// The settings of an application. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] -pub struct Settings { - /// The [`Window`] settings - /// - /// [`Window`]: struct.Window.html - pub window: Window, -} - -/// The window settings of an application. -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub struct Window { - /// The size of the window. - pub size: (u32, u32), - - /// Whether the window should be resizable or not. - pub resizable: bool, - - /// Whether the window should have a border, a title bar, etc. - pub decorations: bool, -} - -impl Default for Window { - fn default() -> Window { - Window { - size: (1024, 768), - resizable: true, - decorations: true, - } - } -} diff --git a/winit/src/settings/mod.rs b/winit/src/settings/mod.rs new file mode 100644 index 00000000..61a67bdb --- /dev/null +++ b/winit/src/settings/mod.rs @@ -0,0 +1,47 @@ +//! Configure your application. + +#[cfg(target_os = "windows")] +#[path = "windows.rs"] +pub mod platform; + +#[cfg(not(target_os = "windows"))] +#[path = "not_windows.rs"] +pub mod platform; + +pub use platform::PlatformSpecific; + +/// The settings of an application. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] +pub struct Settings { + /// The [`Window`] settings + /// + /// [`Window`]: struct.Window.html + pub window: Window, +} + +/// The window settings of an application. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct Window { + /// The size of the window. + pub size: (u32, u32), + + /// Whether the window should be resizable or not. + pub resizable: bool, + + /// Whether the window should have a border, a title bar, etc. + pub decorations: bool, + + /// Platform specific Setting. + pub platform_specific: platform::PlatformSpecific, +} + +impl Default for Window { + fn default() -> Window { + Window { + size: (1024, 768), + resizable: true, + decorations: true, + platform_specific: Default::default(), + } + } +} diff --git a/winit/src/settings/not_windows.rs b/winit/src/settings/not_windows.rs new file mode 100644 index 00000000..5d703f84 --- /dev/null +++ b/winit/src/settings/not_windows.rs @@ -0,0 +1,6 @@ +#![cfg(not(target_os = "windows"))] +//! Platform specific settings for not Windows. + +/// The platform specific window settings of an application. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] +pub struct PlatformSpecific {} diff --git a/winit/src/settings/windows.rs b/winit/src/settings/windows.rs new file mode 100644 index 00000000..76b8d067 --- /dev/null +++ b/winit/src/settings/windows.rs @@ -0,0 +1,9 @@ +#![cfg(target_os = "windows")] +//! Platform specific settings for Windows. + +/// The platform specific window settings of an application. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] +pub struct PlatformSpecific { + /// Parent Window + pub parent: Option, +} -- cgit From 287f3ea99a41f5452ea0ea2fcd075742d6ca4285 Mon Sep 17 00:00:00 2001 From: hatoo Date: Mon, 2 Dec 2019 21:58:35 +0900 Subject: Add tailing newline to winit/Cargo.toml --- winit/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'winit') diff --git a/winit/Cargo.toml b/winit/Cargo.toml index bc739c6d..b5b07449 100644 --- a/winit/Cargo.toml +++ b/winit/Cargo.toml @@ -17,4 +17,4 @@ futures = { version = "0.3", features = ["thread-pool"] } log = "0.4" [target.'cfg(target_os = "windows")'.dependencies.winapi] -version = "0.3.6" \ No newline at end of file +version = "0.3.6" -- 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 +++++++++++------------------- winit/src/settings/mod.rs | 12 ++++-------- 2 files changed, 15 insertions(+), 27 deletions(-) (limited to 'winit') 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") diff --git a/winit/src/settings/mod.rs b/winit/src/settings/mod.rs index 61a67bdb..151d73d7 100644 --- a/winit/src/settings/mod.rs +++ b/winit/src/settings/mod.rs @@ -1,12 +1,8 @@ //! Configure your application. -#[cfg(target_os = "windows")] -#[path = "windows.rs"] -pub mod platform; - -#[cfg(not(target_os = "windows"))] -#[path = "not_windows.rs"] -pub mod platform; +#[cfg_attr(target_os = "windows", path = "windows.rs")] +#[cfg_attr(not(target_os = "windows"), path = "not_windows.rs")] +mod platform; pub use platform::PlatformSpecific; @@ -31,7 +27,7 @@ pub struct Window { /// Whether the window should have a border, a title bar, etc. pub decorations: bool, - /// Platform specific Setting. + /// Platform specific settings. pub platform_specific: platform::PlatformSpecific, } -- cgit