summaryrefslogtreecommitdiffstats
path: root/native/src/window/id.rs
diff options
context:
space:
mode:
Diffstat (limited to 'native/src/window/id.rs')
-rw-r--r--native/src/window/id.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/native/src/window/id.rs b/native/src/window/id.rs
new file mode 100644
index 00000000..0c3e5272
--- /dev/null
+++ b/native/src/window/id.rs
@@ -0,0 +1,26 @@
+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.
+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)
+ }
+}