Skip to content

Commit fdebdec

Browse files
committed
Generate one compound click target per Vector so glyph holes aren't treated as filled
1 parent 52aac2d commit fdebdec

2 files changed

Lines changed: 27 additions & 17 deletions

File tree

editor/src/messages/portfolio/document/utility_types/document_metadata.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,10 @@ impl DocumentMetadata {
223223
}
224224

225225
pub fn layer_outline(&self, layer: LayerNodeIdentifier) -> impl Iterator<Item = &subpath::Subpath<PointId>> {
226-
self.visual_targets(layer).unwrap_or(&[]).iter().filter_map(|target| match target.target_type() {
227-
ClickTargetType::Subpath(subpath) => Some(subpath),
228-
_ => None,
226+
self.visual_targets(layer).unwrap_or(&[]).iter().flat_map(|target| match target.target_type() {
227+
ClickTargetType::Subpath(subpath) => std::slice::from_ref(subpath),
228+
ClickTargetType::CompoundPath(subpaths) => subpaths.as_slice(),
229+
ClickTargetType::FreePoint(_) => &[],
229230
})
230231
}
231232

node-graph/libraries/rendering/src/renderer.rs

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,23 +1465,33 @@ impl Render for Table<Vector> {
14651465
}
14661466
}
14671467

1468-
/// Build click targets (subpaths and free-floating anchors) from a `Vector`, apply the transform, and append to `targets`.
1468+
/// Build one `CompoundPath` (non-zero fill rule, so holes like the inside of an "O" work
1469+
/// correctly) plus one `FreePoint` per disconnected anchor, apply the transform, and append.
14691470
fn extend_targets_from_vector(targets: &mut Vec<ClickTarget>, vector: &Vector, transform: DAffine2) {
14701471
let stroke_width = vector.style.stroke().as_ref().map_or(0., Stroke::effective_width);
14711472
let filled = vector.style.fill() != &Fill::None;
1472-
let fill = |mut subpath: Subpath<_>| {
1473-
if filled {
1474-
subpath.set_closed(true);
1475-
}
1476-
subpath
1477-
};
1478-
targets.extend(vector.stroke_bezier_paths().map(fill).map(|subpath| {
1479-
let mut click_target = ClickTarget::new_with_subpath(subpath, stroke_width);
1473+
let subpaths: Vec<Subpath<_>> = vector
1474+
.stroke_bezier_paths()
1475+
.map(|mut subpath| {
1476+
if filled {
1477+
subpath.set_closed(true);
1478+
}
1479+
subpath
1480+
})
1481+
.collect();
1482+
if !subpaths.is_empty() {
1483+
let mut click_target = ClickTarget::new_with_compound_path(subpaths, stroke_width);
14801484
click_target.apply_transform(transform);
1481-
click_target
1482-
}));
1485+
targets.push(click_target);
1486+
}
1487+
1488+
for click_target in extend_free_point_targets(vector, transform) {
1489+
targets.push(click_target);
1490+
}
1491+
}
14831492

1484-
let single_anchors = vector.point_domain.ids().iter().filter_map(|&point_id| {
1493+
fn extend_free_point_targets(vector: &Vector, transform: DAffine2) -> impl Iterator<Item = ClickTarget> + '_ {
1494+
vector.point_domain.ids().iter().filter_map(move |&point_id| {
14851495
if vector.any_connected(point_id) {
14861496
return None;
14871497
}
@@ -1490,8 +1500,7 @@ fn extend_targets_from_vector(targets: &mut Vec<ClickTarget>, vector: &Vector, t
14901500
let mut click_target = ClickTarget::new_with_free_point(FreePoint::new(point_id, anchor));
14911501
click_target.apply_transform(transform);
14921502
Some(click_target)
1493-
});
1494-
targets.extend(single_anchors);
1503+
})
14951504
}
14961505

14971506
impl Render for Table<Raster<CPU>> {

0 commit comments

Comments
 (0)