2023-12-02 20:41:58 +01:00
|
|
|
use std::hash::Hash;
|
|
|
|
|
|
|
|
|
|
use std::sync::atomic::{self, AtomicU64};
|
2022-06-21 15:59:45 -03:00
|
|
|
|
2022-07-26 16:46:12 -03:00
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
2023-07-12 19:21:05 -07:00
|
|
|
/// The id of the window.
|
2023-03-13 18:19:16 -07:00
|
|
|
///
|
2023-07-12 19:21:05 -07:00
|
|
|
/// Internally Iced reserves `window::Id::MAIN` for the first window spawned.
|
2022-06-21 15:59:45 -03:00
|
|
|
pub struct Id(u64);
|
|
|
|
|
|
2023-12-02 20:41:58 +01:00
|
|
|
static COUNT: AtomicU64 = AtomicU64::new(1);
|
|
|
|
|
|
2022-06-21 15:59:45 -03:00
|
|
|
impl Id {
|
2023-07-12 19:21:05 -07:00
|
|
|
/// The reserved window [`Id`] for the first window in an Iced application.
|
2022-09-19 20:59:37 -03:00
|
|
|
pub const MAIN: Self = Id(0);
|
|
|
|
|
|
2023-07-12 19:21:05 -07:00
|
|
|
/// Creates a new unique window [`Id`].
|
2023-12-02 20:41:58 +01:00
|
|
|
pub fn unique() -> Id {
|
|
|
|
|
Id(COUNT.fetch_add(1, atomic::Ordering::Relaxed))
|
2022-06-21 15:59:45 -03:00
|
|
|
}
|
|
|
|
|
}
|