From a33f49ff4b1c11e467ec492a96e1e05e4d32d6aa Mon Sep 17 00:00:00 2001 From: hatoo Date: Sun, 1 Dec 2019 14:55:05 +0900 Subject: Remove platform-specific logic from iced Make Window.platform_specific use iced_winit::settings::PlatformSpecific --- src/settings.rs | 53 ++++++++++++++++++++++++++++++++++++++ src/settings/mod.rs | 63 --------------------------------------------- src/settings/not_windows.rs | 14 ---------- src/settings/windows.rs | 21 --------------- 4 files changed, 53 insertions(+), 98 deletions(-) create mode 100644 src/settings.rs delete mode 100644 src/settings/mod.rs delete mode 100644 src/settings/not_windows.rs delete mode 100644 src/settings/windows.rs diff --git a/src/settings.rs b/src/settings.rs new file mode 100644 index 00000000..a5820d87 --- /dev/null +++ b/src/settings.rs @@ -0,0 +1,53 @@ +//! Configure your application. + +/// The settings of an application. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] +pub struct Settings { + /// The [`Window`] settings. + /// + /// They will be ignored on the Web. + /// + /// [`Window`]: struct.Window.html + pub window: Window, +} + +/// The window settings of an application. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct Window { + /// The size of the window. + pub size: (u32, u32), + + /// 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 { + fn default() -> Window { + Window { + size: (1024, 768), + resizable: true, + decorations: true, + platform_specific: Default::default(), + } + } +} + +#[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, + }, + } + } +} diff --git a/src/settings/mod.rs b/src/settings/mod.rs deleted file mode 100644 index d64cfa13..00000000 --- a/src/settings/mod.rs +++ /dev/null @@ -1,63 +0,0 @@ -//! 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 { - /// The [`Window`] settings. - /// - /// They will be ignored on the Web. - /// - /// [`Window`]: struct.Window.html - pub window: Window, -} - -/// The window settings of an application. -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub struct Window { - /// The size of the window. - pub size: (u32, u32), - - /// 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: PlatformSpecific, -} - -impl Default for Window { - fn default() -> Window { - Window { - size: (1024, 768), - resizable: true, - decorations: true, - platform_specific: Default::default(), - } - } -} - -#[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.into(), - }, - } - } -} 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, - } - } -} -- cgit