PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Layers panel: a group's layers indent past the group
tessillustrations-droidb13847dc37f1
diff --git a/crates/ui-egui/src/layer_row_ui/tests.rs b/crates/ui-egui/src/layer_row_ui/tests.rsindex 6ec1241b4..28e0b9d8a 100644--- a/crates/ui-egui/src/layer_row_ui/tests.rs+++ b/crates/ui-egui/src/layer_row_ui/tests.rs@@ -106,6 +106,23 @@ fn long_names_never_run_under_the_indicators() {}}+/// A layer inside a group sits one step right of the group's row, so the hierarchy shows: its+/// name used to start where the group's did. Top-level layers stay where they were.+#[test]+fn a_groups_layers_indent_past_the_group() {+ let mut s = photocraft_engine::Session::new();+ s.execute("file.new", json!({"width": 64, "height": 48})).unwrap();+ let child = s.execute("layer.new.layer", json!({"name": "Child"})).unwrap()["layer"].as_u64().unwrap();+ let group = s.execute("layer.groupLayers", json!({"name": "Group"})).unwrap()["layer"].as_u64().unwrap();+ let top = s.execute("layer.new.layer", json!({"name": "Top"})).unwrap()["layer"].as_u64().unwrap();+ let h = harness(s, 1.0, "promedium", 290.0);+ let rows = recorded(&h.ctx);+ let left = |id: u64| rows.iter().find(|r| r.layer == id).and_then(|r| r.name).map(|n| n.left()).unwrap_or_else(|| panic!("layer {id} drawn"));+ let step = crate::layer_tree_ui::TRIANGLE_W;+ assert!((left(child) - left(group) - step).abs() < 0.5, "child {} vs group {}", left(child), left(group));+ assert!((left(group) - left(top) - step).abs() < 0.5, "a top-level layer keeps its place: {} vs group {}", left(top), left(group));+}+fn click(h: &mut Harness<'_, PhotocraftApp>, at: Pos2) {h.hover_at(at);h.run_steps(1);diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rsindex 04e775439..6bd8543ce 100644--- a/crates/ui-egui/src/panels.rs+++ b/crates/ui-egui/src/panels.rs@@ -3071,7 +3071,11 @@ fn layer_row(+ crate::layer_row_ui::reserved_width(l);let ts = crate::mask_thumbs_ui::thumb_size(l, if t.pro { 24.0 } else { 34.0 }, rect.width() - others);let fixed = others + ts + 6.0 + crate::mask_thumbs_ui::width(l, ts);- x += 28.0 + crate::layer_row_ui::indent(depth, rect.width(), fixed);+ // A layer inside a group (or an artboard) indents one step more than its depth, past the+ // triangle's column, so it sits right of its parent: with only its depth its thumbnail lined+ // up under the group's, hiding the hierarchy. Top-level rows don't move.+ let steps = if !l.is_group() && depth > 0 { depth + 1 } else { depth };+ x += 28.0 + crate::layer_row_ui::indent(steps, rect.width(), fixed);let toggled = crate::layer_tree_ui::disclosure(ui, rect, &mut x, l, actions);if l.clipped {paint_clipping_indicator(&painter, pos2(x, rect.center().y), t.text_faint);