mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-24 23:50:13 +00:00
Gradient: freeform Lines mode counts a symbol's stroke on a Preview-off layer of its art
The walk of a symbol instance's art switched to outline for a layer of the art whose Preview is off without checking ignore_layer_preview, so with the option set a press on the art's stroke past the instance's box missed. FindPart::find now checks the option, as the other point hit paths do.
This commit is contained in:
@@ -1793,7 +1793,7 @@ impl FindPart<'_> {
|
||||
if !n.visible || !self.whole_instance && (n.locked || n.is_template()) || self.skips_guide(n) || ArtWalk::used_up() {
|
||||
return None;
|
||||
}
|
||||
let outline = outline || previews_off(n);
|
||||
let outline = outline || !self.opt.ignore_layer_preview && previews_off(n);
|
||||
let opt = HitOptions { outline, ..self.opt };
|
||||
let (NodeKind::Group { children, .. } | NodeKind::Layer { children, .. }) = &n.kind else { return self.hit(n, whole, opt) };
|
||||
if path.len() >= crate::symbol_overrides::MAX_PATH_DEPTH {
|
||||
|
||||
@@ -2831,6 +2831,32 @@ fn a_symbol_instance_is_hit_on_the_stroke_of_its_art_past_its_box() {
|
||||
assert_eq!(at(108.0, HitOptions { outline: true, ..HitOptions::default() }), None, "Outline view");
|
||||
}
|
||||
|
||||
/// A symbol's art on a layer of the symbol whose Preview is off is hit in outline, unless the
|
||||
/// click sets [`HitOptions::ignore_layer_preview`]: then the stroke past the instance's box hits.
|
||||
#[test]
|
||||
fn ignore_layer_preview_reaches_symbol_art_on_a_preview_off_layer() {
|
||||
let mut d = Document::new(300.0, 200.0);
|
||||
let l = d.layers[0].id;
|
||||
// A 20 pt stroke reaches 10 pt past the 0..100 square.
|
||||
let look = Appearance::basic(Paint::solid(Color::BLACK), Paint::solid(Color::BLACK), 20.0);
|
||||
let square = Node::path(d.alloc_id(), shapes::rectangle(Rect::new(0.0, 0.0, 100.0, 100.0)), look);
|
||||
let mut layer = Node::layer(d.alloc_id(), "Art", crate::LayerColor::Preset(2));
|
||||
if let NodeKind::Layer { children, preview, .. } = &mut layer.kind {
|
||||
*children = vec![Arc::new(square)];
|
||||
*preview = false;
|
||||
}
|
||||
let art = Node::group(d.alloc_id(), vec![Arc::new(layer)]);
|
||||
d.symbols.push(crate::Symbol { dynamic: false, name: "Stroked".into(), art: Arc::new(art) });
|
||||
let inst = d.alloc_id();
|
||||
let xf = vectorcraft_geom::Affine::IDENTITY;
|
||||
d.insert(Some(l), 0, Node::new(inst, NodeKind::SymbolInstance { symbol: "Stroked".into(), xf })).unwrap();
|
||||
let at = |x: f64, opt: HitOptions| hit_test(&d, Point::new(x, 50.0), opt).map(|h| h.leaf);
|
||||
let painted = HitOptions { ignore_layer_preview: true, ..HitOptions::default() };
|
||||
assert_eq!(at(108.0, HitOptions::default()), None, "Preview off: in outline");
|
||||
assert_eq!(at(108.0, painted), Some(inst), "ignore_layer_preview: on the stroke past the box");
|
||||
assert_eq!(at(116.0, painted), None, "past the stroke");
|
||||
}
|
||||
|
||||
/// Outside a symbol instance's box, an instance nested in its art counts where its own art is, not
|
||||
/// anywhere in its box: a click or a marquee on empty space in the nested box, where a moved
|
||||
/// clipping path shows the art past the outer box, selects nothing, and on art drawn there it
|
||||
|
||||
Reference in New Issue
Block a user