Implement revamped RedrawRequested on Web (#1301)

* Implement revamped `RedrawRequested` on Web

* Add `web` example
This commit is contained in:
Héctor Ramón 2019-12-03 18:16:06 +01:00 committed by Osspial
parent 5b489284e4
commit 133b11fa6d
3 changed files with 81 additions and 9 deletions

View file

@ -1,5 +1,5 @@
use super::{backend, state::State};
use crate::event::{Event, StartCause, WindowEvent};
use crate::event::{Event, StartCause};
use crate::event_loop as root;
use crate::window::WindowId;
@ -127,18 +127,15 @@ impl<T: 'static> Shared<T> {
if !event_is_start {
self.handle_event(event, &mut control);
}
self.handle_event(Event::MainEventsCleared, &mut control);
// Collect all of the redraw events to avoid double-locking the RefCell
let redraw_events: Vec<WindowId> = self.0.redraw_pending.borrow_mut().drain().collect();
for window_id in redraw_events {
self.handle_event(
Event::WindowEvent {
window_id,
event: WindowEvent::RedrawRequested,
},
&mut control,
);
self.handle_event(Event::RedrawRequested(window_id), &mut control);
}
self.handle_event(Event::EventsCleared, &mut control);
self.handle_event(Event::RedrawEventsCleared, &mut control);
self.apply_control_flow(control);
// If the event loop is closed, it has been closed this iteration and now the closing
// event should be emitted