diff --git a/crates/ui-egui/src/panels/layers/cells.rs b/crates/ui-egui/src/panels/layers/cells.rs index db6e0c342d..c557023bcf 100644 --- a/crates/ui-egui/src/panels/layers/cells.rs +++ b/crates/ui-egui/src/panels/layers/cells.rs @@ -24,7 +24,7 @@ use egui::{Color32, CornerRadius, Pos2, Rect, Response, Vec2, vec2}; use super::model::{DocLayers, RowId}; use super::rows::{TARGET_RADIUS, has_styled_target, shows_targeted, target_marks}; -use super::{NodeId, Value, json}; +use super::{Node, NodeId, Value, json}; use crate::panel_drag::PanelDrag; /// The side of the square of a row whose art is selected. @@ -193,8 +193,9 @@ impl Component for TargetCircle { } } -/// A row's selection square: filled in its layer's colour while the row's art is selected, a small -/// square while the row holds selected art. Without `id` it is only a mark (a ruler guide's row, a +/// A row's selection square: filled in its layer's colour while the row's art is selected (for a +/// layer or sublayer, all of its visible, unlocked art), a small square while the row holds +/// selected art. Without `id` it is only a mark (a ruler guide's row, a /// spine's row) and takes no press. #[derive(Component, Props)] #[component(sample = SelectionSquare::sample)] @@ -346,6 +347,19 @@ impl Component for Cells { } } +/// The marks of node row `n`'s selection square in the panel over `tree`: whether it shows the +/// full-sized square (the row is selected, or it is a layer or sublayer whose visible, unlocked art +/// is all selected), and whether it shows the small one (it holds selected art otherwise). +pub(super) fn square_marks(tree: &DocLayers<'_>, n: &Node) -> (bool, bool) { + let full = tree.is_selected(n.id) || tree.is_full(n.id); + let holds = !full && { + let mut any = false; + n.walk(&mut |c| any |= c.id != n.id && tree.is_selected(c.id)); + any + }; + (full, holds) +} + /// The cells of row `row` (shown as `info`) of the panel over `tree`. pub(super) fn build(tree: &DocLayers<'_>, row: &RowId, info: &LayerInfo) -> Cells { let st = tree.state(); @@ -355,15 +369,11 @@ pub(super) fn build(tree: &DocLayers<'_>, row: &RowId, info: &LayerInfo) -> Cell RowId::Node(id) => { let Some(n) = tree.doc().node(id) else { return Cells::new(None, SelectionSquare::new(None, false, false, color, vec![])) }; let is_sel = selected(id); - let holds = !is_sel && { - let mut any = false; - n.walk(&mut |c| any |= c.id != id && selected(c.id)); - any - }; - let art = if is_sel || holds { st.selection.objects.clone() } else { vec![] }; + let (full, holds) = square_marks(tree, n); + let art = if full || holds { st.selection.objects.clone() } else { vec![] }; let circle = TargetCircle::new(id, shows_targeted(tree, n, is_sel), has_styled_target(n)) .label(crate::i18n::fmt(tl!("Target {row}"), &[("row", info.name.as_str())])); - let square = SelectionSquare::new(Some(id), is_sel, holds, color, art) + let square = SelectionSquare::new(Some(id), full, holds, color, art) .label(crate::i18n::fmt(tl!("Select art of {row}"), &[("row", info.name.as_str())])); Cells::new(Some(circle), square) } diff --git a/crates/ui-egui/src/panels/layers/model.rs b/crates/ui-egui/src/panels/layers/model.rs index 46d24e0806..619fcd6559 100644 --- a/crates/ui-egui/src/panels/layers/model.rs +++ b/crates/ui-egui/src/panels/layers/model.rs @@ -182,6 +182,10 @@ pub(super) struct LayerRows { /// The selected objects. #[plain_data(assume = "node ids are integers")] selected: HashSet, + /// The layers and sublayers whose visible, unlocked art ([`Node::layer_art`]) is all selected + /// and not empty. + #[plain_data(assume = "node ids are integers")] + full: HashSet, /// The selected blends, in selection order. #[plain_data(assume = "node ids are integers")] blends: Vec, @@ -228,6 +232,7 @@ impl LayerRows { let ruler = doc.ruler_guides(); let guide_rows = ruler.iter().enumerate().filter_map(|(i, g)| Some((g.id?, i))).collect(); let blends = st.selection.objects.iter().copied().filter(|id| doc.node(*id).is_some_and(|n| matches!(n.kind, NodeKind::Blend { .. }))); + let selected: HashSet = st.selection.objects.iter().copied().collect(); Self { doc: doc.clone(), opts: app.ui.layers_panel.clone(), @@ -239,7 +244,8 @@ impl LayerRows { guides: vectorcraft_engine::cmd::guide_indexes(doc, &st.selection.guides), ruler, guide_rows, - selected: st.selection.objects.iter().copied().collect(), + full: super::rows::full_layers(doc, &selected), + selected, blends: blends.collect(), root: st.isolation.and_then(|i| isolated_root(doc, i)).map(|(n, ..)| n.id), } @@ -291,6 +297,12 @@ impl LayerRows { self.selected.contains(&id) } + /// Whether `id` is a layer or sublayer whose visible, unlocked art is all selected and not + /// empty. + pub(super) fn is_full(&self, id: NodeId) -> bool { + self.full.contains(&id) + } + /// The node ids a row menu's command acts on: every highlighted row when the menu's row is one of /// them, else the row's own node. pub(super) fn targets(&self, target: &MenuTarget) -> Vec { diff --git a/crates/ui-egui/src/panels/layers/rows.rs b/crates/ui-egui/src/panels/layers/rows.rs index 5359ba672e..20c81d8f91 100644 --- a/crates/ui-egui/src/panels/layers/rows.rs +++ b/crates/ui-egui/src/panels/layers/rows.rs @@ -1,3 +1,5 @@ +use std::collections::HashSet; + use craft::behavior::{EditEvent, SelectionChange}; use craft::keymap::{CommandRef, Mods}; use craft::layers::ui::panel::{ActivateOn, LayerColumn, LayerDrop, LayerMove, LayerPosition, LayerSelect, LayerToggle, LayersEvent}; @@ -110,17 +112,44 @@ pub(super) fn locate_layer_listed(doc: &Document, root: Option) -> bool pub(super) fn shows_targeted(tree: &DocLayers<'_>, n: &Node, is_sel: bool) -> bool { match tree.state().selection.target { Some(id) => id == n.id, - None if n.is_layer() => { - if tree.state().selection.objects.is_empty() { - return false; - } - let art = n.layer_art(true); - !art.is_empty() && art.iter().all(|id| tree.is_selected(*id)) - } + None if n.is_layer() => tree.is_full(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 `layer.target` of a click with `mods` on the target circle of `id`, by the rules of a row click (#8639): plain /// targets it, Ctrl/Cmd adds it to the selection or takes it out, Shift selects the art of every row `filter` lists /// from `anchor` (the last circle clicked, else the targeted row) to it, and Shift+Ctrl/Cmd adds that art. With it, diff --git a/crates/ui-egui/src/panels/layers/tests.rs b/crates/ui-egui/src/panels/layers/tests.rs index 2ac1b0af3f..172bf59860 100644 --- a/crates/ui-egui/src/panels/layers/tests.rs +++ b/crates/ui-egui/src/panels/layers/tests.rs @@ -561,3 +561,98 @@ fn the_target_circle_anchor_does_not_carry_over_to_another_document() { panel.click_with("Target B", egui::Modifiers::SHIFT); assert_eq!(targeted(&panel.app()), (Some(b2), vec![b2])); } + +/// The rows among `rows` whose selection square is full-sized, then those whose square is the +/// small one, in the order given. +fn squares(app: &VectorcraftApp, rows: &[NodeId]) -> (Vec, Vec) { + let st = app.session.active().unwrap(); + let tree = DocLayers::new(app, st); + let (mut full, mut small) = (vec![], vec![]); + for &id in rows { + match cells::square_marks(&tree, st.doc.node(id).unwrap()) { + (true, _) => full.push(id), + (false, true) => small.push(id), + (false, false) => {} + } + } + (full, small) +} + +/// 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() { + use crate::tests::panel_harness::Panel; + use egui::Modifiers; + let (mut app, [layer, sub, g, b, a, c]) = nested(); + let rows = [layer, sub, g, b, a, c]; + name_row(&mut app, layer, "Top"); + name_row(&mut app, sub, "Sub"); + name_row(&mut app, a, "A"); + app.session.execute("select.set", &json!({"ids": [a.0]})).unwrap(); + assert_eq!(squares(&app, &rows), (vec![a], vec![layer, sub]), "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(&app, &rows), (vec![b, a], vec![layer, sub, g]), "a group's member is not the group: the sublayer's square stays small"); + let mut panel = Panel::new(app, show); + panel.click_with("Select art of Sub", Modifiers::NONE); + assert_eq!(squares(&panel.app(), &rows), (vec![sub, g, a], vec![layer]), "the sublayer, its group and rectangle full, the layer small"); + panel.click_with("Select art of Top", Modifiers::NONE); + assert_eq!(squares(&panel.app(), &rows), (vec![layer, sub, g, a, c], vec![]), "the layer and the sublayer full, with each row's art"); + panel.click_with("Select art of A", Modifiers::SHIFT); + assert_eq!(squares(&panel.app(), &rows), (vec![g, c], vec![layer, sub]), "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. + panel.app().session.execute("layer.setProps", &json!({"ids": [c.0], "locked": true})).unwrap(); + panel.click_with("Select art of Sub", Modifiers::NONE); + assert_eq!(squares(&panel.app(), &rows), (vec![layer, sub, g, a], vec![]), "the layer, the sublayer, the group and the rectangle"); + // Hidden art neither. + panel.app().session.execute("layer.setProps", &json!({"ids": [c.0], "locked": false, "visible": false})).unwrap(); + panel.app().session.execute("select.set", &json!({"ids": [a.0, g.0]})).unwrap(); + assert_eq!(squares(&panel.app(), &rows), (vec![layer, sub, g, a], vec![]), "hidden art is left out"); + // With nothing targeted, the full layers' target circles show as targeted too. + let app = panel.app(); + let st = app.session.active().unwrap(); + let tree = DocLayers::new(&app, st); + assert!(rows::shows_targeted(&tree, st.doc.node(layer).unwrap(), false), "the layer shows as targeted"); +} + +/// 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, [layer, sub, g, b, a, c]) = nested(); + let empty = NodeId(app.session.execute("layer.new", &json!({})).unwrap()["id"].as_u64().unwrap()); + app.session.execute("select.set", &json!({"ids": [c.0, a.0, g.0]})).unwrap(); + let rows = [empty, layer, sub, g, b, a, c]; + assert_eq!(squares(&app, &rows), (vec![layer, sub, g, a, c], vec![]), "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}"); + } +} diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 48fb82b20c..76f37f81af 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1627,6 +1627,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).