2022-06-21 15:59:45 -03:00
|
|
|
use std::collections::hash_map::DefaultHasher;
|
2023-01-05 15:26:28 -08:00
|
|
|
use std::fmt::{Display, Formatter};
|
2022-06-21 15:59:45 -03:00
|
|
|
use std::hash::{Hash, Hasher};
|
|
|
|
|
|
2022-07-26 16:46:12 -03:00
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
2023-01-05 15:26:28 -08:00
|
|
|
/// The ID of the window.
|
|
|
|
|
///
|
|
|
|
|
/// This is not necessarily the same as the window ID fetched from `winit::window::Window`.
|
2022-06-21 15:59:45 -03:00
|
|
|
pub struct Id(u64);
|
|
|
|
|
|
|
|
|
|
impl Id {
|
2022-09-19 20:59:37 -03:00
|
|
|
/// TODO(derezzedex): maybe change `u64` to an enum `Type::{Single, Multi(u64)}`
|
|
|
|
|
pub const MAIN: Self = Id(0);
|
|
|
|
|
|
2023-01-05 15:26:28 -08:00
|
|
|
/// Creates a new unique window ID.
|
2022-06-21 15:59:45 -03:00
|
|
|
pub fn new(id: impl Hash) -> Id {
|
|
|
|
|
let mut hasher = DefaultHasher::new();
|
|
|
|
|
id.hash(&mut hasher);
|
|
|
|
|
|
|
|
|
|
Id(hasher.finish())
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-01-05 15:26:28 -08:00
|
|
|
|
|
|
|
|
impl Display for Id {
|
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
|
|
|
write!(f, "Id({})", self.0)
|
|
|
|
|
}
|
|
|
|
|
}
|