diff options
Diffstat (limited to '')
-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 (renamed from winit/src/settings/macos.rs) | 0 | ||||
-rw-r--r-- | core/src/window/settings/other.rs (renamed from winit/src/settings/other.rs) | 0 | ||||
-rw-r--r-- | core/src/window/settings/wasm.rs (renamed from winit/src/settings/wasm.rs) | 0 | ||||
-rw-r--r-- | core/src/window/settings/windows.rs (renamed from winit/src/settings/windows.rs) | 0 |
10 files changed, 73 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/winit/src/settings/macos.rs b/core/src/window/settings/macos.rs index f86e63ad..f86e63ad 100644 --- a/winit/src/settings/macos.rs +++ b/core/src/window/settings/macos.rs diff --git a/winit/src/settings/other.rs b/core/src/window/settings/other.rs index b1103f62..b1103f62 100644 --- a/winit/src/settings/other.rs +++ b/core/src/window/settings/other.rs diff --git a/winit/src/settings/wasm.rs b/core/src/window/settings/wasm.rs index 8e0f1bbc..8e0f1bbc 100644 --- a/winit/src/settings/wasm.rs +++ b/core/src/window/settings/wasm.rs diff --git a/winit/src/settings/windows.rs b/core/src/window/settings/windows.rs index 45d753bd..45d753bd 100644 --- a/winit/src/settings/windows.rs +++ b/core/src/window/settings/windows.rs |