From adf0338ed83c5badad346e3a13ee848bd13b975a Mon Sep 17 00:00:00 2001 From: Markus Siglreithmaier Date: Mon, 3 Jan 2022 23:24:36 +0100 Subject: [PATCH] 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. --- examples/src/lib.rs | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/examples/src/lib.rs b/examples/src/lib.rs index ab087e9..e88da2b 100644 --- a/examples/src/lib.rs +++ b/examples/src/lib.rs @@ -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(), + _ => (), } }); }