mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-03 15:21:17 -05:00
UI: exclude protected dimensions from Outline Stroke eligibility
Use the same linked-dimension roots as the command lift operation without cloning the document. Exercise the real context menu for separate and grouped selections: fill-only sources have no action, stroked sources outline while dimension artwork survives.
This commit is contained in:
@@ -1143,21 +1143,29 @@ pub(crate) fn outlinable(st: &StrokeLayer) -> bool {
|
||||
st.visible && !st.paint.is_none() && st.width > 0.0
|
||||
}
|
||||
|
||||
/// Does Outline Stroke have a stroke to turn into art somewhere under `n`: a visible stroke of
|
||||
/// some paint and weight on a path or compound path (type is not outlined by it)?
|
||||
fn has_outlinable_stroke(n: &Node) -> bool {
|
||||
let mut found = false;
|
||||
each_leaf(n, &mut |l| {
|
||||
found |= !matches!(l.kind, NodeKind::Text(_)) && l.appearance.items.iter().any(|i| matches!(i, AppearanceItem::Stroke(st) if outlinable(st)));
|
||||
});
|
||||
found
|
||||
/// Does Outline Stroke have a stroke to turn into art under `n`, outside the dimension subtrees
|
||||
/// the command will keep? Guides, clipping paths and type are not outlined.
|
||||
fn has_outlinable_stroke(n: &Node, kept: &[NodeId]) -> bool {
|
||||
if kept.contains(&n.id) {
|
||||
return false;
|
||||
}
|
||||
match &n.kind {
|
||||
NodeKind::Path { guide: true, .. } | NodeKind::Path { clipping: true, .. } => false,
|
||||
NodeKind::Path { .. } | NodeKind::Compound { .. } => {
|
||||
n.appearance.items.iter().any(|i| matches!(i, AppearanceItem::Stroke(st) if outlinable(st)))
|
||||
}
|
||||
NodeKind::Group { children, .. } | NodeKind::Layer { children, .. } => children.iter().any(|c| has_outlinable_stroke(c, kept)),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Does `object.path.outlineStroke` have a stroke to outline in `st`'s selection? It acts on the
|
||||
/// selection's roots (a compound path's member stands for its compound, which holds the
|
||||
/// appearance), so eligibility looks at those same roots, not at the selected nodes themselves.
|
||||
/// appearance), excluding the linked dimensions that the command lifts while outlining their art.
|
||||
pub fn can_outline_stroke(st: &crate::DocState) -> bool {
|
||||
selection_roots(st).into_iter().filter_map(|id| st.doc.node(id)).any(has_outlinable_stroke)
|
||||
let roots = selection_roots(st);
|
||||
let kept = super::dimension::with_their_art(&st.doc, &roots);
|
||||
roots.into_iter().filter_map(|id| st.doc.node(id)).any(|n| has_outlinable_stroke(n, &kept))
|
||||
}
|
||||
|
||||
/// `n` with `opacity` and `blend` applied: set on it when it has none of its own, else on a
|
||||
|
||||
@@ -821,6 +821,45 @@ fn outline_stroke_is_offered_for_a_member_of_a_stroked_compound_path() {
|
||||
assert!(app.session.active().unwrap().doc.node(compound).is_none(), "the stroked compound path was replaced by its outline");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn outline_stroke_ignores_a_linked_dimensions_lines_when_its_source_is_selected() {
|
||||
for grouped in [false, true] {
|
||||
let mut app = app();
|
||||
let source = rect(&mut app, 50.0, 50.0);
|
||||
app.run("paint.setFill", json!({"color": "#ff8010"})).unwrap();
|
||||
app.run("paint.setStroke", json!({"none": true})).unwrap();
|
||||
let dimension = NodeId(
|
||||
app.run("dimension.create", json!({"source": {"kind": "segment", "edge": {"node": source.0, "subpath": 0, "segment": 0}}}))
|
||||
.unwrap()["id"]
|
||||
.as_u64()
|
||||
.unwrap(),
|
||||
);
|
||||
app.run("select.set", json!({"ids": [source.0, dimension.0]})).unwrap();
|
||||
if grouped {
|
||||
app.run("object.group", json!({})).unwrap();
|
||||
}
|
||||
let selected = app.session.active().unwrap().selection.objects.clone();
|
||||
let ctx = egui::Context::default();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
let p = screen(&app, 100.0, 125.0);
|
||||
let texts = click(&mut app, &ctx, p, PointerButton::Secondary);
|
||||
assert_eq!(app.session.active().unwrap().selection.objects, selected, "grouped: {grouped}");
|
||||
assert!(has(&texts, "Arrange"), "the menu opened: {texts:?}");
|
||||
assert!(!has(&texts, "Outline Stroke"), "only the protected dimension has strokes: {texts:?}");
|
||||
click(&mut app, &ctx, pos2(10.0, 590.0), PointerButton::Primary);
|
||||
|
||||
app.run("paint.setStroke", json!({"ids": [source.0], "color": "#000000"})).unwrap();
|
||||
app.run("stroke.set", json!({"ids": [source.0], "weight": 6})).unwrap();
|
||||
let dimension_art = app.session.active().unwrap().doc.node(dimension).unwrap().children().unwrap().to_vec();
|
||||
let texts = click(&mut app, &ctx, p, PointerButton::Secondary);
|
||||
assert!(has(&texts, "Outline Stroke"), "the source has a stroke to outline: {texts:?}");
|
||||
click(&mut app, &ctx, at(&texts, "Outline Stroke"), PointerButton::Primary);
|
||||
let st = app.session.active().unwrap();
|
||||
assert!(st.doc.node(source).is_none(), "the source was replaced by filled outlines");
|
||||
assert_eq!(st.doc.node(dimension).unwrap().children().unwrap(), dimension_art.as_slice(), "the dimension keeps its own art");
|
||||
}
|
||||
}
|
||||
|
||||
/// Point type holding `t` at (20, 60), with Auto Spell Check on.
|
||||
fn spelled(app: &mut VectorcraftApp, t: &str) -> NodeId {
|
||||
let id = NodeId(app.run("text.create", json!({"x": 20, "y": 60, "text": t, "size": 24})).unwrap()["id"].as_u64().unwrap());
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user