diff options
author | 2024-10-22 00:13:42 +0200 | |
---|---|---|
committer | 2024-11-05 23:52:56 +0100 | |
commit | 5c33ce18ed8b12db9a6ba138112804761d26fddb (patch) | |
tree | cb51c63fb14c4c84e20fd6f201ffaaaf86dc7b0c /winit | |
parent | 42a2cb6d4f78343f43d6a68a28e5502d9426ed2c (diff) | |
download | iced-5c33ce18ed8b12db9a6ba138112804761d26fddb.tar.gz iced-5c33ce18ed8b12db9a6ba138112804761d26fddb.tar.bz2 iced-5c33ce18ed8b12db9a6ba138112804761d26fddb.zip |
Draft `reactive-rendering` feature for `button`
Diffstat (limited to 'winit')
-rw-r--r-- | winit/Cargo.toml | 2 | ||||
-rw-r--r-- | winit/src/program.rs | 95 | ||||
-rw-r--r-- | winit/src/program/state.rs | 5 |
3 files changed, 74 insertions, 28 deletions
diff --git a/winit/Cargo.toml b/winit/Cargo.toml index bd6feb00..b8f5a723 100644 --- a/winit/Cargo.toml +++ b/winit/Cargo.toml @@ -22,7 +22,7 @@ x11 = ["winit/x11"] wayland = ["winit/wayland"] wayland-dlopen = ["winit/wayland-dlopen"] wayland-csd-adwaita = ["winit/wayland-csd-adwaita"] -multi-window = ["iced_runtime/multi-window"] +reactive-rendering = [] [dependencies] iced_futures.workspace = true diff --git a/winit/src/program.rs b/winit/src/program.rs index 8d1eec3a..2ac7ad0d 100644 --- a/winit/src/program.rs +++ b/winit/src/program.rs @@ -691,6 +691,7 @@ async fn run_instance<P, C>( let mut ui_caches = FxHashMap::default(); let mut user_interfaces = ManuallyDrop::new(FxHashMap::default()); let mut clipboard = Clipboard::unconnected(); + let mut redraw_queue = Vec::new(); debug.startup_finished(); @@ -758,14 +759,30 @@ async fn run_instance<P, C>( } Event::EventLoopAwakened(event) => { match event { - event::Event::NewEvents( - event::StartCause::Init - | event::StartCause::ResumeTimeReached { .. }, - ) => { + event::Event::NewEvents(event::StartCause::Init) => { for (_id, window) in window_manager.iter_mut() { window.raw.request_redraw(); } } + event::Event::NewEvents( + event::StartCause::ResumeTimeReached { .. }, + ) => { + let now = Instant::now(); + + while let Some((target, id)) = + redraw_queue.last().copied() + { + if target > now { + break; + } + + let _ = redraw_queue.pop(); + + if let Some(window) = window_manager.get_mut(id) { + window.raw.request_redraw(); + } + } + } event::Event::PlatformSpecific( event::PlatformSpecific::MacOS( event::MacOS::ReceivedUrl(url), @@ -857,23 +874,19 @@ async fn run_instance<P, C>( status: core::event::Status::Ignored, }); - let _ = control_sender.start_send(Control::ChangeFlow( - match ui_state { - user_interface::State::Updated { - redraw_request: Some(redraw_request), - } => match redraw_request { - window::RedrawRequest::NextFrame => { - window.raw.request_redraw(); - - ControlFlow::Wait - } - window::RedrawRequest::At(at) => { - ControlFlow::WaitUntil(at) - } - }, - _ => ControlFlow::Wait, - }, - )); + if let user_interface::State::Updated { + redraw_request: Some(redraw_request), + } = ui_state + { + match redraw_request { + window::RedrawRequest::NextFrame => { + window.raw.request_redraw(); + } + window::RedrawRequest::At(at) => { + redraw_queue.push((at, id)); + } + } + } let physical_size = window.state.physical_size(); @@ -1065,13 +1078,25 @@ async fn run_instance<P, C>( &mut messages, ); + #[cfg(not(feature = "reactive-rendering"))] window.raw.request_redraw(); - if !uis_stale { - uis_stale = matches!( - ui_state, - user_interface::State::Outdated - ); + match ui_state { + #[cfg(feature = "reactive-rendering")] + user_interface::State::Updated { + redraw_request: Some(redraw_request), + } => match redraw_request { + window::RedrawRequest::NextFrame => { + window.raw.request_redraw(); + } + window::RedrawRequest::At(at) => { + redraw_queue.push((at, id)); + } + }, + user_interface::State::Outdated => { + uis_stale = true; + } + user_interface::State::Updated { .. } => {} } for (event, status) in window_events @@ -1139,6 +1164,24 @@ async fn run_instance<P, C>( actions = 0; } } + + if !redraw_queue.is_empty() { + redraw_queue.sort_by( + |(target_a, _), (target_b, _)| { + target_a.cmp(target_b).reverse() + }, + ); + + let (target, _id) = redraw_queue + .last() + .copied() + .expect("Redraw queue is not empty"); + + let _ = + control_sender.start_send(Control::ChangeFlow( + ControlFlow::WaitUntil(target), + )); + } } _ => {} } diff --git a/winit/src/program/state.rs b/winit/src/program/state.rs index a7fa2788..b8a58960 100644 --- a/winit/src/program/state.rs +++ b/winit/src/program/state.rs @@ -190,7 +190,10 @@ where .. }, .. - } => _debug.toggle(), + } => { + _debug.toggle(); + window.request_redraw(); + } _ => {} } } |