Refactor window creation in iced_winit
This commit is contained in:
parent
369ed9bc2e
commit
7756081fdb
2 changed files with 15 additions and 27 deletions
|
|
@ -96,25 +96,12 @@ pub trait Application: Sized {
|
||||||
|
|
||||||
let mut title = application.title();
|
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 = {
|
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_title(&title)
|
||||||
.with_inner_size(winit::dpi::LogicalSize {
|
.with_inner_size(winit::dpi::LogicalSize {
|
||||||
width: f64::from(width),
|
width: f64::from(width),
|
||||||
|
|
@ -123,8 +110,13 @@ pub trait Application: Sized {
|
||||||
.with_resizable(settings.window.resizable)
|
.with_resizable(settings.window.resizable)
|
||||||
.with_decorations(settings.window.decorations);
|
.with_decorations(settings.window.decorations);
|
||||||
|
|
||||||
if let Some(parent) = settings.window.platform_specific.parent {
|
#[cfg(target_os = "windows")]
|
||||||
window_builder = window_builder.with_parent_window(parent);
|
{
|
||||||
|
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")
|
window_builder.build(&event_loop).expect("Open window")
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,8 @@
|
||||||
//! Configure your application.
|
//! Configure your application.
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg_attr(target_os = "windows", path = "windows.rs")]
|
||||||
#[path = "windows.rs"]
|
#[cfg_attr(not(target_os = "windows"), path = "not_windows.rs")]
|
||||||
pub mod platform;
|
mod platform;
|
||||||
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
|
||||||
#[path = "not_windows.rs"]
|
|
||||||
pub mod platform;
|
|
||||||
|
|
||||||
pub use platform::PlatformSpecific;
|
pub use platform::PlatformSpecific;
|
||||||
|
|
||||||
|
|
@ -31,7 +27,7 @@ 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.
|
/// Platform specific settings.
|
||||||
pub platform_specific: platform::PlatformSpecific,
|
pub platform_specific: platform::PlatformSpecific,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue