Made poll events loop over as many events as there may be instead of just one. (#333)

This commit is contained in:
Ken Reed 2017-10-29 02:02:57 -04:00 committed by tomaka
parent b3c5ee6219
commit 01d1178d7b

View file

@ -44,11 +44,14 @@ impl EventsLoop {
MonitorId MonitorId
} }
pub fn poll_events<F>(&mut self, mut callback: F) pub fn poll_events<F>(&mut self, mut callback: F)
where F: FnMut(::Event) where F: FnMut(::Event)
{ {
let event = match self.event_rx.try_recv() { while let Ok(event) = self.event_rx.try_recv() {
Ok(android_glue::Event::EventMotion(motion)) => {
let e = match event{
android_glue::Event::EventMotion(motion) => {
Some(Event::WindowEvent { Some(Event::WindowEvent {
window_id: RootWindowId(WindowId), window_id: RootWindowId(WindowId),
event: WindowEvent::Touch(Touch { event: WindowEvent::Touch(Touch {
@ -64,16 +67,16 @@ impl EventsLoop {
}), }),
}) })
}, },
Ok(android_glue::Event::InitWindow) => { android_glue::Event::InitWindow => {
// The activity went to foreground. // The activity went to foreground.
Some(Event::Suspended(false)) Some(Event::Suspended(false))
}, },
Ok(android_glue::Event::TermWindow) => { android_glue::Event::TermWindow => {
// The activity went to background. // The activity went to background.
Some(Event::Suspended(true)) Some(Event::Suspended(true))
}, },
Ok(android_glue::Event::WindowResized) | android_glue::Event::WindowResized |
Ok(android_glue::Event::ConfigChanged) => { android_glue::Event::ConfigChanged => {
// Activity Orientation changed or resized. // Activity Orientation changed or resized.
let native_window = unsafe { android_glue::get_native_window() }; let native_window = unsafe { android_glue::get_native_window() };
if native_window.is_null() { if native_window.is_null() {
@ -87,7 +90,7 @@ impl EventsLoop {
}) })
} }
}, },
Ok(android_glue::Event::WindowRedrawNeeded) => { android_glue::Event::WindowRedrawNeeded => {
// The activity needs to be redrawn. // The activity needs to be redrawn.
Some(Event::WindowEvent { Some(Event::WindowEvent {
window_id: RootWindowId(WindowId), window_id: RootWindowId(WindowId),
@ -99,9 +102,10 @@ impl EventsLoop {
} }
}; };
if let Some(event) = event { if let Some(event) = e {
callback(event); callback(event);
} }
};
} }
pub fn run_forever<F>(&mut self, mut callback: F) pub fn run_forever<F>(&mut self, mut callback: F)