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

@ -1,6 +1,5 @@
use crate::dpi::{LogicalPosition, LogicalSize};
use crate::error::{ExternalError, NotSupportedError, OsError as RootOE};
use crate::event::{Event, WindowEvent};
use crate::icon::Icon;
use crate::monitor::MonitorHandle as RootMH;
use crate::window::{CursorIcon, WindowAttributes, WindowId as RootWI};
@ -16,6 +15,7 @@ pub struct Window {
previous_pointer: RefCell<&'static str>,
position: RefCell<LogicalPosition>,
id: Id,
register_redraw_request: Box<dyn Fn()>,
}
impl Window {
@ -28,12 +28,9 @@ impl Window {
let id = target.generate_id();
let mut canvas = backend::Canvas::create(move || {
runner.send_event(Event::WindowEvent {
window_id: RootWI(id),
event: WindowEvent::RedrawRequested,
})
})?;
let mut canvas = backend::Canvas::create()?;
let register_redraw_request = Box::new(move || runner.request_redraw(RootWI(id)));
target.register(&mut canvas, id);
@ -42,6 +39,7 @@ impl Window {
previous_pointer: RefCell::new("auto"),
position: RefCell::new(LogicalPosition { x: 0.0, y: 0.0 }),
id,
register_redraw_request,
};
window.set_inner_size(attr.inner_size.unwrap_or(LogicalSize {
@ -69,7 +67,7 @@ impl Window {
}
pub fn request_redraw(&self) {
self.canvas.request_redraw();
(self.register_redraw_request)();
}
pub fn outer_position(&self) -> Result<LogicalPosition, NotSupportedError> {