On Web, use the new WebCanvasWindowHandle (#3270)

This commit is contained in:
daxpedda
2023-12-22 22:33:50 +01:00
committed by GitHub
parent 2c15de7cf9
commit 8cd3aaa8a2
8 changed files with 54 additions and 20 deletions

View File

@@ -1,4 +1,5 @@
use std::cell::Cell;
use std::ops::Deref;
use std::rc::Rc;
use std::sync::{Arc, Mutex};
@@ -49,7 +50,8 @@ pub struct Common {
pub window: web_sys::Window,
pub document: Document,
/// Note: resizing the HTMLCanvasElement should go through `backend::set_canvas_size` to ensure the DPI factor is maintained.
pub raw: HtmlCanvasElement,
/// Note: this is read-only because we use a pointer to this for [`WindowHandle`](rwh_06::WindowHandle).
raw: Rc<HtmlCanvasElement>,
style: Style,
old_size: Rc<Cell<PhysicalSize<u32>>>,
current_size: Rc<Cell<PhysicalSize<u32>>>,
@@ -101,7 +103,7 @@ impl Canvas {
let common = Common {
window: window.clone(),
document: document.clone(),
raw: canvas.clone(),
raw: Rc::new(canvas.clone()),
style,
old_size: Rc::default(),
current_size: Rc::default(),
@@ -539,7 +541,11 @@ impl Common {
E: 'static + AsRef<web_sys::Event> + wasm_bindgen::convert::FromWasmAbi,
F: 'static + FnMut(E),
{
EventListenerHandle::new(self.raw.clone(), event_name, Closure::new(handler))
EventListenerHandle::new(self.raw.deref().clone(), event_name, Closure::new(handler))
}
pub fn raw(&self) -> &HtmlCanvasElement {
&self.raw
}
}