Fix web redraw requested (#1181)

* Keep track of what windows have requested redraw

Instead of using request_animation_frame and sending redraw request
events, just keep track of all windows that have asked for a redraw.
This doesn't handle dispatching the events

* Issue redraw events to windows that request it

* Cargo fmt
This commit is contained in:
Ryan G 2019-09-23 09:14:26 -04:00 committed by GitHub
parent 2c47c43f47
commit 28a50817af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 36 deletions

View file

@ -9,7 +9,6 @@ use web_sys::{FocusEvent, HtmlCanvasElement, KeyboardEvent, PointerEvent, WheelE
pub struct Canvas {
raw: HtmlCanvasElement,
on_redraw: Closure<dyn Fn()>,
on_focus: Option<Closure<dyn FnMut(FocusEvent)>>,
on_blur: Option<Closure<dyn FnMut(FocusEvent)>>,
on_keyboard_release: Option<Closure<dyn FnMut(KeyboardEvent)>>,
@ -30,10 +29,7 @@ impl Drop for Canvas {
}
impl Canvas {
pub fn create<F>(on_redraw: F) -> Result<Self, RootOE>
where
F: 'static + Fn(),
{
pub fn create() -> Result<Self, RootOE> {
let window =
web_sys::window().ok_or(os_error!(OsError("Failed to obtain window".to_owned())))?;
@ -57,7 +53,6 @@ impl Canvas {
Ok(Canvas {
raw: canvas,
on_redraw: Closure::wrap(Box::new(on_redraw) as Box<dyn Fn()>),
on_blur: None,
on_focus: None,
on_keyboard_release: None,
@ -101,13 +96,6 @@ impl Canvas {
&self.raw
}
pub fn request_redraw(&self) {
let window = web_sys::window().expect("Failed to obtain window");
window
.request_animation_frame(&self.on_redraw.as_ref().unchecked_ref())
.expect("Failed to request animation frame");
}
pub fn on_blur<F>(&mut self, mut handler: F)
where
F: 'static + FnMut(),