From 691201b7487364f9bdd27bdd8a1c5d21883c264e Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 20 Nov 2026 14:30:03 -0800 Subject: [PATCH] Layers: a layer or sublayer with all its art selected shows the full-sized square The selection square of a layer or sublayer is full-sized while all of its visible, unlocked art is selected, and small while only some of it is. Hidden, locked and template art does not keep the square small, a group counts as one item (a selected member is not the group), and a layer with no such art shows no square. Group rows are unchanged. The panel finds these layers once per frame, in one pass over the layers and their direct children, and the untargeted target circle of a layer reads the same set. Help page: https://helpx.adobe.com/illustrator/desktop/manage-layers/create-and-organize-layers/layers-overview.html --- crates/ui-egui/src/panels/layers.rs | 7 ++- crates/ui-egui/src/panels/layers/rows.rs | 49 ++++++++++++---- crates/ui-egui/src/panels/layers/tests.rs | 70 +++++++++++++++++++++++ docs/target-app-parity.md | 1 + 4 files changed, 116 insertions(+), 11 deletions(-) diff --git a/crates/ui-egui/src/panels/layers.rs b/crates/ui-egui/src/panels/layers.rs index 93aa99e6da..e2ebe3c4fa 100644 --- a/crates/ui-egui/src/panels/layers.rs +++ b/crates/ui-egui/src/panels/layers.rs @@ -162,6 +162,9 @@ struct View<'a> { /// Where the row thumbnails come from. thumbs: ThumbSource<'a>, sel: HashSet, + /// The layers and sublayers whose visible, unlocked art ([`Node::layer_art`]) is all selected + /// and not empty. + full_layers: HashSet, /// The selected ruler guides, as indexes into [`Self::ruler_guides`]. guides: Vec, /// The document's ruler guides ([`Document::ruler_guides`]). @@ -320,10 +323,12 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { let reveal = renamed.or(located).or(reveal); let Some(st) = app.session.active() else { return }; let list = rows_of_doc(ui, st, &app.ui.layers_panel, &query, &app.ui.layers_filter); + let sel: HashSet = st.selection.objects.iter().copied().collect(); let view = View { doc: &doc, thumbs: ThumbSource::of(app, st, &doc), - sel: st.selection.objects.iter().copied().collect(), + full_layers: rows::full_layers(&doc, &sel), + sel, guides: vectorcraft_engine::cmd::guide_indexes(&doc, &st.selection.guides), ruler_guides: doc.ruler_guides(), target: st.selection.target, diff --git a/crates/ui-egui/src/panels/layers/rows.rs b/crates/ui-egui/src/panels/layers/rows.rs index c945537326..34fb517a26 100644 --- a/crates/ui-egui/src/panels/layers/rows.rs +++ b/crates/ui-egui/src/panels/layers/rows.rs @@ -2,8 +2,8 @@ use super::controls::collect_for_export_menu; use super::model::{Place, Row, opens, painted_name}; use super::thumbs::{node_arc, real_thumb, thumb}; use super::{ - Arc, COLUMN, Color32, ColumnDrag, Document, INDENT, LayersDrag, Node, NodeId, NodeKind, Out, PanelDrag, ROW_KEYS, SQUARE_X, Sense, Stroke, - StrokeKind, TARGET_X, Tokens, Ui, Value, View, icons, json, vec2, widgets, + Arc, COLUMN, Color32, ColumnDrag, Document, HashSet, INDENT, LayersDrag, Node, NodeId, NodeKind, Out, PanelDrag, ROW_KEYS, SQUARE_X, Sense, + Stroke, StrokeKind, TARGET_X, Tokens, Ui, Value, View, icons, json, vec2, widgets, }; use vectorcraft_tools::intertwine::{in_intertwine, refused_member}; @@ -499,6 +499,8 @@ pub(super) fn row(ui: &mut Ui, view: &View, item: &Row, out: &mut Out) { n.walk(&mut |c| any |= c.id != n.id && view.sel.contains(&c.id)); any }); + // A layer or sublayer whose selectable art is all selected shows the full-sized square. + let full = view.full_layers.contains(&n.id); row_background(ui, view, n, r, &resp); eye_and_lock(ui, view, n, r, out); // Layer colour bar (every row shows the colour of its layer). @@ -523,7 +525,7 @@ pub(super) fn row(ui: &mut Ui, view: &View, item: &Row, out: &mut Out) { let tc = egui::pos2(r.right() - TARGET_X, r.center().y); let tresp = target_circle(ui, n, tc, h, shows_targeted(view, n, is_sel), &mut out.actions, t); let sq = egui::pos2(r.right() - SQUARE_X, r.center().y); - if is_sel { + if is_sel || full { let q = egui::Rect::from_center_size(sq, vec2(7.0, 7.0)); ui.painter().rect_filled(q, 0.0, color); ui.painter().rect_stroke(q, 0.0, Stroke::new(1.0, t.text), StrokeKind::Inside); @@ -938,17 +940,44 @@ fn drop_target(ui: &Ui, view: &View, n: &Node, r: egui::Rect, indent: f32, open: fn shows_targeted(view: &View, n: &Node, is_sel: bool) -> bool { match view.target { Some(id) => id == n.id, - None if n.is_layer() => { - if view.sel.is_empty() { - return false; - } - let art = n.layer_art(true); - !art.is_empty() && art.iter().all(|id| view.sel.contains(id)) - } + None if n.is_layer() => view.full_layers.contains(&n.id), None => is_sel, } } +/// The layers and sublayers of `doc` whose [`Node::layer_art`] with `editable` is not empty and +/// all in `sel`, found in one pass over the layers and their direct children. +pub(super) fn full_layers(doc: &Document, sel: &HashSet) -> HashSet { + /// Adds `layer` to `out` when it is full, and returns its art's count and selected count. + fn visit(layer: &Node, sel: &HashSet, out: &mut HashSet) -> (usize, usize) { + let (mut art, mut selected) = (0, 0); + for c in layer.children().into_iter().flatten() { + let counts = !(c.is_ruler_guide() || !c.visible || c.locked || c.is_template()); + if c.is_layer() { + let (a, s) = visit(c, sel, out); + if counts { + art += a; + selected += s; + } + } else if counts { + art += 1; + selected += usize::from(sel.contains(&c.id)); + } + } + if art > 0 && selected == art { + out.insert(layer.id); + } + (art, selected) + } + let mut out = HashSet::new(); + if !sel.is_empty() { + for layer in doc.layers.iter().filter(|l| l.is_layer()) { + visit(layer, sel, &mut out); + } + } + out +} + /// The radius of the inner ring of a targeted item's target circle (the double ring); the outer /// ring's radius is 5. pub(super) const TARGET_RING: f32 = 2.8; diff --git a/crates/ui-egui/src/panels/layers/tests.rs b/crates/ui-egui/src/panels/layers/tests.rs index 0fddbc41a8..aa029563e9 100644 --- a/crates/ui-egui/src/panels/layers/tests.rs +++ b/crates/ui-egui/src/panels/layers/tests.rs @@ -1610,6 +1610,76 @@ fn selection_squares_show_and_select_a_rows_art() { let _ = (layer, sub, b); } +/// A layer or sublayer whose selectable art is all selected shows the full-sized square; one +/// holding some of its art, or a group's member instead of the group, shows the small one. +#[test] +fn a_layer_with_all_its_art_selected_shows_the_full_square() { + let (mut app, [_, _, g, b, a, c]) = nested(); + let ctx = egui::Context::default(); + let (circles, _) = frame(&mut app, &ctx, vec![], false); + let square = |i: usize| circles[i] + vec2(TARGET_X - SQUARE_X, 0.0); + app.session.execute("select.set", &json!({"ids": [a.0]})).unwrap(); + assert_eq!(squares(&mut app, &ctx), (1, 2), "the rectangle's square, small ones on the sublayer and the layer"); + app.session.execute("select.set", &json!({"ids": [a.0, b.0]})).unwrap(); + assert_eq!(squares(&mut app, &ctx), (2, 3), "a group's member is not the group: the sublayer's square stays small"); + click_with(&mut app, &ctx, square(1), egui::Modifiers::NONE); + assert_eq!(squares(&mut app, &ctx), (3, 1), "the sublayer, its group and rectangle full, the layer small"); + click_with(&mut app, &ctx, square(0), egui::Modifiers::NONE); + assert_eq!(squares(&mut app, &ctx), (5, 0), "the layer and the sublayer full, with each row's art"); + click_with(&mut app, &ctx, square(4), egui::Modifiers::SHIFT); + assert_eq!(squares(&mut app, &ctx), (2, 2), "one rectangle let go: the layer and the sublayer small again"); + // Locked art cannot be selected, so it does not keep the layer's square small. + app.session.execute("layer.setProps", &json!({"ids": [c.0], "locked": true})).unwrap(); + click_with(&mut app, &ctx, square(1), egui::Modifiers::NONE); + assert_eq!(squares(&mut app, &ctx), (4, 0), "the layer, the sublayer, the group and the rectangle"); + // Hidden art neither. + app.session.execute("layer.setProps", &json!({"ids": [c.0], "locked": false, "visible": false})).unwrap(); + app.session.execute("select.set", &json!({"ids": [a.0, g.0]})).unwrap(); + assert_eq!(squares(&mut app, &ctx), (4, 0), "hidden art is left out"); +} + +/// A layer with no selectable art shows no square, whatever else is selected. +#[test] +fn a_layer_without_art_shows_no_square() { + let (mut app, [_, _, g, _, a, c]) = nested(); + app.session.execute("layer.new", &json!({})).unwrap(); + let ctx = egui::Context::default(); + app.session.execute("select.set", &json!({"ids": [c.0, a.0, g.0]})).unwrap(); + assert_eq!(squares(&mut app, &ctx), (5, 0), "the first layer's rows; the new, empty layer's none"); +} + +/// The panel's set of full layers is the layers and sublayers whose `layer_art(true)` is not empty +/// and all selected, for every selection of the document's objects, hidden and locked ones included. +#[test] +fn full_layers_are_the_layers_with_all_their_art_selected() { + let (mut app, [_, _, _, _, _, c]) = nested(); + let run = |app: &mut VectorcraftApp, id: &str, p: serde_json::Value| app.session.execute(id, &p).unwrap(); + let id = |v: serde_json::Value| NodeId(v["id"].as_u64().unwrap()); + let hidden = id(run(&mut app, "layer.newSublayer", json!({"name": "Hidden"}))); + run(&mut app, "shape.rectangle", json!({"x": 200, "y": 0, "width": 20, "height": 20})); + run(&mut app, "layer.setProps", json!({"ids": [hidden.0], "visible": false})); + run(&mut app, "layer.setProps", json!({"ids": [c.0], "locked": true})); + run(&mut app, "layer.new", json!({})); + let doc = app.session.active().unwrap().doc.clone(); + let (mut layers, mut objects) = (vec![], vec![]); + for l in &doc.layers { + l.walk(&mut |n| if n.is_layer() { layers.push(n) } else { objects.push(n.id) }); + } + assert_eq!((layers.len(), objects.len()), (4, 5), "the layers, the sublayers and the objects"); + for bits in 0u32..(1 << objects.len()) { + let sel: HashSet = objects.iter().enumerate().filter(|(i, _)| (bits >> i) & 1 == 1).map(|(_, id)| *id).collect(); + let want: HashSet = layers + .iter() + .filter(|l| { + let art = l.layer_art(true); + !art.is_empty() && art.iter().all(|i| sel.contains(i)) + }) + .map(|l| l.id) + .collect(); + assert_eq!(rows::full_layers(&doc, &sel), want, "selection {bits:b}"); + } +} + /// Alt-click on a layer's or sublayer's name makes it current, as a plain click does, and selects /// its art, as its selection square does. On another row, beside the name or with Shift or Ctrl/Cmd /// held too, it is the click without Alt. diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 57ac87a396..9d60731b43 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1600,6 +1600,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur Ctrl/Cmd+Alt-clicking an eye switches the other layers to Outline and the row's layer to Preview, or switches all layers back to Preview when the others are in Outline (`layer.outlineOthers`, `layer.previewAll`). Ctrl/Cmd+Alt-clicking New Layer adds a layer directly below the current layer, at its level (`layer.new {below: true}`), and Ctrl/Cmd+Alt-clicking New Sublayer adds a sublayer under the contents of the layer it goes into (`layer.newSublayer {bottom: true}`), each in one undo step. The reference app's [Default keyboard shortcuts](https://web.archive.org/web/20260726060015/https://helpx.adobe.com/illustrator/using/default-keyboard-shortcuts.html) page lists these clicks for placing a layer below the selected layer and a new sublayer at the bottom of the layer list. Alt-clicking a layer's or sublayer's name makes it the current layer, as a click does, and selects its visible, unlocked art, as its selection square does (`layer.selectAll`, then `layer.setCurrent`); on a hidden or locked layer it clears the selection. The reference app's [Default keyboard shortcuts](https://web.archive.org/web/20260726060015/https://helpx.adobe.com/illustrator/using/default-keyboard-shortcuts.html) page lists Alt-click on the layer name for selecting all objects on the layer. + A layer or sublayer whose selectable art is all selected shows the full-sized selection square instead of the small one, as the [help page](https://helpx.adobe.com/illustrator/desktop/manage-layers/create-and-organize-layers/layers-overview.html) describes for a layer with every item selected. As VectorCraft's own rules, sublayers follow the same rule, "all" means the visible, unlocked art its selection square selects (hidden or locked art does not keep the square small, and a selected member of a group is not the group), and a layer with no such art shows no square. A group row keeps the small square while only its members are selected (`panels::layers` tests `a_layer_with_all_its_art_selected_shows_the_full_square`, `a_layer_without_art_shows_no_square` and `full_layers_are_the_layers_with_all_their_art_selected`). Object › Arrange › Send to Current Layer returns the error "the target layer is locked or hidden" and leaves the selected objects where they are when the current layer is hidden or locked, or is inside a hidden or locked layer. Selected objects are deselected, the key object included, when a row drag moves them into a hidden layer or group, when `node.move` moves them into a hidden or locked layer or group, when Merge Selected moves them into a hidden or locked layer, when Collect in New Layer moves them into a new layer inside a hidden or locked layer, when Flatten Artwork moves them into a locked layer, and when applying a data set hides them. Layer Options for several highlighted rows shows the first row's settings, and OK changes only the settings set in the dialog: each row keeps its own color, Template, Lock, Show, Print, Preview and Dim Images otherwise (`crates/ui-egui/src/dialogs/layer_options.rs` tests).