Merge pull request #94 from hatoo/improve-setting
Improve window setting
This commit is contained in:
commit
60b32a9fed
6 changed files with 62 additions and 10 deletions
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -37,6 +41,8 @@ impl From<Settings> for iced_winit::Settings {
|
|||
window: iced_winit::settings::Window {
|
||||
size: settings.window.size,
|
||||
resizable: settings.window.resizable,
|
||||
decorations: settings.window.decorations,
|
||||
platform_specific: Default::default(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -96,17 +96,31 @@ pub trait Application: Sized {
|
|||
|
||||
let mut title = application.title();
|
||||
|
||||
let (width, height) = settings.window.size;
|
||||
let window = {
|
||||
let mut window_builder = WindowBuilder::new();
|
||||
|
||||
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)
|
||||
.build(&event_loop)
|
||||
.expect("Open window");
|
||||
let (width, height) = settings.window.size;
|
||||
|
||||
window_builder = window_builder
|
||||
.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);
|
||||
|
||||
#[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")
|
||||
};
|
||||
|
||||
let dpi = window.hidpi_factor();
|
||||
let mut size = window.inner_size();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,11 @@
|
|||
//! Configure your application.
|
||||
|
||||
#[cfg_attr(target_os = "windows", path = "windows.rs")]
|
||||
#[cfg_attr(not(target_os = "windows"), path = "not_windows.rs")]
|
||||
mod platform;
|
||||
|
||||
pub use platform::PlatformSpecific;
|
||||
|
||||
/// The settings of an application.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
||||
pub struct Settings {
|
||||
|
|
@ -17,6 +23,12 @@ 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 settings.
|
||||
pub platform_specific: platform::PlatformSpecific,
|
||||
}
|
||||
|
||||
impl Default for Window {
|
||||
|
|
@ -24,6 +36,8 @@ impl Default for Window {
|
|||
Window {
|
||||
size: (1024, 768),
|
||||
resizable: 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