Add platform specific settings

This commit is contained in:
hatoo 2019-11-30 21:32:46 +09:00
parent f0a857ddde
commit 5077f1dc6a
9 changed files with 106 additions and 0 deletions

View file

@ -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<winit::dpi::LogicalSize> = None;

View file

@ -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(),
}
}
}

View 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 {}

View 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>,
}