api: replace WindowId From/Into u64 with WindowId::{from,into}_raw()

Co-authored-by: Mads Marquart <mads@marquart.dk>
Co-authored-by: Kirill Chibisov <contact@kchibisov.com>
This commit is contained in:
daxpedda 2024-09-27 22:12:50 +02:00 committed by GitHub
parent 380eea0072
commit 6e1b9fa24d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 62 additions and 93 deletions

View file

@ -49,7 +49,7 @@ struct Execution {
suspended: Cell<bool>,
event_loop_recreation: Cell<bool>,
events: RefCell<VecDeque<EventWrapper>>,
id: RefCell<u32>,
id: Cell<u64>,
window: web_sys::Window,
navigator: Navigator,
document: Document,
@ -171,7 +171,7 @@ impl Shared {
window,
navigator,
document,
id: RefCell::new(0),
id: Cell::new(0),
all_canvases: RefCell::new(Vec::new()),
redraw_pending: RefCell::new(HashSet::new()),
destroy_pending: RefCell::new(VecDeque::new()),
@ -438,11 +438,11 @@ impl Shared {
// Generate a strictly increasing ID
// This is used to differentiate windows when handling events
pub fn generate_id(&self) -> u32 {
let mut id = self.0.id.borrow_mut();
*id += 1;
pub fn generate_id(&self) -> u64 {
let id = self.0.id.get();
self.0.id.set(id.checked_add(1).expect("exhausted `WindowId`"));
*id
id
}
pub fn request_redraw(&self, id: WindowId) {

View file

@ -430,23 +430,19 @@ impl Drop for Inner {
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct WindowId(pub(crate) u32);
pub struct WindowId(pub(crate) u64);
impl WindowId {
pub const fn dummy() -> Self {
Self(0)
}
}
impl From<WindowId> for u64 {
fn from(window_id: WindowId) -> Self {
window_id.0 as u64
pub const fn into_raw(self) -> u64 {
self.0
}
}
impl From<u64> for WindowId {
fn from(raw_id: u64) -> Self {
Self(raw_id as u32)
pub const fn from_raw(id: u64) -> Self {
Self(id)
}
}