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:
parent
2c47c43f47
commit
28a50817af
4 changed files with 34 additions and 36 deletions
|
|
@ -4,7 +4,6 @@ use crate::error::OsError as RootOE;
|
|||
use crate::event::{ModifiersState, MouseButton, MouseScrollDelta, ScanCode, VirtualKeyCode};
|
||||
use crate::platform_impl::OsError;
|
||||
|
||||
use std::rc::Rc;
|
||||
use stdweb::traits::IPointerEvent;
|
||||
use stdweb::unstable::TryInto;
|
||||
use stdweb::web::event::{
|
||||
|
|
@ -13,12 +12,11 @@ use stdweb::web::event::{
|
|||
};
|
||||
use stdweb::web::html_element::CanvasElement;
|
||||
use stdweb::web::{
|
||||
document, window, EventListenerHandle, IChildNode, IElement, IEventTarget, IHtmlElement,
|
||||
document, EventListenerHandle, IChildNode, IElement, IEventTarget, IHtmlElement,
|
||||
};
|
||||
|
||||
pub struct Canvas {
|
||||
raw: CanvasElement,
|
||||
on_redraw: Rc<dyn Fn()>,
|
||||
on_focus: Option<EventListenerHandle>,
|
||||
on_blur: Option<EventListenerHandle>,
|
||||
on_keyboard_release: Option<EventListenerHandle>,
|
||||
|
|
@ -39,10 +37,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 canvas: CanvasElement = document()
|
||||
.create_element("canvas")
|
||||
.map_err(|_| os_error!(OsError("Failed to create canvas element".to_owned())))?
|
||||
|
|
@ -60,7 +55,6 @@ impl Canvas {
|
|||
|
||||
Ok(Canvas {
|
||||
raw: canvas,
|
||||
on_redraw: Rc::new(on_redraw),
|
||||
on_blur: None,
|
||||
on_focus: None,
|
||||
on_keyboard_release: None,
|
||||
|
|
@ -104,11 +98,6 @@ impl Canvas {
|
|||
&self.raw
|
||||
}
|
||||
|
||||
pub fn request_redraw(&self) {
|
||||
let on_redraw = self.on_redraw.clone();
|
||||
window().request_animation_frame(move |_| on_redraw());
|
||||
}
|
||||
|
||||
pub fn on_blur<F>(&mut self, mut handler: F)
|
||||
where
|
||||
F: 'static + FnMut(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue