diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/src/event.rs | 2 | ||||
-rw-r--r-- | core/src/widget/tree.rs | 2 | ||||
-rw-r--r-- | core/src/window/id.rs | 28 | ||||
-rw-r--r-- | core/src/window/position.rs | 0 | ||||
-rw-r--r-- | core/src/window/settings.rs | 76 |
5 files changed, 106 insertions, 2 deletions
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 0af40c33..da269632 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/id.rs b/core/src/window/id.rs new file mode 100644 index 00000000..0a11b1aa --- /dev/null +++ b/core/src/window/id.rs @@ -0,0 +1,28 @@ +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. +/// +/// Internally Iced uses `window::Id::MAIN` as the first window spawned. +pub struct Id(u64); + +impl Id { + /// The reserved window ID for the primary 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()) + } +} + +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 new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/core/src/window/position.rs diff --git a/core/src/window/settings.rs b/core/src/window/settings.rs new file mode 100644 index 00000000..458b9232 --- /dev/null +++ b/core/src/window/settings.rs @@ -0,0 +1,76 @@ +use crate::window::{Icon, Level, Position}; + +pub use iced_winit::settings::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, +} + +impl Default for Settings { + fn default() -> Settings { + Settings { + 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, + platform_specific: Default::default(), + } + } +} + +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, + } + } +} |