Stop polling in event loop on RedrawRequest::NextFrame
This commit is contained in:
parent
e772e5a9e9
commit
50a7852cb8
3 changed files with 8 additions and 13 deletions
|
|
@ -275,8 +275,6 @@ where
|
|||
shell: &mut Shell<'_, Message>,
|
||||
_viewport: &Rectangle,
|
||||
) -> event::Status {
|
||||
const FRAME_RATE: u64 = 60;
|
||||
|
||||
let state = tree.state.downcast_mut::<State>();
|
||||
|
||||
if let Event::Window(_, window::Event::RedrawRequested(now)) = event {
|
||||
|
|
@ -287,9 +285,7 @@ where
|
|||
);
|
||||
|
||||
state.cache.clear();
|
||||
shell.request_redraw(RedrawRequest::At(
|
||||
now + Duration::from_millis(1000 / FRAME_RATE),
|
||||
));
|
||||
shell.request_redraw(RedrawRequest::NextFrame);
|
||||
}
|
||||
|
||||
event::Status::Ignored
|
||||
|
|
|
|||
|
|
@ -196,16 +196,12 @@ where
|
|||
shell: &mut Shell<'_, Message>,
|
||||
_viewport: &Rectangle,
|
||||
) -> event::Status {
|
||||
const FRAME_RATE: u64 = 60;
|
||||
|
||||
let state = tree.state.downcast_mut::<State>();
|
||||
|
||||
if let Event::Window(_, window::Event::RedrawRequested(now)) = event {
|
||||
*state = state.timed_transition(self.cycle_duration, now);
|
||||
|
||||
shell.request_redraw(RedrawRequest::At(
|
||||
now + Duration::from_millis(1000 / FRAME_RATE),
|
||||
));
|
||||
shell.request_redraw(RedrawRequest::NextFrame);
|
||||
}
|
||||
|
||||
event::Status::Ignored
|
||||
|
|
|
|||
|
|
@ -314,7 +314,6 @@ async fn run_instance<A, E, C>(
|
|||
match event {
|
||||
event::Event::NewEvents(
|
||||
event::StartCause::Init
|
||||
| event::StartCause::Poll
|
||||
| event::StartCause::ResumeTimeReached { .. },
|
||||
) if !redraw_pending => {
|
||||
window.request_redraw();
|
||||
|
|
@ -387,7 +386,11 @@ async fn run_instance<A, E, C>(
|
|||
user_interface::State::Updated {
|
||||
redraw_request: Some(redraw_request),
|
||||
} => match redraw_request {
|
||||
window::RedrawRequest::NextFrame => ControlFlow::Poll,
|
||||
window::RedrawRequest::NextFrame => {
|
||||
window.request_redraw();
|
||||
|
||||
ControlFlow::Wait
|
||||
}
|
||||
window::RedrawRequest::At(at) => {
|
||||
ControlFlow::WaitUntil(at)
|
||||
}
|
||||
|
|
@ -469,7 +472,7 @@ async fn run_instance<A, E, C>(
|
|||
_ => {}
|
||||
}
|
||||
|
||||
if !redraw_pending && events.is_empty() && messages.is_empty() {
|
||||
if events.is_empty() && messages.is_empty() {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue