Selection: a selected linked image is crossed from corner to corner

A selected linked image or placed document now 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. An image is outlined along its frame, so a
turned or distorted image's outline follows its corners. The lines are
selection marks: View > Hide Edges hides them, the hover highlight
does not draw them, and output is unchanged. The overlay's point
limit counts their ends where they are drawn.

Fixes #9080
This commit is contained in:
dotCooCoo committed 2026-11-22 03:41:21 -08:00
1 parent db9acab4da
commit 86eed6b47d
8 files changed
+194 -15

No files matched your search

+62 -8
View File
@@ -39,8 +39,8 @@ pub(super) fn c32(rgb: [u8; 3]) -> Color32 {
Color32::from_rgb(rgb[0], rgb[1], rgb[2])
}
/// Outline of a node for highlighting (paths, compound children, area type frames, other
/// text/image bounds, symbol instances' bounds measured by their art from `symbols`; a clip
/// Outline of a node for highlighting (paths, compound children, area type frames, other text
/// bounds, images' frames, symbol instances' bounds measured by their art from `symbols`; a clip
/// group's clipping path only, as [`walk_drawn`] visits it).
pub(super) fn node_outline(n: &Node, symbols: &SymbolBoxes) -> BezPath {
let mut bp = BezPath::new();
@@ -62,7 +62,13 @@ pub(super) fn node_outline(n: &Node, symbols: &SymbolBoxes) -> BezPath {
bp.extend(vectorcraft_geom::shapes::rectangle(b).to_bezpath());
}
}
NodeKind::Image(_) | NodeKind::SymbolInstance { .. } => {
// An image shows its frame, turned or distorted with it.
NodeKind::Image(_) => {
if let Some(frame) = c.image_frame() {
bp.extend(frame);
}
}
NodeKind::SymbolInstance { .. } => {
if let Some(b) = c.geometric_bounds_with(symbols) {
bp.extend(vectorcraft_geom::shapes::rectangle(b).to_bezpath());
}
@@ -87,6 +93,41 @@ pub(super) fn node_outline(n: &Node, symbols: &SymbolBoxes) -> BezPath {
bp
}
/// Whether `n` is a linked image or a placed document, which the selection marks cross.
fn is_linked(n: &Node) -> bool {
match &n.kind {
NodeKind::Image(im) => im.link.is_some(),
NodeKind::PlacedDocument(_) => true,
_ => false,
}
}
/// The corners (top left, top right, bottom right, bottom left) of a linked image's frame or of a
/// placed document's box. `None` for an embedded image and for anything else.
fn linked_corners(n: &Node) -> Option<[Point; 4]> {
match &n.kind {
NodeKind::Image(_) if is_linked(n) => n.image_corners(),
NodeKind::PlacedDocument(p) => Some(p.corners()),
_ => None,
}
}
/// The lines that cross each linked image and placed document of `n` that [`walk_drawn`] visits,
/// from corner to corner of its frame or box (#9080). The selection marks draw them; the hover
/// highlight does not.
pub(super) fn linked_crosses(n: &Node) -> BezPath {
let mut bp = BezPath::new();
walk_drawn(n, &mut |c| {
if let Some([tl, tr, br, bl]) = linked_corners(c) {
bp.move_to(tl);
bp.line_to(br);
bp.move_to(tr);
bp.line_to(bl);
}
});
bp
}
/// The width of the key object's outline (Align to Key Object), thicker than the selection's.
pub(super) const KEY_OUTLINE: f32 = 2.5;
@@ -100,19 +141,32 @@ pub(super) const OVERLAY_MAX_ANCHORS: usize = 100_000;
/// Whether `nodes` have more than [`OVERLAY_MAX_ANCHORS`] points to outline ([`overlay_points`];
/// counting stops there).
pub(super) fn too_many_anchors<'a>(nodes: impl IntoIterator<Item = &'a Node>) -> bool {
fn over(n: &Node, left: &mut usize) -> bool {
match left.checked_sub(overlay_points(n)) {
over_limit(nodes, false)
}
/// Whether `nodes` have more than [`OVERLAY_MAX_ANCHORS`] points to outline and to cross where they
/// are linked images or placed documents ([`linked_crosses`]), as the selection marks draw them.
pub(super) fn too_many_marks<'a>(nodes: impl IntoIterator<Item = &'a Node>) -> bool {
over_limit(nodes, true)
}
/// Whether `nodes` have more than [`OVERLAY_MAX_ANCHORS`] points ([`overlay_points`], with the
/// ends of the crossing lines when `crosses`); counting stops there.
fn over_limit<'a>(nodes: impl IntoIterator<Item = &'a Node>, crosses: bool) -> bool {
fn over(n: &Node, left: &mut usize, crosses: bool) -> bool {
let ends = if crosses && is_linked(n) { 4 } else { 0 };
match left.checked_sub(overlay_points(n) + ends) {
Some(l) => *left = l,
None => return true,
}
// A clip group counts only its clipping path, the one child `walk_drawn` visits.
if n.clips() {
return n.children().and_then(|children| children.first()).is_some_and(|clip| over(clip, left));
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))
!matches!(n.kind, NodeKind::Envelope { .. }) && n.editing_children().iter().any(|c| over(c, left, crosses))
}
let mut left = OVERLAY_MAX_ANCHORS;
nodes.into_iter().any(|n| over(n, &mut left))
nodes.into_iter().any(|n| over(n, &mut left, crosses))
}
/// The points counted for `n` itself, without its children, toward [`OVERLAY_MAX_ANCHORS`]: a
+2 -2
View File
@@ -6,7 +6,7 @@ use egui::epaint::{TessellationOptions, Tessellator};
use super::artboards::names_an_artboard;
use super::input::marquee_through;
use super::outline::{KEY_OUTLINE, c32, node_outline, selection_hit_at, stroke_path, to_screen_path, too_many_anchors};
use super::outline::{KEY_OUTLINE, c32, node_outline, selection_hit_at, stroke_path, to_screen_path, too_many_anchors, too_many_marks};
use super::selection_marks::{MarkOptions, SelectionMarks};
use super::{BezPath, Color32, CornerRadius, NodeKind, Overlay, Pos2, Shape, Stroke, StrokeKind, Tokens, VectorcraftApp, Xf, vec2};
@@ -161,7 +161,7 @@ pub(super) fn selection_overlay(app: &mut VectorcraftApp, p: &egui::Painter, xf:
};
let st = app.session.active();
let show_marks = !crate::dialogs::halftone::previewing(app);
let big = show_marks && st.is_some_and(|st| too_many_anchors(st.selection.objects.iter().filter_map(|id| st.doc.node(*id))));
let big = show_marks && st.is_some_and(|st| too_many_marks(st.selection.objects.iter().filter_map(|id| st.doc.node(*id))));
let big_bounds = if big { app.selection_bounds() } else { None };
let app = &*app;
let Some(st) = app.session.active() else { return };
+5 -3
View File
@@ -10,7 +10,7 @@ use std::collections::HashMap;
use std::sync::Arc;
use super::grid::LineLook;
use super::outline::{c32, node_outline, to_screen_path, too_many_anchors};
use super::outline::{c32, linked_crosses, node_outline, to_screen_path, too_many_marks};
use super::view::fit_zoom;
use super::{
Affine, BezPath, CacheKey, Point, Rect, RulerScale, Sense, Stroke, StrokeKind, Tokens, Ui, VectorcraftApp, View, Xf, artboard_edges, backdrop,
@@ -639,7 +639,7 @@ fn outline_shapes(st: &vectorcraft_engine::DocState, xf: &Xf) -> Vec<egui::Shape
st.selection.objects.iter().filter_map(|id| Some((*id, st.doc.node(*id)?))).collect();
let color = |id: vectorcraft_doc::NodeId| Stroke::new(1.0, c32(st.doc.layer_color(id)));
let mut stroke = |bp: &BezPath, s: Stroke| shapes.extend(to_screen_path(bp, xf).into_iter().map(|line| egui::Shape::line(line, s)));
if too_many_anchors(nodes.iter().map(|(_, n)| *n)) {
if too_many_marks(nodes.iter().map(|(_, n)| *n)) {
let bounds = nodes.iter().filter_map(|(_, n)| n.geometric_bounds_with(&symbols)).reduce(|a, b| a.union(b));
if let (Some(b), Some((id, _))) = (bounds, nodes.first()) {
stroke(&vectorcraft_geom::shapes::rectangle(b).to_bezpath(), color(*id));
@@ -647,7 +647,9 @@ fn outline_shapes(st: &vectorcraft_engine::DocState, xf: &Xf) -> Vec<egui::Shape
return shapes;
}
for (id, n) in nodes {
stroke(&node_outline(n, &symbols), color(id));
let color = color(id);
stroke(&node_outline(n, &symbols), color);
stroke(&linked_crosses(n), color);
}
shapes
}
+27 -1
View File
@@ -892,7 +892,7 @@ fn outlines_made_each_frame(st: &vectorcraft_engine::DocState, xf: &Xf) -> Vec<S
shapes.push(Shape::line(line, s));
}
};
if too_many_anchors(nodes.iter().map(|(_, n)| *n)) {
if too_many_marks(nodes.iter().map(|(_, n)| *n)) {
let bounds = nodes.iter().filter_map(|(_, n)| n.geometric_bounds_with(&symbols)).reduce(|a, b| a.union(b));
if let (Some(b), Some((id, _))) = (bounds, nodes.first()) {
stroke_path(&vectorcraft_geom::shapes::rectangle(b).to_bezpath(), color(*id));
@@ -901,6 +901,7 @@ fn outlines_made_each_frame(st: &vectorcraft_engine::DocState, xf: &Xf) -> Vec<S
}
for (id, n) in nodes {
stroke_path(&node_outline(n, &symbols), color(id));
stroke_path(&linked_crosses(n), color(id));
}
shapes
}
@@ -942,6 +943,31 @@ fn kept_outlines_do_not_show_for_a_new_document_that_takes_a_freed_documents_add
assert!(!reused, "the weak reference keeps the freed document's address from being taken");
}
/// Another pane crosses a selected linked image from corner to corner, as the current pane does,
/// and outlines a selected embedded image alone (#9080).
#[test]
fn other_panes_cross_a_selected_linked_image() {
use craft_image_codecs::{ChannelLayout, EncodeOptions, Format, Image, SampleType};
let dir = vectorcraft_testkit::temp_dir("panes-linked-image");
let png = dir.join("red.png");
let image = Image::from_raw(40, 40, ChannelLayout::Rgba, SampleType::U8, [200u8, 40, 40, 255].repeat(40 * 40)).unwrap();
std::fs::write(&png, craft_image_codecs::encode(&image, Format::Png, &EncodeOptions::default()).unwrap()).unwrap();
let mut app = app_with(2);
app.run("document.activate", json!({"index": 1})).unwrap();
app.run("window.arrange.tile", json!({})).unwrap();
let ctx = egui::Context::default();
let linked = in_first(&mut app, "file.place", json!({"path": png, "link": true, "at": [100, 100]}))["ids"][0].clone();
let embedded = in_first(&mut app, "file.place", json!({"path": png, "link": false, "at": [250, 100]}))["ids"][0].clone();
let lines = |app: &mut VectorcraftApp, id: &serde_json::Value| {
in_first(app, "select.set", json!({"ids": [id]}));
frame(app, &ctx, vec![]);
let drawn = frame(app, &ctx, vec![]);
kept_outlines(app, &ctx, &drawn).len()
};
let (linked, embedded) = (lines(&mut app, &linked), lines(&mut app, &embedded));
assert_eq!(linked, embedded + 2, "the outline of a linked image and its two crossing lines; an embedded image's outline alone");
}
#[test]
fn other_panes_keep_their_selected_outlines_until_the_document_selection_or_view_changes() {
let mut app = app_with(2);
+3 -1
View File
@@ -21,7 +21,7 @@ use egui::epaint::{ClippedShape, Primitive, RectShape, TessellationOptions, Tess
use egui::{Mesh, Vec2};
use vectorcraft_doc::{AnchorRef, NodeId, SegmentRef};
use super::outline::{KEY_OUTLINE, c32, node_outline, to_screen_path, walk_drawn};
use super::outline::{KEY_OUTLINE, c32, linked_crosses, node_outline, to_screen_path, walk_drawn};
use super::overlays::{HandleLook, anchor_square, selected_anchor};
use super::{BezPath, Color32, Node, NodeKind, Point, Pos2, Shape, Stroke, StrokeKind, SymbolBoxes, Xf, pos2, vec2};
@@ -839,6 +839,8 @@ fn object_marks(
if !matches!(n.kind, NodeKind::Text(ref tx) if matches!(tx.kind, vectorcraft_doc::TextKind::Point)) {
marks.outline(&node_outline(n, symbols), xf, Stroke::new(1.0, color));
}
// Linked images and placed documents crossed from corner to corner.
marks.outline(&linked_crosses(n), xf, Stroke::new(1.0, color));
// Anchors (and handles for selected anchors in direct mode); a gradient mesh's or a mesh
// envelope's points.
walk_drawn(n, &mut |c| {
@@ -63,6 +63,7 @@ fn plain(app: &VectorcraftApp, p: &egui::Painter, xf: &Xf, curve_points_from_too
if !matches!(n.kind, NodeKind::Text(ref tx) if matches!(tx.kind, vectorcraft_doc::TextKind::Point)) {
stroke(&node_outline(n, &symbols), 1.0);
}
stroke(&linked_crosses(n), 1.0);
walk_drawn(n, &mut |c| {
let envelope = vectorcraft_doc::live::envelope_overlay(c).and_then(|(_, grid)| grid);
let grid = match &c.kind {
@@ -584,6 +585,73 @@ fn an_edit_of_a_symbol_outlines_its_instance_again() {
assert_matches_plain(&ctx, &mut marks, &app, &view, 1.0, "after the edit");
}
/// A selected linked image and a selected placed document are crossed from corner to corner, on a
/// turned image along its frame; a selected embedded image shows its outline alone, and output of
/// the linked image shows no cross (#9080).
#[test]
fn a_selected_linked_image_is_crossed_and_an_embedded_one_is_not() {
use craft_image_codecs::{ChannelLayout, EncodeOptions, Format, Image, SampleType};
let dir = vectorcraft_testkit::temp_dir("selection-marks-linked");
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 placed = dir.join("art.vectorcraft");
std::fs::write(&placed, vectorcraft_format::save_file(&vectorcraft_doc::Document::new(60.0, 40.0))).unwrap();
let mut app = VectorcraftApp::new(Session::new(), Default::default());
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
let place = |app: &mut VectorcraftApp, path: &std::path::Path, link: bool, at: [f64; 2]| {
NodeId(app.run("file.place", json!({"path": path, "link": link, "at": at})).unwrap()["ids"][0].as_u64().unwrap())
};
let linked = place(&mut app, &png, true, [100.0, 120.0]);
let embedded = place(&mut app, &png, false, [300.0, 120.0]);
let document = place(&mut app, &placed, true, [200.0, 230.0]);
let ctx = egui::Context::default();
let view = xf(1.0, VIEW, 0.0);
// Whether the marks draw within a pixel of each of the points a quarter and three quarters of
// the way along each diagonal of `corners`, clear of the outline.
let crossed = |app: &VectorcraftApp, corners: [Point; 4]| -> [bool; 4] {
let picture = picture(&ctx, 1.0, |p| paint(&mut SelectionMarks::default(), app, p, &view, false));
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);
picture.pixels[y * picture.size.0 + x][3] > 0.0
})
})
};
let [tl, tr, br, bl] = corners;
assert!([(tl, tr), (tr, br), (br, bl), (bl, tl)].into_iter().all(|(a, b)| drawn(a.midpoint(b))), "the outline runs along the frame");
[tl.lerp(br, 0.25), tl.lerp(br, 0.75), tr.lerp(bl, 0.25), tr.lerp(bl, 0.75)].map(drawn)
};
let corners = |app: &VectorcraftApp, id: NodeId| {
let n = app.session.active().unwrap().doc.node(id).unwrap();
match &n.kind {
NodeKind::PlacedDocument(p) => p.corners(),
_ => n.image_corners().unwrap(),
}
};
app.run("select.all", json!({})).unwrap();
assert_eq!(crossed(&app, corners(&app, linked)), [true; 4], "a linked image");
assert_eq!(crossed(&app, corners(&app, document)), [true; 4], "a placed document");
assert_eq!(crossed(&app, corners(&app, embedded)), [false; 4], "an embedded image");
assert_matches_plain(&ctx, &mut SelectionMarks::default(), &app, &view, 1.0, "linked and embedded images");
app.run("select.set", json!({"ids": [linked.0]})).unwrap();
app.run("object.rotate", json!({"angle": 30})).unwrap();
assert_eq!(crossed(&app, corners(&app, linked)), [true; 4], "a turned linked image, along its frame");
let doc = &app.session.active().unwrap().doc;
let [tl, tr, br, bl] = corners(&app, linked);
let bounds = doc.node(linked).unwrap().geometric_bounds().unwrap();
let out = vectorcraft_testkit::raster::render_region(doc, bounds, 1.0);
let pixel = |q: Point| out.pixel((q.x - bounds.x0).round() as u32, (q.y - bounds.y0).round() as u32);
// Halfway between the middle of the left side and the centre: clear of both diagonals.
let clear = pixel(tl.midpoint(bl).midpoint(tl.midpoint(br)));
assert!(clear[0] > 150 && clear[1] < 100 && clear[3] == 255, "the render shows the image: {clear:?}");
let on_lines = [tl.lerp(br, 0.25), tl.lerp(br, 0.75), tr.lerp(bl, 0.25), tr.lerp(bl, 0.75)];
assert!(on_lines.iter().all(|q| pixel(*q) == clear), "output of a selected linked image is not crossed");
}
/// A frame of the whole canvas keeps entries for the selected objects only.
#[test]
fn the_canvas_drops_entries_it_does_not_draw() {
+26
View File
@@ -776,6 +776,32 @@ fn a_clip_group_over_a_huge_path_shows_its_clipping_path() {
assert_eq!((anchors, hovered), (4, true), "the square's four anchors, and the hover highlight");
}
/// The selection marks count the ends of the lines that cross linked images toward the overlay's
/// limit; the hover highlight and the key object's outline, which draw no such lines, do not
/// (#9080).
#[test]
fn the_overlay_limit_counts_crossing_lines_only_where_they_are_drawn() {
use super::outline::{too_many_anchors, too_many_marks};
let image = |link: Option<vectorcraft_doc::LinkInfo>| {
let im = vectorcraft_doc::ImageObject {
key: "k".into(),
width: 10,
height: 10,
xf: vectorcraft_geom::Affine::IDENTITY,
link,
placement: Default::default(),
pixels: None,
};
vectorcraft_doc::Node::new(vectorcraft_doc::NodeId(1), NodeKind::Image(Box::new(im)))
};
// Four corners each fit; with the four ends of the crossing lines they do not.
let count = OVERLAY_MAX_ANCHORS / 6;
let linked = vec![image(Some(vectorcraft_doc::LinkInfo { path: "/a.png".into(), ..Default::default() })); count];
let embedded = vec![image(None); count];
assert!(!too_many_anchors(&linked) && too_many_marks(&linked), "linked images");
assert!(!too_many_anchors(&embedded) && !too_many_marks(&embedded), "embedded images");
}
/// #2422: the art inside a clip group still shows its whole outline when it is picked on its
/// own: by Edit Contents, by a Direct Selection or Group Selection click, and in isolation mode;
/// so does its Group Selection hover highlight.
+1
View File
@@ -661,6 +661,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. `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 turned one, a placed document, an embedded image 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. 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.