diff --git a/crates/ui-egui/src/app/control.rs b/crates/ui-egui/src/app/control.rs index a5485c379..8d1ecf1c7 100644 --- a/crates/ui-egui/src/app/control.rs +++ b/crates/ui-egui/src/app/control.rs @@ -41,6 +41,10 @@ impl SlideApp { channel.captures.note_pass(); let finished = channel.captures.issue(&host, craft::ui::runtime::motion::now(), document); control::finish_captures(self, &mut channel, finished); + // A capture settles over passes and waits out its delay; an idle window would draw no more of them. + if channel.captures.any_unissued() { + ui.ctx().request_repaint(); + } self.control = Some(channel); } } diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rs index 9932675f3..33a8c81b6 100644 --- a/crates/ui-egui/src/control.rs +++ b/crates/ui-egui/src/control.rs @@ -967,6 +967,41 @@ mod tests { Ok(()) } + /// A screenshot needs passes to settle before it is issued: an idle window keeps asking for them until it is. + #[test] + fn a_screenshot_keeps_an_idle_window_painting_until_it_is_issued() -> Result<(), Box> { + let (sender, receiver) = mpsc::channel(); + let mut harness = harness_with( + deckcraft_engine::Session::with_new(), + crate::Services::default(), + egui_kittest::Harness::builder().with_size(egui::vec2(1440.0, 900.0)).with_step_dt(1.0 / 60.0), + |platform| platform.control = Some(ControlChannel::new(receiver)), + ); + let idle = |harness: &mut egui_kittest::Harness<'static, SlideApp>| { + (0..600).any(|_| { + harness.run_steps(1); + !harness.ctx.has_requested_repaint() + }) + }; + assert!(idle(&mut harness), "the window goes idle before the request"); + let (request, _reply) = ControlRequest::new("ui.screenshot", json!({})); + sender.send(request).map_err(|_| "control channel closed")?; + let unissued = + |harness: &egui_kittest::Harness<'static, SlideApp>| harness.state().control.as_ref().is_some_and(|c| c.captures.any_unissued()); + harness.run_steps(1); + assert!(unissued(&harness), "the request is admitted and settling"); + for _ in 0..600 { + if !unissued(&harness) { + break; + } + assert!(harness.ctx.has_requested_repaint(), "a settling screenshot asks for the next pass"); + std::thread::sleep(std::time::Duration::from_millis(2)); + harness.run_steps(1); + } + assert!(!unissued(&harness), "the capture was issued"); + Ok(()) + } + /// A request from a client's own thread is answered by the UI thread's frame: the connection thread only /// forwards it and asks for a repaint, so it never touches a running pass's state. #[cfg(not(target_arch = "wasm32"))]