mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 16:59:43 +01:00
Selection: a selected group leaves its hidden members unmarked
The selection marks walked every member of a selected group or layer, so a hidden member, and the art inside a hidden group or a hidden sublayer, showed its outline, its anchors and the lines across a linked image, although the canvas does not draw hidden objects. The walk now skips hidden members, so the selection marks, the hover highlight and the outlines in other panes leave them out, and the overlay point limit no longer counts their points. The same holds for the members of a blend, a repeat and an intertwine. A compound path keeps every path, since it draws all of them, and an Image Trace object keeps its hidden source image in the views that show it. A hidden object that is itself selected keeps its marks.
This commit is contained in:
1 parent
e79aa9836a
commit
4f6e1515b4
5 files changed
+170
-6
No files matched your search
@@ -361,7 +361,8 @@ impl Node {
|
||||
}
|
||||
|
||||
/// Children that contribute to a container's editing bounds and selection highlights. A live trace retains a
|
||||
/// hidden bitmap for re-tracing/release; only source-image views measure that bitmap.
|
||||
/// hidden bitmap for re-tracing/release; only source-image views measure that bitmap. The canvas's selection
|
||||
/// highlights also leave out hidden members, except a compound path's paths.
|
||||
pub fn editing_children(&self) -> &[Arc<Node>] {
|
||||
let children = self.children().map(Vec::as_slice).unwrap_or_default();
|
||||
let trace_source = self.extras().trace.is_some()
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use super::{BezPath, Color32, Node, NodeKind, PathEl, Point, Pos2, Shape, Stroke, SymbolBoxes, VectorcraftApp, Xf, pos2};
|
||||
|
||||
pub(super) fn to_screen_path(bp: &BezPath, xf: &Xf) -> Vec<Vec<Pos2>> {
|
||||
@@ -163,7 +165,7 @@ fn over_limit<'a>(nodes: impl IntoIterator<Item = &'a Node>, crosses: bool) -> b
|
||||
if n.clips() {
|
||||
return n.children().and_then(|children| children.first()).is_some_and(|clip| over(clip, left, crosses));
|
||||
}
|
||||
!matches!(n.kind, NodeKind::Envelope { .. }) && n.editing_children().iter().any(|c| over(c, left, crosses))
|
||||
!matches!(n.kind, NodeKind::Envelope { .. }) && drawn_children(n).any(|c| over(c, left, crosses))
|
||||
}
|
||||
let mut left = OVERLAY_MAX_ANCHORS;
|
||||
nodes.into_iter().any(|n| over(n, &mut left, crosses))
|
||||
@@ -193,9 +195,23 @@ fn overlay_points(n: &Node) -> usize {
|
||||
}
|
||||
}
|
||||
|
||||
/// The children of `n` that [`walk_drawn`] visits: [`Node::editing_children`], without the hidden
|
||||
/// members, which the canvas does not draw. An Image Trace object's hidden source image stays when
|
||||
/// the object's view shows it. Every path of a compound path stays, since the compound path draws
|
||||
/// all of them.
|
||||
fn drawn_children(n: &Node) -> impl Iterator<Item = &Arc<Node>> {
|
||||
let members = !matches!(n.kind, NodeKind::Compound { .. });
|
||||
let source = (n.extras().trace.is_some() && n.trace_view().shows_source())
|
||||
.then(|| n.children().and_then(|children| children.first()))
|
||||
.flatten()
|
||||
.filter(|c| matches!(c.kind, NodeKind::Image(_)));
|
||||
n.editing_children().iter().filter(move |c| !members || c.visible || source.is_some_and(|s| Arc::ptr_eq(s, c)))
|
||||
}
|
||||
|
||||
/// [`Node::walk`] over what a selection highlight shows: an envelope's content is left out (the
|
||||
/// envelope shows its mesh instead), and a clip group or clipping layer shows only its clipping
|
||||
/// path, its first child, not the art the path clips (#2422).
|
||||
/// envelope shows its mesh instead), a clip group or clipping layer shows only its clipping path,
|
||||
/// its first child, not the art the path clips (#2422), and hidden members are left out
|
||||
/// ([`drawn_children`]).
|
||||
pub(super) fn walk_drawn<'a>(n: &'a Node, f: &mut impl FnMut(&'a Node)) {
|
||||
f(n);
|
||||
if matches!(n.kind, NodeKind::Envelope { .. }) {
|
||||
@@ -207,7 +223,7 @@ pub(super) fn walk_drawn<'a>(n: &'a Node, f: &mut impl FnMut(&'a Node)) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
for c in n.editing_children().iter() {
|
||||
for c in drawn_children(n) {
|
||||
walk_drawn(c, f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -692,6 +692,70 @@ fn a_selected_linked_image_is_crossed_and_an_embedded_one_is_not() {
|
||||
}
|
||||
}
|
||||
|
||||
/// A selected group outlines, marks and crosses only the members the canvas draws: a hidden member
|
||||
/// and the members of a hidden group inside it leave no outline, anchors or crossing lines.
|
||||
#[test]
|
||||
fn a_selected_group_leaves_its_hidden_members_unmarked() {
|
||||
use craft_image_codecs::{ChannelLayout, EncodeOptions, Format, Image, SampleType};
|
||||
let dir = vectorcraft_testkit::temp_dir("selection-marks-hidden");
|
||||
let png = dir.join("red.png");
|
||||
let pixels = [200u8, 40, 40, 255].repeat(40 * 40);
|
||||
let image = Image::from_raw(40, 40, ChannelLayout::Rgba, SampleType::U8, pixels).unwrap();
|
||||
std::fs::write(&png, craft_image_codecs::encode(&image, Format::Png, &EncodeOptions::default()).unwrap()).unwrap();
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
|
||||
let left = id_of(&app.run("shape.rectangle", json!({"x": 40, "y": 40, "width": 20, "height": 20})).unwrap());
|
||||
let right = id_of(&app.run("shape.rectangle", json!({"x": 330, "y": 230, "width": 20, "height": 20})).unwrap());
|
||||
let hidden = id_of(&app.run("shape.rectangle", json!({"x": 120, "y": 100, "width": 40, "height": 40})).unwrap());
|
||||
let linked = NodeId(app.run("file.place", json!({"path": png, "link": true, "at": [240.0, 150.0]})).unwrap()["ids"][0].as_u64().unwrap());
|
||||
app.run("select.set", json!({"ids": [linked.0]})).unwrap();
|
||||
let inner = id_of(&app.run("object.group", json!({})).unwrap());
|
||||
app.run("select.set", json!({"ids": [left.0, right.0, hidden.0, inner.0]})).unwrap();
|
||||
let group = id_of(&app.run("object.group", json!({})).unwrap());
|
||||
app.session
|
||||
.edit("Hide", |doc, _| {
|
||||
for id in [hidden, inner] {
|
||||
if let Some(n) = doc.node_mut(id) {
|
||||
n.visible = false;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
app.run("select.set", json!({"ids": [group.0]})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let view = xf(1.0, VIEW, 0.0);
|
||||
let marks = picture(&ctx, 1.0, |p| paint(&mut SelectionMarks::default(), &app, p, &view, false));
|
||||
// Whether the marks draw within a pixel of document point `q`.
|
||||
let drawn = |q: Point| {
|
||||
let s = view.to_screen(q);
|
||||
(-1..=1).any(|dy| {
|
||||
(-1..=1).any(|dx| {
|
||||
let (x, y) = ((s.x.round() as i64 + dx) as usize, (s.y.round() as i64 + dy) as usize);
|
||||
marks.pixels[y * marks.size.0 + x][3] > 0.0
|
||||
})
|
||||
})
|
||||
};
|
||||
let doc = &app.session.active().unwrap().doc;
|
||||
let sides = |id: NodeId| {
|
||||
let b = doc.node(id).unwrap().geometric_bounds().unwrap();
|
||||
[Point::new(b.x0, b.y0), Point::new(b.x1, b.y0), Point::new(b.x1, b.y1), Point::new(b.x0, b.y1)]
|
||||
};
|
||||
for id in [left, right] {
|
||||
let [tl, tr, br, bl] = sides(id);
|
||||
assert!([tl, tr, br, bl, tl.midpoint(tr), br.midpoint(bl)].into_iter().all(drawn), "a visible member is outlined and marked");
|
||||
}
|
||||
let [tl, tr, br, bl] = doc.node(linked).unwrap().image_corners().unwrap();
|
||||
assert!(
|
||||
![tl.lerp(br, 0.25), tl.lerp(br, 0.75), tr.lerp(bl, 0.25), tr.lerp(bl, 0.75)].into_iter().any(drawn),
|
||||
"the lines across a linked image in a hidden group"
|
||||
);
|
||||
assert!(![tl.midpoint(tr), tr.midpoint(br)].into_iter().any(drawn), "the outline of a linked image in a hidden group");
|
||||
let [tl, tr, br, bl] = sides(hidden);
|
||||
assert!(![tl, tr, br, bl, tl.midpoint(tr), tr.midpoint(br), br.midpoint(bl), bl.midpoint(tl)].into_iter().any(drawn), "a hidden member");
|
||||
assert_matches_plain(&ctx, &mut SelectionMarks::default(), &app, &view, 1.0, "a group with hidden members");
|
||||
}
|
||||
|
||||
/// A frame of the whole canvas keeps entries for the selected objects only.
|
||||
#[test]
|
||||
fn the_canvas_drops_entries_it_does_not_draw() {
|
||||
|
||||
@@ -802,6 +802,41 @@ fn the_overlay_limit_counts_crossing_lines_only_where_they_are_drawn() {
|
||||
assert!(!too_many_anchors(&embedded) && !too_many_marks(&embedded), "embedded images");
|
||||
}
|
||||
|
||||
/// The overlay's limit counts the points of the members the highlight outlines: a hidden member of
|
||||
/// a group, and the art of a hidden sublayer, do not count toward it.
|
||||
#[test]
|
||||
fn the_overlay_limit_leaves_out_hidden_members() {
|
||||
use super::outline::{too_many_anchors, too_many_marks};
|
||||
use std::sync::Arc;
|
||||
use vectorcraft_doc::{Appearance, LayerColor, NodeId};
|
||||
use vectorcraft_geom::{PathData, SubPath};
|
||||
let points: Vec<Point> = (0..=OVERLAY_MAX_ANCHORS).map(|i| Point::new(i as f64, 0.0)).collect();
|
||||
let many = Arc::new(Node::path(NodeId(2), PathData::single(SubPath::polyline(&points, false)), Appearance::default()));
|
||||
let few = Arc::new(Node::path(
|
||||
NodeId(3),
|
||||
vectorcraft_geom::shapes::rectangle(vectorcraft_geom::Rect::new(0.0, 0.0, 10.0, 10.0)),
|
||||
Appearance::default(),
|
||||
));
|
||||
for visible in [true, false] {
|
||||
let mut member = (*many).clone();
|
||||
member.visible = visible;
|
||||
let group = Node::group(NodeId(1), vec![Arc::new(member), few.clone()]);
|
||||
let mut sublayer = Node::layer(NodeId(5), "Sublayer", LayerColor::Preset(1));
|
||||
sublayer.visible = visible;
|
||||
if let Some(children) = sublayer.children_mut() {
|
||||
children.push(many.clone());
|
||||
}
|
||||
let mut layer = Node::layer(NodeId(4), "Layer", LayerColor::Preset(0));
|
||||
if let Some(children) = layer.children_mut() {
|
||||
children.extend([Arc::new(sublayer), few.clone()]);
|
||||
}
|
||||
for (n, what) in [(&group, "a group"), (&layer, "a layer")] {
|
||||
assert_eq!(too_many_anchors([n]), visible, "{what}, member visible: {visible}");
|
||||
assert_eq!(too_many_marks([n]), visible, "{what}, member visible: {visible}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// View › Hide Edges hides the lines across a selected linked image along with its outline
|
||||
/// (#9080).
|
||||
#[test]
|
||||
@@ -13466,8 +13501,55 @@ fn live_trace_selection_highlight_excludes_the_retained_source_rectangle() {
|
||||
};
|
||||
assert_eq!(node_outline(&group, &symbols).bounding_box(), want);
|
||||
}
|
||||
// Without a trace the image is an ordinary hidden member, which the canvas does not draw.
|
||||
group.extras_mut().trace = None;
|
||||
assert_eq!(node_outline(&group, &symbols).bounding_box(), vectorcraft_geom::Rect::new(0.0, 0.0, 200.0, 200.0));
|
||||
assert_eq!(node_outline(&group, &symbols).bounding_box(), vectorcraft_geom::Rect::new(20.0, 30.0, 80.0, 90.0));
|
||||
// A hidden path sent to the back of a trace is not its source image, in any view.
|
||||
let mut path =
|
||||
Node::path(NodeId(4), vectorcraft_geom::shapes::rectangle(vectorcraft_geom::Rect::new(0.0, 0.0, 200.0, 200.0)), Appearance::default());
|
||||
path.visible = false;
|
||||
let art = Node::path(NodeId(3), vectorcraft_geom::shapes::rectangle(vectorcraft_geom::Rect::new(20.0, 30.0, 80.0, 90.0)), Appearance::default());
|
||||
let mut group = Node::group(NodeId(1), vec![Arc::new(path), Arc::new(art)]);
|
||||
for view in TraceView::ALL {
|
||||
group.extras_mut().trace = Some(Box::new(json!({"view":view.id()})));
|
||||
assert_eq!(node_outline(&group, &symbols).bounding_box(), vectorcraft_geom::Rect::new(20.0, 30.0, 80.0, 90.0), "{view:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// A compound path draws every path it holds, hidden ones included, so its highlight outlines them
|
||||
/// all; a group, a blend, an intertwine and a layer leave out a hidden member, and a layer the art
|
||||
/// of a hidden sublayer.
|
||||
#[test]
|
||||
fn a_compound_path_outlines_its_hidden_paths_and_a_group_does_not() {
|
||||
use std::sync::Arc;
|
||||
use vectorcraft_doc::{Appearance, LayerColor, NodeId};
|
||||
use vectorcraft_geom::FillRule;
|
||||
let rect = |id: u64, r: vectorcraft_geom::Rect, visible: bool| {
|
||||
let mut n = Node::path(NodeId(id), vectorcraft_geom::shapes::rectangle(r), Appearance::default());
|
||||
n.visible = visible;
|
||||
Arc::new(n)
|
||||
};
|
||||
let children = || {
|
||||
vec![rect(2, vectorcraft_geom::Rect::new(0.0, 0.0, 100.0, 100.0), true), rect(3, vectorcraft_geom::Rect::new(30.0, 30.0, 70.0, 70.0), false)]
|
||||
};
|
||||
let doc = vectorcraft_doc::Document::new(300.0, 300.0);
|
||||
let symbols = doc.symbol_boxes();
|
||||
let contours = |n: &Node| node_outline(n, &symbols).elements().iter().filter(|e| matches!(e, PathEl::MoveTo(_))).count();
|
||||
assert_eq!(contours(&Node::new(NodeId(1), NodeKind::Compound { children: children(), rule: FillRule::EvenOdd })), 2, "a compound path");
|
||||
assert_eq!(contours(&Node::new(NodeId(1), NodeKind::Blend { children: children(), spec: Default::default() })), 1, "a blend");
|
||||
assert_eq!(contours(&Node::group(NodeId(1), children())), 1, "a group");
|
||||
assert_eq!(contours(&Node::new(NodeId(1), NodeKind::Intertwine { children: children() })), 1, "an intertwine");
|
||||
let mut layer = Node::layer(NodeId(1), "Layer", LayerColor::Preset(0));
|
||||
let mut sublayer = Node::layer(NodeId(4), "Sublayer", LayerColor::Preset(1));
|
||||
sublayer.visible = false;
|
||||
if let Some(c) = sublayer.children_mut() {
|
||||
c.push(rect(5, vectorcraft_geom::Rect::new(150.0, 150.0, 200.0, 200.0), true));
|
||||
}
|
||||
if let Some(c) = layer.children_mut() {
|
||||
c.extend(children());
|
||||
c.push(Arc::new(sublayer));
|
||||
}
|
||||
assert_eq!(contours(&layer), 1, "a layer");
|
||||
}
|
||||
|
||||
/// Hovering over point type shows only its baseline (not the transform bounding box), while
|
||||
|
||||
@@ -662,6 +662,7 @@ since 2026-10-01.
|
||||
- **Selection — disconnected path deletion (#3380, deletion only):** Clear/Delete and Cut turn surviving disconnected pieces of an ordinary contour into independent selected sibling objects. The first keeps its ID; all keep appearance, baked transforms and stacking order. `deletion_split_preserves_gradient_placement` compares rendered survivors with the original paint space and checks linear/radial fill/stroke vectors, already placed gradients and atomic Undo/Redo; connected remainders keep automatic fitting. Existing multi-subpath paths and explicit compound members retain their semantics. Original synthetic regressions in `crates/engine/tests/it/delete_path_pieces.rs` cover styled/transformed rectangles, cubic handles, compound preservation and atomic Undo/Redo; `crates/ui-egui/src/tests/removeanchors.rs` covers real-frame Delete/Backspace and a second Delete removing all survivors. Segment endpoint highlighting remains open. Scores and hours unchanged.
|
||||
- **Selection: deletion on paths with many subpaths:** Clear/Delete, `path.deleteAnchors`, Copy, Cut and Cut Path read each subpath's selected anchors or segments directly from the path's ordered selection, instead of scanning every selected anchor or segment of the path once per subpath. The result is unchanged: `crates/engine/tests/it/delete_path_pieces.rs` checks exact surviving subpaths and their order, open and closed contours, an untouched subpath, references to missing subpaths and indexes, one Undo/Redo step and a second Delete, for anchor and segment selections on one path. Scores and hours unchanged.
|
||||
- **Selection: linked images are crossed (#9080):** a selected linked image or placed document shows two lines in its layer's color from corner to corner of its frame, in the current pane and in other panes of the same document. A selected embedded image shows its outline alone. A selected or highlighted image of either kind is outlined along its frame, so a turned or distorted image's outline follows its corners instead of the box square to the page around it. The lines are part of the selection marks, so View › Hide Edges hides them and output does not draw them. When the selection has more than VectorCraft's own limit of 100,000 outline points (each linked image or placed document adds 4 for the ends of its lines), the current pane and other panes draw one rectangle around the selected objects instead of their outlines and lines; the current pane still draws the key object's thicker outline. `a_selected_linked_image_is_crossed_and_an_embedded_one_is_not` in `crates/ui-egui/src/canvas/selection_marks/tests.rs` covers a linked image, a placed document and an embedded image, each image also turned and distorted, the key object's outline, the hover highlight and a render of the document; `other_panes_cross_a_selected_linked_image` in `crates/ui-egui/src/canvas/panes/tests.rs` covers another pane; `hide_edges_hides_the_lines_across_a_linked_image` in `crates/ui-egui/src/canvas/tests.rs` covers View › Hide Edges. Scores and hours unchanged.
|
||||
- **Selection: hidden members are not marked:** a selected group, layer, blend or intertwine draws no outline, anchors or lines across a linked image for its hidden members or for the art of a hidden sublayer, and neither do the hover highlight and other panes; the points of those members do not count toward the 100,000-point limit. Every path of a compound path, and an Image Trace object's source image in the views that show it, are still outlined. `a_selected_group_leaves_its_hidden_members_unmarked` in `crates/ui-egui/src/canvas/selection_marks/tests.rs`; `a_compound_path_outlines_its_hidden_paths_and_a_group_does_not`, `the_overlay_limit_leaves_out_hidden_members` and `live_trace_selection_highlight_excludes_the_retained_source_rectangle` in `crates/ui-egui/src/canvas/tests.rs`. Scores and hours unchanged.
|
||||
- **Panel collapse controls (#5925, in part):** The small » in a floating tab-group header moves that group into the side icon rail, reusing the existing rail or creating one. An opened rail panel has the same control to fold its flyout back into the rail, including after a tab switch. Both controls preserve the tab group and its menu; other floating groups and full-width docked headers stay as they were. Pointer regressions in `crates/ui-egui/src/panel_docking/tests.rs` cover grouped tabs, reopening, separate groups, a missing rail, the menu and flyout closure after switching tabs; `native_tests.rs` covers the native-window click and removal of the empty palette. Scores and estimates unchanged.
|
||||
|
||||
- 3D lighting presets: `crates/effects/src/lighting_presets.rs`, `crates/engine/src/cmd/effectcmd/lighting_presets_tests.rs` and the pointer tests in `crates/ui-egui/src/dialogs/revolve/tests.rs` cover recognition, atomic targeting, native round trips, preview, Cancel, reset and Undo.
|
||||
|
||||
Reference in new issue
Block a user