-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
228 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
use std::collections::hash_map::DefaultHasher; | ||
use std::hash::{Hash, Hasher}; | ||
use std::hash::Hash; | ||
|
||
use std::sync::atomic::{self, AtomicU64}; | ||
|
||
#[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); | ||
|
||
static COUNT: AtomicU64 = AtomicU64::new(1); | ||
|
||
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()) | ||
pub fn unique() -> Id { | ||
Id(COUNT.fetch_add(1, atomic::Ordering::Relaxed)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.