From f0a857ddde7cf4739c1acde57e8df502e983a254 Mon Sep 17 00:00:00 2001 From: hatoo Date: Sat, 30 Nov 2019 20:38:32 +0900 Subject: [PATCH 1/8] Add `decorations` to Setting --- src/settings.rs | 5 +++++ winit/src/application.rs | 1 + winit/src/settings.rs | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/src/settings.rs b/src/settings.rs index 2556c51b..c9ece5ef 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -19,6 +19,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 { @@ -26,6 +29,7 @@ impl Default for Window { Window { size: (1024, 768), resizable: true, + decorations: true, } } } @@ -37,6 +41,7 @@ impl From for iced_winit::Settings { window: iced_winit::settings::Window { size: settings.window.size, resizable: settings.window.resizable, + decorations: settings.window.decorations, }, } } 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, } } } From 5077f1dc6a6aca5ab84dd89296fb70489393cf57 Mon Sep 17 00:00:00 2001 From: hatoo Date: Sat, 30 Nov 2019 21:32:46 +0900 Subject: [PATCH 2/8] Add platform specific settings --- Cargo.toml | 3 +++ src/{settings.rs => settings/mod.rs} | 15 +++++++++++++++ src/settings/not_windows.rs | 14 ++++++++++++++ src/settings/windows.rs | 21 +++++++++++++++++++++ winit/Cargo.toml | 3 +++ winit/src/application.rs | 21 +++++++++++++++++++++ winit/src/{settings.rs => settings/mod.rs} | 14 ++++++++++++++ winit/src/settings/not_windows.rs | 6 ++++++ winit/src/settings/windows.rs | 9 +++++++++ 9 files changed, 106 insertions(+) rename src/{settings.rs => settings/mod.rs} (75%) create mode 100644 src/settings/not_windows.rs create mode 100644 src/settings/windows.rs rename winit/src/{settings.rs => settings/mod.rs} (70%) create mode 100644 winit/src/settings/not_windows.rs create mode 100644 winit/src/settings/windows.rs diff --git a/Cargo.toml b/Cargo.toml index 7039a5b3..5361133c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,6 +34,9 @@ iced_wgpu = { version = "0.1.0", path = "wgpu" } [target.'cfg(target_arch = "wasm32")'.dependencies] iced_web = { version = "0.1.0", path = "web" } +[target.'cfg(target_os = "windows")'.dependencies.winapi] +version = "0.3.6" + [dev-dependencies] env_logger = "0.7" serde = { version = "1.0", features = ["derive"] } diff --git a/src/settings.rs b/src/settings/mod.rs similarity index 75% rename from src/settings.rs rename to src/settings/mod.rs index c9ece5ef..d64cfa13 100644 --- a/src/settings.rs +++ b/src/settings/mod.rs @@ -1,5 +1,15 @@ //! 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 { @@ -22,6 +32,9 @@ pub struct Window { /// Whether the window should have a border, a title bar, etc. pub decorations: bool, + + /// Platform specific Setting. + pub platform_specific: PlatformSpecific, } impl Default for Window { @@ -30,6 +43,7 @@ impl Default for Window { size: (1024, 768), resizable: true, decorations: true, + platform_specific: Default::default(), } } } @@ -42,6 +56,7 @@ impl From for iced_winit::Settings { size: settings.window.size, resizable: settings.window.resizable, decorations: settings.window.decorations, + platform_specific: settings.window.platform_specific.into(), }, } } diff --git a/src/settings/not_windows.rs b/src/settings/not_windows.rs new file mode 100644 index 00000000..1ae14c7f --- /dev/null +++ b/src/settings/not_windows.rs @@ -0,0 +1,14 @@ +#![cfg(not(target_os = "windows"))] +//! Platform specific settings for not Windows. + +/// The platform specific window settings of an application. +#[cfg(not(target_os = "windows"))] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] +pub struct PlatformSpecific {} + +#[cfg(not(target_os = "windows"))] +impl From for iced_winit::settings::PlatformSpecific { + fn from(_: PlatformSpecific) -> iced_winit::settings::PlatformSpecific { + iced_winit::settings::PlatformSpecific {} + } +} diff --git a/src/settings/windows.rs b/src/settings/windows.rs new file mode 100644 index 00000000..0372111f --- /dev/null +++ b/src/settings/windows.rs @@ -0,0 +1,21 @@ +#![cfg(target_os = "windows")] +//! Platform specific settings for Windows. + +/// The platform specific window settings of an application. +#[cfg(target_os = "windows")] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] +pub struct PlatformSpecific { + /// Parent Window + pub parent: Option, +} + +#[cfg(target_os = "windows")] +impl From for iced_winit::settings::PlatformSpecific { + fn from( + platform_specific: PlatformSpecific, + ) -> iced_winit::settings::PlatformSpecific { + iced_winit::settings::PlatformSpecific { + parent: platform_specific.parent, + } + } +} 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/mod.rs similarity index 70% rename from winit/src/settings.rs rename to winit/src/settings/mod.rs index 503b9dea..61a67bdb 100644 --- a/winit/src/settings.rs +++ b/winit/src/settings/mod.rs @@ -1,5 +1,15 @@ //! 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 { @@ -20,6 +30,9 @@ pub struct Window { /// 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 { @@ -28,6 +41,7 @@ impl Default for 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, +} From a33f49ff4b1c11e467ec492a96e1e05e4d32d6aa Mon Sep 17 00:00:00 2001 From: hatoo Date: Sun, 1 Dec 2019 14:55:05 +0900 Subject: [PATCH 3/8] Remove platform-specific logic from iced Make Window.platform_specific use iced_winit::settings::PlatformSpecific --- src/{settings/mod.rs => settings.rs} | 14 ++------------ src/settings/not_windows.rs | 14 -------------- src/settings/windows.rs | 21 --------------------- 3 files changed, 2 insertions(+), 47 deletions(-) rename src/{settings/mod.rs => settings.rs} (84%) delete mode 100644 src/settings/not_windows.rs delete mode 100644 src/settings/windows.rs diff --git a/src/settings/mod.rs b/src/settings.rs similarity index 84% rename from src/settings/mod.rs rename to src/settings.rs index d64cfa13..a5820d87 100644 --- a/src/settings/mod.rs +++ b/src/settings.rs @@ -1,15 +1,5 @@ //! 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 { @@ -34,7 +24,7 @@ pub struct Window { pub decorations: bool, /// Platform specific Setting. - pub platform_specific: PlatformSpecific, + pub platform_specific: iced_winit::settings::PlatformSpecific, } impl Default for Window { @@ -56,7 +46,7 @@ impl From for iced_winit::Settings { size: settings.window.size, resizable: settings.window.resizable, decorations: settings.window.decorations, - platform_specific: settings.window.platform_specific.into(), + platform_specific: settings.window.platform_specific, }, } } diff --git a/src/settings/not_windows.rs b/src/settings/not_windows.rs deleted file mode 100644 index 1ae14c7f..00000000 --- a/src/settings/not_windows.rs +++ /dev/null @@ -1,14 +0,0 @@ -#![cfg(not(target_os = "windows"))] -//! Platform specific settings for not Windows. - -/// The platform specific window settings of an application. -#[cfg(not(target_os = "windows"))] -#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] -pub struct PlatformSpecific {} - -#[cfg(not(target_os = "windows"))] -impl From for iced_winit::settings::PlatformSpecific { - fn from(_: PlatformSpecific) -> iced_winit::settings::PlatformSpecific { - iced_winit::settings::PlatformSpecific {} - } -} diff --git a/src/settings/windows.rs b/src/settings/windows.rs deleted file mode 100644 index 0372111f..00000000 --- a/src/settings/windows.rs +++ /dev/null @@ -1,21 +0,0 @@ -#![cfg(target_os = "windows")] -//! Platform specific settings for Windows. - -/// The platform specific window settings of an application. -#[cfg(target_os = "windows")] -#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] -pub struct PlatformSpecific { - /// Parent Window - pub parent: Option, -} - -#[cfg(target_os = "windows")] -impl From for iced_winit::settings::PlatformSpecific { - fn from( - platform_specific: PlatformSpecific, - ) -> iced_winit::settings::PlatformSpecific { - iced_winit::settings::PlatformSpecific { - parent: platform_specific.parent, - } - } -} From a1f9be3089536681324c1a5233c3a58f47367b9f Mon Sep 17 00:00:00 2001 From: hatoo Date: Mon, 2 Dec 2019 21:44:08 +0900 Subject: [PATCH 4/8] Remove unneeded dependency "winapi" from iced --- Cargo.toml | 3 --- 1 file changed, 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5361133c..7039a5b3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,9 +34,6 @@ iced_wgpu = { version = "0.1.0", path = "wgpu" } [target.'cfg(target_arch = "wasm32")'.dependencies] iced_web = { version = "0.1.0", path = "web" } -[target.'cfg(target_os = "windows")'.dependencies.winapi] -version = "0.3.6" - [dev-dependencies] env_logger = "0.7" serde = { version = "1.0", features = ["derive"] } From 97f1f3dcf4af8325fd24fbd70c13dbde307fce72 Mon Sep 17 00:00:00 2001 From: hatoo Date: Mon, 2 Dec 2019 21:57:07 +0900 Subject: [PATCH 5/8] Modify src/settings.rs to keep original API --- src/settings.rs | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/src/settings.rs b/src/settings.rs index a5820d87..bd13dcaa 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -19,12 +19,6 @@ 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, - - /// Platform specific Setting. - pub platform_specific: iced_winit::settings::PlatformSpecific, } impl Default for Window { @@ -32,8 +26,6 @@ impl Default for Window { Window { size: (1024, 768), resizable: true, - decorations: true, - platform_specific: Default::default(), } } } @@ -41,13 +33,9 @@ impl Default for Window { #[cfg(not(target_arch = "wasm32"))] impl From for iced_winit::Settings { fn from(settings: Settings) -> iced_winit::Settings { - iced_winit::Settings { - window: iced_winit::settings::Window { - size: settings.window.size, - resizable: settings.window.resizable, - decorations: settings.window.decorations, - platform_specific: settings.window.platform_specific, - }, - } + let mut iced_winit_settings = iced_winit::settings::Settings::default(); + iced_winit_settings.window.size = settings.window.size; + iced_winit_settings.window.resizable = settings.window.resizable; + iced_winit_settings } } From 287f3ea99a41f5452ea0ea2fcd075742d6ca4285 Mon Sep 17 00:00:00 2001 From: hatoo Date: Mon, 2 Dec 2019 21:58:35 +0900 Subject: [PATCH 6/8] Add tailing newline to winit/Cargo.toml --- winit/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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" From 369ed9bc2e3c09666458bd0a0c0834a402239b3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Tue, 3 Dec 2019 07:08:12 +0100 Subject: [PATCH 7/8] Add `decorations` to `settings::Window` --- src/settings.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/settings.rs b/src/settings.rs index bd13dcaa..62a1a614 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -19,6 +19,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. or not. + pub decorations: bool, } impl Default for Window { @@ -26,6 +29,7 @@ impl Default for Window { Window { size: (1024, 768), resizable: true, + decorations: true, } } } @@ -33,9 +37,13 @@ impl Default for Window { #[cfg(not(target_arch = "wasm32"))] impl From for iced_winit::Settings { fn from(settings: Settings) -> iced_winit::Settings { - let mut iced_winit_settings = iced_winit::settings::Settings::default(); - iced_winit_settings.window.size = settings.window.size; - iced_winit_settings.window.resizable = settings.window.resizable; - iced_winit_settings + iced_winit::Settings { + window: iced_winit::settings::Window { + size: settings.window.size, + resizable: settings.window.resizable, + decorations: settings.window.decorations, + platform_specific: Default::default(), + }, + } } } From 7756081fdbc93aee3f5d11fbd14e3d9f2cbefe57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Tue, 3 Dec 2019 07:20:22 +0100 Subject: [PATCH 8/8] Refactor window creation in `iced_winit` --- winit/src/application.rs | 30 +++++++++++------------------- winit/src/settings/mod.rs | 12 ++++-------- 2 files changed, 15 insertions(+), 27 deletions(-) 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, }