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.
This commit is contained in:
qvest-ssels committed 2026-11-28 12:43:07 +01:00
1 parent cededa48f2
commit b79aca08ff
2 files changed
+32 -5

No files matched your search

@@ -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() {
+11 -5
View File
@@ -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 });
}