From 48cebbb22cfd701984017f1f3336735bc70272d3 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 19 Dec 2023 12:37:04 +0100 Subject: Fix redraw request handling in new event loop logic --- winit/src/application.rs | 61 +++++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/winit/src/application.rs b/winit/src/application.rs index ed6ba9eb..aea828bc 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -338,6 +338,38 @@ async fn run_instance( event: event::WindowEvent::RedrawRequested { .. }, .. } => { + // TODO: Avoid redrawing all the time by forcing widgets to + // request redraws on state changes + // + // Then, we can use the `interface_state` here to decide if a redraw + // is needed right away, or simply wait until a specific time. + let redraw_event = Event::Window( + window::Id::MAIN, + window::Event::RedrawRequested(Instant::now()), + ); + + let (interface_state, _) = user_interface.update( + &[redraw_event.clone()], + state.cursor(), + &mut renderer, + &mut clipboard, + &mut messages, + ); + + let _ = control_sender.start_send(match interface_state { + user_interface::State::Updated { + redraw_request: Some(redraw_request), + } => match redraw_request { + window::RedrawRequest::NextFrame => ControlFlow::Poll, + window::RedrawRequest::At(at) => { + ControlFlow::WaitUntil(at) + } + }, + _ => ControlFlow::Wait, + }); + + runtime.broadcast(redraw_event, core::event::Status::Ignored); + debug.draw_started(); let new_mouse_interaction = user_interface.draw( &mut renderer, @@ -514,36 +546,7 @@ async fn run_instance( } } - // TODO: Avoid redrawing all the time by forcing widgets to - // request redraws on state changes - // - // Then, we can use the `interface_state` here to decide if a redraw - // is needed right away, or simply wait until a specific time. - let redraw_event = Event::Window( - window::Id::MAIN, - window::Event::RedrawRequested(Instant::now()), - ); - - let (interface_state, _) = user_interface.update( - &[redraw_event.clone()], - state.cursor(), - &mut renderer, - &mut clipboard, - &mut messages, - ); - window.request_redraw(); - runtime.broadcast(redraw_event, core::event::Status::Ignored); - - let _ = control_sender.start_send(match interface_state { - user_interface::State::Updated { - redraw_request: Some(redraw_request), - } => match redraw_request { - window::RedrawRequest::NextFrame => ControlFlow::Poll, - window::RedrawRequest::At(at) => ControlFlow::WaitUntil(at), - }, - _ => ControlFlow::Wait, - }); redraw_pending = false; } -- cgit