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
.borrow_mut()
.run_return(|event, _, control_flow| {
*control_flow = ControlFlow::Wait;
f();
if let Event::WindowEvent {
event:
WindowEvent::CloseRequested
| WindowEvent::KeyboardInput {
input:
KeyboardInput {
state: ElementState::Pressed,
virtual_keycode: Some(VirtualKeyCode::Escape),
..
},
..
},
..
} = event
{
*control_flow = ControlFlow::Exit
*control_flow = ControlFlow::Poll;
match event {
Event::WindowEvent {
event:
WindowEvent::CloseRequested
| WindowEvent::KeyboardInput {
input:
KeyboardInput {
state: ElementState::Pressed,
virtual_keycode: Some(VirtualKeyCode::Escape),
..
},
..
},
..
} => *control_flow = ControlFlow::Exit,
Event::MainEventsCleared => f(),
_ => (),
}
});
}