Add platform specific settings
This commit is contained in:
parent
f0a857ddde
commit
5077f1dc6a
9 changed files with 106 additions and 0 deletions
|
|
@ -34,6 +34,9 @@ iced_wgpu = { version = "0.1.0", path = "wgpu" }
|
||||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||||
iced_web = { version = "0.1.0", path = "web" }
|
iced_web = { version = "0.1.0", path = "web" }
|
||||||
|
|
||||||
|
[target.'cfg(target_os = "windows")'.dependencies.winapi]
|
||||||
|
version = "0.3.6"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
env_logger = "0.7"
|
env_logger = "0.7"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,15 @@
|
||||||
//! Configure your application.
|
//! 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.
|
/// The settings of an application.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
||||||
pub struct Settings {
|
pub struct Settings {
|
||||||
|
|
@ -22,6 +32,9 @@ pub struct Window {
|
||||||
|
|
||||||
/// Whether the window should have a border, a title bar, etc.
|
/// Whether the window should have a border, a title bar, etc.
|
||||||
pub decorations: bool,
|
pub decorations: bool,
|
||||||
|
|
||||||
|
/// Platform specific Setting.
|
||||||
|
pub platform_specific: PlatformSpecific,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Window {
|
impl Default for Window {
|
||||||
|
|
@ -30,6 +43,7 @@ impl Default for Window {
|
||||||
size: (1024, 768),
|
size: (1024, 768),
|
||||||
resizable: true,
|
resizable: true,
|
||||||
decorations: true,
|
decorations: true,
|
||||||
|
platform_specific: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -42,6 +56,7 @@ impl From<Settings> for iced_winit::Settings {
|
||||||
size: settings.window.size,
|
size: settings.window.size,
|
||||||
resizable: settings.window.resizable,
|
resizable: settings.window.resizable,
|
||||||
decorations: settings.window.decorations,
|
decorations: settings.window.decorations,
|
||||||
|
platform_specific: settings.window.platform_specific.into(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
14
src/settings/not_windows.rs
Normal file
14
src/settings/not_windows.rs
Normal file
|
|
@ -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<PlatformSpecific> for iced_winit::settings::PlatformSpecific {
|
||||||
|
fn from(_: PlatformSpecific) -> iced_winit::settings::PlatformSpecific {
|
||||||
|
iced_winit::settings::PlatformSpecific {}
|
||||||
|
}
|
||||||
|
}
|
||||||
21
src/settings/windows.rs
Normal file
21
src/settings/windows.rs
Normal file
|
|
@ -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<winapi::shared::windef::HWND>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
impl From<PlatformSpecific> for iced_winit::settings::PlatformSpecific {
|
||||||
|
fn from(
|
||||||
|
platform_specific: PlatformSpecific,
|
||||||
|
) -> iced_winit::settings::PlatformSpecific {
|
||||||
|
iced_winit::settings::PlatformSpecific {
|
||||||
|
parent: platform_specific.parent,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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"}
|
winit = { version = "0.20.0-alpha3", git = "https://github.com/rust-windowing/winit", rev = "709808eb4e69044705fcb214bcc30556db761405"}
|
||||||
futures = { version = "0.3", features = ["thread-pool"] }
|
futures = { version = "0.3", features = ["thread-pool"] }
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
|
||||||
|
[target.'cfg(target_os = "windows")'.dependencies.winapi]
|
||||||
|
version = "0.3.6"
|
||||||
|
|
@ -98,6 +98,7 @@ pub trait Application: Sized {
|
||||||
|
|
||||||
let (width, height) = settings.window.size;
|
let (width, height) = settings.window.size;
|
||||||
|
|
||||||
|
#[cfg(not(target_os = "windows"))]
|
||||||
let window = WindowBuilder::new()
|
let window = WindowBuilder::new()
|
||||||
.with_title(&title)
|
.with_title(&title)
|
||||||
.with_inner_size(winit::dpi::LogicalSize {
|
.with_inner_size(winit::dpi::LogicalSize {
|
||||||
|
|
@ -109,6 +110,26 @@ pub trait Application: Sized {
|
||||||
.build(&event_loop)
|
.build(&event_loop)
|
||||||
.expect("Open window");
|
.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 dpi = window.hidpi_factor();
|
||||||
let mut size = window.inner_size();
|
let mut size = window.inner_size();
|
||||||
let mut new_size: Option<winit::dpi::LogicalSize> = None;
|
let mut new_size: Option<winit::dpi::LogicalSize> = None;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,15 @@
|
||||||
//! Configure your application.
|
//! 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.
|
/// The settings of an application.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
||||||
pub struct Settings {
|
pub struct Settings {
|
||||||
|
|
@ -20,6 +30,9 @@ pub struct Window {
|
||||||
|
|
||||||
/// Whether the window should have a border, a title bar, etc.
|
/// Whether the window should have a border, a title bar, etc.
|
||||||
pub decorations: bool,
|
pub decorations: bool,
|
||||||
|
|
||||||
|
/// Platform specific Setting.
|
||||||
|
pub platform_specific: platform::PlatformSpecific,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Window {
|
impl Default for Window {
|
||||||
|
|
@ -28,6 +41,7 @@ impl Default for Window {
|
||||||
size: (1024, 768),
|
size: (1024, 768),
|
||||||
resizable: true,
|
resizable: true,
|
||||||
decorations: true,
|
decorations: true,
|
||||||
|
platform_specific: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
6
winit/src/settings/not_windows.rs
Normal file
6
winit/src/settings/not_windows.rs
Normal file
|
|
@ -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 {}
|
||||||
9
winit/src/settings/windows.rs
Normal file
9
winit/src/settings/windows.rs
Normal file
|
|
@ -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<winapi::shared::windef::HWND>,
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue