Skip to content

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

fix(ui-egui): expand layer visibility eye hitbox and render sunken well (#8467)

kobaltgitd8cf69b38a5e
diff --git a/crates/ui-egui/src/layer_row_ui/tests.rs b/crates/ui-egui/src/layer_row_ui/tests.rs
index c47f9522a..a5c9ed383 100644
--- a/crates/ui-egui/src/layer_row_ui/tests.rs
+++ b/crates/ui-egui/src/layer_row_ui/tests.rs
@@ -638,3 +638,38 @@ fn clicking_the_lock_icon_on_a_row_unlocks_the_layer() {
assert!(doc.background().is_none(), "the Background became a normal layer");
assert!(!doc.layer(bg).unwrap().locks.any());
}
+
+#[test]
+fn eye_column_edges_toggle_visibility_without_selecting_layer() {
+ // #8467: clicks at the far left or right edge of the eye column must toggle visibility
+ // rather than falling through to select the row.
+ let mut s = photocraft_engine::Session::new();
+ s.execute("file.new", json!({"width": 64, "height": 48})).unwrap();
+ let l1 = s.execute("layer.new.layer", json!({"name": "Top"})).unwrap()["layer"].as_u64().unwrap();
+ let l0 = s.execute("layer.new.layer", json!({"name": "Bottom"})).unwrap()["layer"].as_u64().unwrap();
+ s.execute("layer.select", json!({"layer": l0})).unwrap();
+
+ let mut h = harness(s, 1.0, "promedium", 290.0);
+ let visible = |h: &Harness<'_, PhotocraftApp>, id: u64| h.state().session.active().unwrap().doc.layer(photocraft_doc::LayerId(id)).unwrap().visible;
+ let selected = |h: &Harness<'_, PhotocraftApp>| h.state().session.active().unwrap().active_layer.unwrap().0;
+
+ let row_for = |h: &Harness<'_, PhotocraftApp>, id: u64| {
+ recorded(&h.ctx).into_iter().find(|r| r.layer == id).unwrap().row
+ };
+
+ let top_row = row_for(&h, l1);
+ // Click at the far left edge of the eye column (left + 1.0, top + 1.0)
+ let left_edge = pos2(top_row.left() + 1.0, top_row.top() + 1.0);
+ click(&mut h, left_edge);
+
+ assert!(!visible(&h, l1), "click on left edge of eye column should hide layer");
+ assert_eq!(selected(&h), l0, "click on eye column must not select the layer");
+
+ // Click at the right edge of the eye column (left + 29.0, bottom - 1.0)
+ let right_edge = pos2(top_row.left() + 29.0, top_row.bottom() - 1.0);
+ click(&mut h, right_edge);
+
+ assert!(visible(&h, l1), "click on right edge of eye column should show layer again");
+ assert_eq!(selected(&h), l0, "click on eye column must not select the layer");
+}
+
diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs
index 65efb1c13..2530e5b92 100644
--- a/crates/ui-egui/src/panels.rs
+++ b/crates/ui-egui/src/panels.rs
@@ -3209,14 +3209,28 @@ fn layer_row(
painter.line_segment([rect.left_bottom(), rect.right_bottom()], Stroke::new(1.0, t.separator));
}
let mut x = rect.left() + 6.0;
- let eye = Rect::from_min_size(pos2(x, rect.center().y - 11.0), vec2(22.0, 22.0));
- // The eye takes drags too (so a drag starting on it never reorders the row): dragging down
- // the eyes gives every row swept over the visibility the first eye toggled to.
- let eye_resp = ui.interact(eye, ui.id().with(("eye", l.id.0)), Sense::click_and_drag());
- // A hidden layer's eye box is left empty (still clickable).
+ // The whole eye column takes drags too (so a drag starting on it never reorders the row): dragging down
+ // the eyes gives every row swept over the visibility the first eye toggled to (#8467).
+ let eye_resp = ui.interact(eye_cell, ui.id().with(("eye", l.id.0)), Sense::click_and_drag());
+ // A hidden layer's eye box shows a sunken well indicating its eye socket (#8467).
if l.visible {
// Centre the drawing in the column while preserving the visibility hit area.
icons::paint(ui, eye_cell, "eye", 15.0, t.layer_label_icon(l.label));
+ } else {
+ let well = Rect::from_center_size(eye_cell.center(), vec2(12.0, 12.0));
+ if t.bevel {
+ crate::widgets::surface(ui, well, t.field, false);
+ } else {
+ let (hi, lo) = if t.dark() {
+ (Color32::from_black_alpha(65), Color32::from_white_alpha(35))
+ } else {
+ (Color32::from_black_alpha(55), Color32::from_white_alpha(70))
+ };
+ painter.line_segment([well.left_bottom(), well.left_top()], Stroke::new(1.0, hi));
+ painter.line_segment([well.left_top(), well.right_top()], Stroke::new(1.0, hi));
+ painter.line_segment([well.right_top(), well.right_bottom()], Stroke::new(1.0, lo));
+ painter.line_segment([well.right_bottom(), well.left_bottom()], Stroke::new(1.0, lo));
+ }
}
eye_sweep(ctx, l, rect, &eye_resp, actions);
if eye_resp.clicked() {