From b79aca08fff10c14a3def455d64257ef5bcc781a Mon Sep 17 00:00:00 2001 From: qvest-ssels <214787280+qvest-ssels@users.noreply.github.com> Date: Sat, 28 Nov 2026 12:43:07 +0100 Subject: [PATCH] Contextual task bar: a crop applied or discarded while the bar is hidden still ends its context The crop frame count is now kept on every canvas pass from the tool's session, not only while the bar shows. --- .../src/task_bar_drag_context_tests.rs | 21 +++++++++++++++++++ crates/ui-egui/src/tools/crop_task_bar.rs | 16 +++++++++----- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/crates/ui-egui/src/task_bar_drag_context_tests.rs b/crates/ui-egui/src/task_bar_drag_context_tests.rs index ece9196202..df6c270577 100644 --- a/crates/ui-egui/src/task_bar_drag_context_tests.rs +++ b/crates/ui-egui/src/task_bar_drag_context_tests.rs @@ -185,6 +185,27 @@ fn a_new_crop_frame_is_a_new_context() { assert_eq!(bar(&mut h)["rect"], automatic_crop_rect()); } +/// A crop discarded while the bar is hidden still ends that frame's context: the next frame's bar is automatic. +#[test] +fn a_crop_discarded_while_the_bar_is_hidden_is_a_new_context() { + let mut h = harness(); + crop_frame(&mut h); + drag_grip(&mut h); + assert!(place(&h).offset.is_some()); + control(&mut h, "ui.set", json!({"panels": {"context_task_bar": false}})); + h.run_steps(4); + crate::crop_ui::discard(h.state_mut()); + h.run_steps(4); + h.state_mut().canvas_tools.crop.tool.crop_to(CropBox::new(DocRect::new(100.0, 100.0, 200.0, 160.0), 0.0)); + h.run_steps(4); + assert!(crate::crop_ui::pending(h.state()), "a new pending frame while the bar is hidden"); + control(&mut h, "ui.set", json!({"panels": {"context_task_bar": true}})); + h.run_steps(6); + let p = place(&h); + assert!(p.offset.is_none() && p.at.is_none(), "{p:?}"); + assert_eq!(bar(&mut h)["rect"], automatic_crop_rect()); +} + /// The Frame tool's bar: another frame layer is another context. #[test] fn another_frame_layer_is_a_new_context() { diff --git a/crates/ui-egui/src/tools/crop_task_bar.rs b/crates/ui-egui/src/tools/crop_task_bar.rs index 7d84cdf30c..0fc4bdcdc5 100644 --- a/crates/ui-egui/src/tools/crop_task_bar.rs +++ b/crates/ui-egui/src/tools/crop_task_bar.rs @@ -38,6 +38,8 @@ pub fn eligible(app: &PhotocraftApp) -> bool { pub fn show(app: &mut PhotocraftApp, ui: &mut egui::Ui, area: egui::Rect) { // The canvas run that shows the bar reports where; a replay of that run shows it there still. app.ui.task_bar_shown = None; + // A crop applied or discarded while the bar is hidden still ends that frame's context. + track_crop_frame(app); if !wanted(app) { return; } @@ -77,16 +79,20 @@ fn label(text: &str) -> Label { Label::from(text.to_string()) } -/// A new crop frame (the last one applied or discarded) or another document is a new context for the bar (#16758). -fn enter_context(app: &mut PhotocraftApp) { - let Some(doc) = app.session.active().map(|d| d.doc.id.0) else { return }; - let pending = crop_ui::pending(app); +/// Counts the crop frames that end (applied or discarded) on every pass, whether the bar shows or not. +fn track_crop_frame(app: &mut PhotocraftApp) { + let pending = app.canvas_tools.crop.tool.session().pending(); let track = &mut app.ui.task_bar_track; if track.crop_pending && !pending { track.crop_frame = track.crop_frame.wrapping_add(1); } track.crop_pending = pending; - let frame = track.crop_frame; +} + +/// A new crop frame (the last one applied or discarded) or another document is a new context for the bar (#16758). +fn enter_context(app: &mut PhotocraftApp) { + let Some(doc) = app.session.active().map(|d| d.doc.id.0) else { return }; + let frame = app.ui.task_bar_track.crop_frame; app.ui.enter_task_bar_context(TaskBarContext::Crop { doc, frame }); }