example: Refactor event loop handling for continuous redraw (#542)

Switch to continuous redrawing using `Poll` and `MainEventsCleared`.

Fixes hangs in case of non-Mailbox present modes.
This commit is contained in:
Markus Siglreithmaier 2022-01-03 23:24:36 +01:00 committed by GitHub
parent 8f05905ecb
commit adf0338ed8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -184,24 +184,24 @@ impl ExampleBase {
self.event_loop self.event_loop
.borrow_mut() .borrow_mut()
.run_return(|event, _, control_flow| { .run_return(|event, _, control_flow| {
*control_flow = ControlFlow::Wait; *control_flow = ControlFlow::Poll;
f(); match event {
if let Event::WindowEvent { Event::WindowEvent {
event: event:
WindowEvent::CloseRequested WindowEvent::CloseRequested
| WindowEvent::KeyboardInput { | WindowEvent::KeyboardInput {
input: input:
KeyboardInput { KeyboardInput {
state: ElementState::Pressed, state: ElementState::Pressed,
virtual_keycode: Some(VirtualKeyCode::Escape), virtual_keycode: Some(VirtualKeyCode::Escape),
.. ..
}, },
.. ..
}, },
.. ..
} = event } => *control_flow = ControlFlow::Exit,
{ Event::MainEventsCleared => f(),
*control_flow = ControlFlow::Exit _ => (),
} }
}); });
} }