diff options
author | 2023-07-12 19:21:05 -0700 | |
---|---|---|
committer | 2023-07-21 13:53:38 -0700 | |
commit | d53ccc857da4d4cda769904342aeb5a82a64f146 (patch) | |
tree | 7de16b72e0e054d10380586ba5b79a7181478aa7 /core | |
parent | 633f405f3f78bc7f82d2b2061491b0e011137451 (diff) | |
download | iced-d53ccc857da4d4cda769904342aeb5a82a64f146.tar.gz iced-d53ccc857da4d4cda769904342aeb5a82a64f146.tar.bz2 iced-d53ccc857da4d4cda769904342aeb5a82a64f146.zip |
refactored window storage;
new helper window events (Destroyed, Created);
clippy + fmt;
Diffstat (limited to 'core')
-rw-r--r-- | core/Cargo.toml | 3 | ||||
-rw-r--r-- | core/src/window.rs | 6 | ||||
-rw-r--r-- | core/src/window/event.rs | 17 | ||||
-rw-r--r-- | core/src/window/id.rs | 15 | ||||
-rw-r--r-- | core/src/window/position.rs | 22 | ||||
-rw-r--r-- | core/src/window/settings.rs | 40 | ||||
-rw-r--r-- | core/src/window/settings/macos.rs | 12 | ||||
-rw-r--r-- | core/src/window/settings/other.rs | 3 | ||||
-rw-r--r-- | core/src/window/settings/wasm.rs | 11 | ||||
-rw-r--r-- | core/src/window/settings/windows.rs | 21 |
10 files changed, 120 insertions, 30 deletions
diff --git a/core/Cargo.toml b/core/Cargo.toml index 55f2e85f..edf9e7c8 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -20,5 +20,8 @@ optional = true [target.'cfg(target_arch = "wasm32")'.dependencies] instant = "0.1" +[target.'cfg(windows)'.dependencies.raw-window-handle] +version = "0.5.2" + [dev-dependencies] approx = "0.5" diff --git a/core/src/window.rs b/core/src/window.rs index a6dbdfb4..10db31b6 100644 --- a/core/src/window.rs +++ b/core/src/window.rs @@ -2,14 +2,20 @@ pub mod icon; mod event; +mod id; mod level; mod mode; +mod position; mod redraw_request; +mod settings; mod user_attention; pub use event::Event; pub use icon::Icon; +pub use id::Id; pub use level::Level; pub use mode::Mode; +pub use position::Position; pub use redraw_request::RedrawRequest; +pub use settings::Settings; pub use user_attention::UserAttention; diff --git a/core/src/window/event.rs b/core/src/window/event.rs index e2fb5e66..3efce05e 100644 --- a/core/src/window/event.rs +++ b/core/src/window/event.rs @@ -1,4 +1,5 @@ use crate::time::Instant; +use crate::Size; use std::path::PathBuf; @@ -32,6 +33,22 @@ pub enum Event { /// occurs. CloseRequested, + /// A window was destroyed by the runtime. + Destroyed, + + /// A window was created. + /// + /// **Note:** this event is not supported on Wayland. + Created { + /// The position of the created window. This is relative to the top-left corner of the desktop + /// the window is on, including virtual desktops. Refers to window's "inner" position, + /// or the client area, in logical pixels. + position: (i32, i32), + /// The size of the created window. This is its "inner" size, or the size of the + /// client area, in logical pixels. + size: Size<u32>, + }, + /// A window was focused. Focused, diff --git a/core/src/window/id.rs b/core/src/window/id.rs index 0a11b1aa..65002d43 100644 --- a/core/src/window/id.rs +++ b/core/src/window/id.rs @@ -1,18 +1,17 @@ use std::collections::hash_map::DefaultHasher; -use std::fmt::{Display, Formatter}; use std::hash::{Hash, Hasher}; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] -/// The ID of the window. +/// The id of the window. /// -/// Internally Iced uses `window::Id::MAIN` as the first window spawned. +/// Internally Iced reserves `window::Id::MAIN` for the first window spawned. pub struct Id(u64); impl Id { - /// The reserved window ID for the primary window in an Iced application. + /// The reserved window [`Id`] for the first window in an Iced application. pub const MAIN: Self = Id(0); - /// Creates a new unique window ID. + /// Creates a new unique window [`Id`]. pub fn new(id: impl Hash) -> Id { let mut hasher = DefaultHasher::new(); id.hash(&mut hasher); @@ -20,9 +19,3 @@ impl Id { Id(hasher.finish()) } } - -impl Display for Id { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "Id({})", self.0) - } -} diff --git a/core/src/window/position.rs b/core/src/window/position.rs index e69de29b..c260c29e 100644 --- a/core/src/window/position.rs +++ b/core/src/window/position.rs @@ -0,0 +1,22 @@ +/// The position of a window in a given screen. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Position { + /// The platform-specific default position for a new window. + Default, + /// The window is completely centered on the screen. + Centered, + /// The window is positioned with specific coordinates: `(X, Y)`. + /// + /// When the decorations of the window are enabled, Windows 10 will add some + /// invisible padding to the window. This padding gets included in the + /// position. So if you have decorations enabled and want the window to be + /// at (0, 0) you would have to set the position to + /// `(PADDING_X, PADDING_Y)`. + Specific(i32, i32), +} + +impl Default for Position { + fn default() -> Self { + Self::Default + } +} diff --git a/core/src/window/settings.rs b/core/src/window/settings.rs index 458b9232..20811e83 100644 --- a/core/src/window/settings.rs +++ b/core/src/window/settings.rs @@ -1,6 +1,26 @@ use crate::window::{Icon, Level, Position}; -pub use iced_winit::settings::PlatformSpecific; +#[cfg(target_os = "windows")] +#[path = "settings/windows.rs"] +mod platform; + +#[cfg(target_os = "macos")] +#[path = "settings/macos.rs"] +mod platform; + +#[cfg(target_arch = "wasm32")] +#[path = "settings/wasm.rs"] +mod platform; + +#[cfg(not(any( + target_os = "windows", + target_os = "macos", + target_arch = "wasm32" +)))] +#[path = "settings/other.rs"] +mod platform; + +pub use platform::PlatformSpecific; /// The window settings of an application. #[derive(Debug, Clone)] @@ -56,21 +76,3 @@ impl Default for Settings { } } } - -impl From<Settings> for iced_winit::settings::Window { - fn from(settings: Settings) -> Self { - Self { - size: settings.size, - position: iced_winit::Position::from(settings.position), - min_size: settings.min_size, - max_size: settings.max_size, - visible: settings.visible, - resizable: settings.resizable, - decorations: settings.decorations, - transparent: settings.transparent, - level: settings.level, - icon: settings.icon.map(Icon::into), - platform_specific: settings.platform_specific, - } - } -} diff --git a/core/src/window/settings/macos.rs b/core/src/window/settings/macos.rs new file mode 100644 index 00000000..f86e63ad --- /dev/null +++ b/core/src/window/settings/macos.rs @@ -0,0 +1,12 @@ +//! Platform specific settings for macOS. + +/// The platform specific window settings of an application. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] +pub struct PlatformSpecific { + /// Hides the window title. + pub title_hidden: bool, + /// Makes the titlebar transparent and allows the content to appear behind it. + pub titlebar_transparent: bool, + /// Makes the window content appear behind the titlebar. + pub fullsize_content_view: bool, +} diff --git a/core/src/window/settings/other.rs b/core/src/window/settings/other.rs new file mode 100644 index 00000000..b1103f62 --- /dev/null +++ b/core/src/window/settings/other.rs @@ -0,0 +1,3 @@ +/// The platform specific window settings of an application. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] +pub struct PlatformSpecific; diff --git a/core/src/window/settings/wasm.rs b/core/src/window/settings/wasm.rs new file mode 100644 index 00000000..8e0f1bbc --- /dev/null +++ b/core/src/window/settings/wasm.rs @@ -0,0 +1,11 @@ +//! Platform specific settings for WebAssembly. + +/// The platform specific window settings of an application. +#[derive(Debug, Clone, PartialEq, Eq, Default)] +pub struct PlatformSpecific { + /// The identifier of a DOM element that will be replaced with the + /// application. + /// + /// If set to `None`, the application will be appended to the HTML body. + pub target: Option<String>, +} diff --git a/core/src/window/settings/windows.rs b/core/src/window/settings/windows.rs new file mode 100644 index 00000000..45d753bd --- /dev/null +++ b/core/src/window/settings/windows.rs @@ -0,0 +1,21 @@ +//! Platform specific settings for Windows. +use raw_window_handle::RawWindowHandle; + +/// The platform specific window settings of an application. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct PlatformSpecific { + /// Parent window + pub parent: Option<RawWindowHandle>, + + /// Drag and drop support + pub drag_and_drop: bool, +} + +impl Default for PlatformSpecific { + fn default() -> Self { + Self { + parent: None, + drag_and_drop: true, + } + } +} |