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:
parent
8f05905ecb
commit
adf0338ed8
|
@ -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
|
_ => (),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue