Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Layers panel: thumbnails off no longer leave mask thumbnails that catch drags

abc2cb62dbd6ced770
diff --git a/crates/ui-egui/src/mask_thumbs_ui.rs b/crates/ui-egui/src/mask_thumbs_ui.rs
index 1a8ff55d7..225cd47e8 100644
--- a/crates/ui-egui/src/mask_thumbs_ui.rs
+++ b/crates/ui-egui/src/mask_thumbs_ui.rs
@@ -181,6 +181,12 @@ pub fn recorded(ctx: &egui::Context, id: u64) -> Option<Rects> {
ctx.data(|d| d.get_temp::<std::collections::HashMap<u64, Rects>>(rects_id())).and_then(|m| m.get(&id).cloned())
}
+/// Drop what was recorded for layer `id`, so a row drawn without mask thumbnails (thumbnail size
+/// None) can't be hit through rects from an earlier frame.
+pub fn forget(ctx: &egui::Context, id: u64) {
+ ctx.data_mut(|d| d.get_temp_mut_or_default::<std::collections::HashMap<u64, Rects>>(rects_id()).remove(&id));
+}
+
/// A small vertical chain: two interlocking links.
fn paint_chain(painter: &Painter, c: Pos2, color: Color32) {
let st = Stroke::new(1.2, color);
diff --git a/crates/ui-egui/src/mask_thumbs_ui/tests.rs b/crates/ui-egui/src/mask_thumbs_ui/tests.rs
index 163c7cbae..369e7468f 100644
--- a/crates/ui-egui/src/mask_thumbs_ui/tests.rs
+++ b/crates/ui-egui/src/mask_thumbs_ui/tests.rs
@@ -214,6 +214,36 @@ fn dragging_a_layer_row_to_trash_still_deletes_the_layer_with_a_mask_targeted()
assert!(h.state().session.active().unwrap().doc.layer(photocraft_doc::LayerId(masked)).is_none());
}
+/// With the thumbnail size set to None no mask thumbnail is drawn, so a drag from where one used
+/// to be moves the layer (the row) rather than a mask that is no longer on screen.
+#[test]
+fn thumbnails_off_forget_the_mask_rects_and_drag_the_layer() {
+ let (s, masked, _) = session();
+ let mut h = harness(s, 0, 1.0, 290.0);
+ let stale = recorded(&h.ctx, masked).unwrap().0.into_iter().find(|(k, _)| *k == MaskKind::Pixel).unwrap().1;
+ click_with(&mut h, stale.center(), Modifiers::NONE);
+ h.state_mut().ui.layers_panel_options.thumbnail_size = crate::state::LayerThumbnailSize::None;
+ h.run_steps(3);
+ assert!(recorded(&h.ctx, masked).is_none(), "no mask thumbnails are recorded while they are off");
+
+ let row = crate::layer_row_ui::recorded(&h.ctx).into_iter().find(|r| r.layer == masked).unwrap().row;
+ let from = pos2(stale.center().x, row.center().y);
+ assert!(row.contains(from), "the old thumbnail position is still on the row");
+ let to = h.get_by_label("Delete Layer Mask").rect().center();
+ h.hover_at(from);
+ h.run_steps(1);
+ h.event(egui::Event::PointerButton { pos: from, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE });
+ h.run_steps(1);
+ for k in 1..=8 {
+ h.event(egui::Event::PointerMoved(from + (to - from) * (k as f32 / 8.0)));
+ h.run_steps(1);
+ }
+ h.event(egui::Event::PointerButton { pos: to, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });
+ h.run_steps(3);
+ assert!(!h.state().ui.dialogs.iter().any(|d| crate::mask_trash_prompt::owns(&d.fields)), "no mask prompt: the mask was not dragged");
+ assert!(h.state().session.active().unwrap().doc.layer(photocraft_doc::LayerId(masked)).is_none(), "the layer went to the trash");
+}
+
/// #3113: dragging the layer mask's thumbnail onto the Trash asks "Apply mask to layer before
/// removing?" and keeps the layer; Apply applies the mask, Delete deletes it.
#[test]
diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs
index d4e495ae1..875014273 100644
--- a/crates/ui-egui/src/panels.rs
+++ b/crates/ui-egui/src/panels.rs
@@ -2954,6 +2954,10 @@ fn layer_row(
// The Layers Panel Options thumbnail size controls rows and both layer/mask thumbnails.
let (base, row_h) = crate::layers_panel_ui::thumbnail_geometry(app.ui.layers_panel_options.thumbnail_size, t.pro);
let (rect, resp) = ui.allocate_exact_size(vec2(ui.available_width(), row_h), Sense::click_and_drag());
+ // With thumbnails off no mask thumbnail is drawn, so none may keep catching drags from older frames.
+ if base == 0.0 {
+ crate::mask_thumbs_ui::forget(ctx, l.id.0);
+ }
// A drag from a mask's thumbnail drags that mask, not the layer (#3113, #3119).
let mask_drag = starts_mask_drag(ctx, l, &resp);
if let Some(kind) = mask_drag {