mirror of
https://github.com/rust-windowing/winit.git
synced 2026-06-27 07:03:15 -04:00
On Web, use the new WebCanvasWindowHandle (#3270)
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user