Layers panel: drag down the eyes to show or hide layers; empty eye when hidden (#666)

- The eye column takes drags: pressing an eye toggles that layer and every
  row the pointer then sweeps over gets the same visibility (each row once
  per drag). A drag that starts on an eye no longer reorders the layers.
- A hidden layer's eye box is left empty instead of drawing a struck-out
  eye; it is still clickable.

Co-authored-by: Jason Short <[email protected]>
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
authored and GitHub committed 2026-10-07 16:03:21 -04:00
1 parent 9270a31f24
commit 43c86ef645
2 files changed
+65 -2

No files matched your search

+38
View File
@@ -178,3 +178,41 @@ fn collapse_all_groups_from_the_panel_menu_and_it_is_saved() {
assert!(groups_open(&s).iter().all(|o| !o), "{name}: groups stay closed");
}
}
/// Dragging down the eye column hides (or shows) every layer swept over and never reorders the
/// layers; a hidden layer's eye box is empty and a click shows it again.
#[test]
fn dragging_down_the_eyes_sweeps_visibility_without_reordering() {
let mut s = photocraft_engine::Session::new();
s.execute("file.new", json!({"width": 64, "height": 48})).unwrap();
for i in 0..4 {
s.execute("layer.new.layer", json!({"name": format!("L{i}")})).unwrap();
}
let mut h = harness(s, 1.0, "promedium", 290.0);
let order = |h: &Harness<'_, PhotocraftApp>| h.state().session.active().unwrap().doc.layers.iter().map(|l| l.id).collect::<Vec<_>>();
let visible = |h: &Harness<'_, PhotocraftApp>, id: u64| h.state().session.active().unwrap().doc.layer(photocraft_doc::LayerId(id)).unwrap().visible;
let before = order(&h);
// Rows top to bottom: L3, L2, L1, L0, Background.
let rows = recorded(&h.ctx);
let eye = |r: &RowRects| pos2(r.row.left() + 17.0, r.row.center().y);
let (first, last) = (eye(&rows[0]), eye(&rows[2]));
h.event(egui::Event::PointerMoved(first));
h.run_steps(1);
h.event(egui::Event::PointerButton { pos: first, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE });
h.run_steps(1);
for k in 1..=10 {
h.event(egui::Event::PointerMoved(first + (last - first) * (k as f32 / 10.0)));
h.run_steps(1);
}
h.event(egui::Event::PointerButton { pos: last, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });
h.run_steps(3);
for r in &rows[..3] {
assert!(!visible(&h, r.layer), "layer {} swept hidden", r.layer);
}
assert!(visible(&h, rows[3].layer), "rows past the sweep are untouched");
assert_eq!(order(&h), before, "an eye drag never reorders the layers");
// A click on the (empty) eye box of a hidden layer shows it again.
let p = eye(&recorded(&h.ctx)[1]);
click(&mut h, p);
assert!(visible(&h, rows[1].layer));
}
+27 -2
View File
@@ -1606,8 +1606,33 @@ fn layer_row(
}
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));
let eye_resp = ui.interact(eye, ui.id().with(("eye", l.id.0)), Sense::click());
icons::paint(ui, eye, if l.visible { "eye" } else { "eye-off" }, 15.0, if l.visible { t.icon } else { t.text_faint });
// 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).
if l.visible {
icons::paint(ui, eye, "eye", 15.0, t.icon);
}
let sweep_id = egui::Id::new("layer-eye-sweep");
if eye_resp.drag_started() {
let visible = !l.visible;
ctx.data_mut(|d| d.insert_temp(sweep_id, (visible, vec![l.id.0])));
actions.push(("layer.setProps".into(), json!({"layer": l.id.0, "visible": visible})));
} else if let Some((visible, mut swept)) = ctx.data(|d| d.get_temp::<(bool, Vec<u64>)>(sweep_id)) {
if !ctx.input(|i| i.pointer.primary_down()) {
ctx.data_mut(|d| d.remove::<(bool, Vec<u64>)>(sweep_id));
} else if let Some(p) = ctx.input(|i| i.pointer.interact_pos())
&& p.y >= rect.top()
&& p.y < rect.bottom()
&& !swept.contains(&l.id.0)
{
if l.visible != visible {
actions.push(("layer.setProps".into(), json!({"layer": l.id.0, "visible": visible})));
}
swept.push(l.id.0);
ctx.data_mut(|d| d.insert_temp(sweep_id, (visible, swept)));
}
}
if eye_resp.clicked() {
// ⌥-click shows only this layer; ⌥-click it again to restore the others.
if ui.input(|i| i.modifiers.alt) {