diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/Cargo.toml | 3 | ||||
-rw-r--r-- | core/src/event.rs | 2 | ||||
-rw-r--r-- | core/src/widget/tree.rs | 2 | ||||
-rw-r--r-- | core/src/window.rs | 6 | ||||
-rw-r--r-- | core/src/window/event.rs | 20 | ||||
-rw-r--r-- | core/src/window/id.rs | 21 | ||||
-rw-r--r-- | core/src/window/position.rs | 22 | ||||
-rw-r--r-- | core/src/window/settings.rs | 94 | ||||
-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 |
13 files changed, 223 insertions, 5 deletions
diff --git a/core/Cargo.toml b/core/Cargo.toml index 82946847..7db4fa53 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -23,5 +23,8 @@ palette.optional = true [target.'cfg(target_arch = "wasm32")'.dependencies] instant.workspace = true +[target.'cfg(windows)'.dependencies.raw-window-handle] +version = "0.5.2" + [dev-dependencies] approx = "0.5" diff --git a/core/src/event.rs b/core/src/event.rs index 953cd73f..870b3074 100644 --- a/core/src/event.rs +++ b/core/src/event.rs @@ -19,7 +19,7 @@ pub enum Event { Mouse(mouse::Event), /// A window event - Window(window::Event), + Window(window::Id, window::Event), /// A touch event Touch(touch::Event), diff --git a/core/src/widget/tree.rs b/core/src/widget/tree.rs index d4b8828a..ff52b1ce 100644 --- a/core/src/widget/tree.rs +++ b/core/src/widget/tree.rs @@ -67,7 +67,7 @@ impl Tree { } } - /// Reconciliates the children of the tree with the provided list of widgets. + /// Reconciles the children of the tree with the provided list of widgets. pub fn diff_children<'a, Message, Renderer>( &mut self, new_children: &[impl Borrow<dyn Widget<Message, Renderer> + 'a>], diff --git a/core/src/window.rs b/core/src/window.rs index a6dbdfb4..448ffc45 100644 --- a/core/src/window.rs +++ b/core/src/window.rs @@ -1,15 +1,21 @@ //! Build window-based GUI applications. pub mod icon; +pub mod settings; mod event; +mod id; mod level; mod mode; +mod position; mod redraw_request; 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..f7759435 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; @@ -27,11 +28,24 @@ 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 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 new file mode 100644 index 00000000..65002d43 --- /dev/null +++ b/core/src/window/id.rs @@ -0,0 +1,21 @@ +use std::collections::hash_map::DefaultHasher; +use std::hash::{Hash, Hasher}; + +#[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); + +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 new(id: impl Hash) -> Id { + let mut hasher = DefaultHasher::new(); + id.hash(&mut hasher); + + Id(hasher.finish()) + } +} diff --git a/core/src/window/position.rs b/core/src/window/position.rs new file mode 100644 index 00000000..c260c29e --- /dev/null +++ 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 new file mode 100644 index 00000000..25df8159 --- /dev/null +++ b/core/src/window/settings.rs @@ -0,0 +1,94 @@ +//! 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}; + +pub use platform::PlatformSpecific; +/// The window settings of an application. +#[derive(Debug, Clone)] +pub struct Settings { + /// The initial size of the window. + pub size: (u32, u32), + + /// The initial position of the window. + pub position: Position, + + /// The minimum size of the window. + pub min_size: Option<(u32, u32)>, + + /// The maximum size of the window. + pub max_size: Option<(u32, u32)>, + + /// 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: (1024, 768), + 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, + } + } +} |