diff options
author | 2023-12-05 01:03:09 +0100 | |
---|---|---|
committer | 2023-12-05 01:03:09 +0100 | |
commit | fc285d3e461626408c56bbc1605fcf0c974b2f69 (patch) | |
tree | 8aca292516d9aa43b78a14f51dd90caf60c691d7 /core/src/window | |
parent | 8727b3fc50ec251d9c117c51ca1289be5ba9b117 (diff) | |
parent | 5c5e7653bed248ba63faa6563e4d673e4441415e (diff) | |
download | iced-fc285d3e461626408c56bbc1605fcf0c974b2f69.tar.gz iced-fc285d3e461626408c56bbc1605fcf0c974b2f69.tar.bz2 iced-fc285d3e461626408c56bbc1605fcf0c974b2f69.zip |
Merge pull request #1964 from bungoboingo/feat/multi-window-support
[Feature] 🪟 Multi Window 🪟 .. redux!
Diffstat (limited to 'core/src/window')
-rw-r--r-- | core/src/window/event.rs | 22 | ||||
-rw-r--r-- | core/src/window/id.rs | 21 | ||||
-rw-r--r-- | core/src/window/position.rs | 24 | ||||
-rw-r--r-- | core/src/window/settings.rs | 95 | ||||
-rw-r--r-- | core/src/window/settings/linux.rs | 11 | ||||
-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 |
9 files changed, 216 insertions, 4 deletions
diff --git a/core/src/window/event.rs b/core/src/window/event.rs index e2fb5e66..b9ee7aca 100644 --- a/core/src/window/event.rs +++ b/core/src/window/event.rs @@ -1,10 +1,27 @@ use crate::time::Instant; +use crate::{Point, Size}; use std::path::PathBuf; /// A window-related event. -#[derive(PartialEq, Eq, Clone, Debug)] +#[derive(PartialEq, Clone, Debug)] pub enum Event { + /// A window was opened. + Opened { + /// The position of the opened 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. + /// + /// **Note**: Not available in Wayland. + position: Option<Point>, + /// The size of the created window. This is its "inner" size, or the size of the + /// client area, in logical pixels. + size: Size, + }, + + /// A window was closed. + Closed, + /// A window was moved. Moved { /// The new logical x location of the window @@ -27,9 +44,6 @@ pub enum Event { RedrawRequested(Instant), /// The user has requested for the window to close. - /// - /// Usually, you will want to terminate the execution whenever this event - /// occurs. CloseRequested, /// A window was focused. diff --git a/core/src/window/id.rs b/core/src/window/id.rs new file mode 100644 index 00000000..20474c8f --- /dev/null +++ b/core/src/window/id.rs @@ -0,0 +1,21 @@ +use std::hash::Hash; + +use std::sync::atomic::{self, AtomicU64}; + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] +/// The id of the window. +/// +/// Internally Iced reserves `window::Id::MAIN` for the first window spawned. +pub struct Id(u64); + +static COUNT: AtomicU64 = AtomicU64::new(1); + +impl Id { + /// The reserved window [`Id`] for the first window in an Iced application. + pub const MAIN: Self = Id(0); + + /// Creates a new unique window [`Id`]. + pub fn unique() -> Id { + Id(COUNT.fetch_add(1, atomic::Ordering::Relaxed)) + } +} diff --git a/core/src/window/position.rs b/core/src/window/position.rs new file mode 100644 index 00000000..73391e75 --- /dev/null +++ b/core/src/window/position.rs @@ -0,0 +1,24 @@ +use crate::Point; + +/// The position of a window in a given screen. +#[derive(Debug, Clone, Copy, PartialEq)] +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(Point), +} + +impl Default for Position { + fn default() -> Self { + Self::Default + } +} diff --git a/core/src/window/settings.rs b/core/src/window/settings.rs new file mode 100644 index 00000000..fbbf86ab --- /dev/null +++ b/core/src/window/settings.rs @@ -0,0 +1,95 @@ +//! Configure your windows. +#[cfg(target_os = "windows")] +#[path = "settings/windows.rs"] +mod platform; + +#[cfg(target_os = "macos")] +#[path = "settings/macos.rs"] +mod platform; + +#[cfg(target_os = "linux")] +#[path = "settings/linux.rs"] +mod platform; + +#[cfg(target_arch = "wasm32")] +#[path = "settings/wasm.rs"] +mod platform; + +#[cfg(not(any( + target_os = "windows", + target_os = "macos", + target_os = "linux", + target_arch = "wasm32" +)))] +#[path = "settings/other.rs"] +mod platform; + +use crate::window::{Icon, Level, Position}; +use crate::Size; + +pub use platform::PlatformSpecific; +/// The window settings of an application. +#[derive(Debug, Clone)] +pub struct Settings { + /// The initial logical dimensions of the window. + pub size: Size, + + /// The initial position of the window. + pub position: Position, + + /// The minimum size of the window. + pub min_size: Option<Size>, + + /// The maximum size of the window. + pub max_size: Option<Size>, + + /// Whether the window should be visible or not. + pub visible: bool, + + /// 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, + + /// Whether the window should be transparent. + pub transparent: bool, + + /// The window [`Level`]. + pub level: Level, + + /// The icon of the window. + pub icon: Option<Icon>, + + /// Platform specific settings. + pub platform_specific: PlatformSpecific, + + /// Whether the window will close when the user requests it, e.g. when a user presses the + /// close button. + /// + /// This can be useful if you want to have some behavior that executes before the window is + /// actually destroyed. If you disable this, you must manually close the window with the + /// `window::close` command. + /// + /// By default this is enabled. + pub exit_on_close_request: bool, +} + +impl Default for Settings { + fn default() -> Self { + Self { + size: Size::new(1024.0, 768.0), + position: Position::default(), + min_size: None, + max_size: None, + visible: true, + resizable: true, + decorations: true, + transparent: false, + level: Level::default(), + icon: None, + exit_on_close_request: true, + platform_specific: PlatformSpecific::default(), + } + } +} diff --git a/core/src/window/settings/linux.rs b/core/src/window/settings/linux.rs new file mode 100644 index 00000000..009b9d9e --- /dev/null +++ b/core/src/window/settings/linux.rs @@ -0,0 +1,11 @@ +//! Platform specific settings for Linux. + +/// The platform specific window settings of an application. +#[derive(Debug, Clone, PartialEq, Eq, Default)] +pub struct PlatformSpecific { + /// Sets the application id of the window. + /// + /// As a best practice, it is suggested to select an application id that match + /// the basename of the application’s .desktop file. + pub application_id: String, +} 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, + } + } +} |