Properties: the Profile row stays while another selected stroke has a variable width

This commit is contained in:
dotCooCoo committed 2026-11-20 18:50:11 -08:00
1 parent 1759064a3e
commit f6593b16dc
4 files changed
+127 -8

No files matched your search

+31 -7
View File
@@ -497,6 +497,32 @@ impl Session {
/// and with a target that has no stroke row, since `stroke.set` gives such a target a plain
/// stroke.
pub fn brushed_strokes_profiled(&self) -> Option<bool> {
let st = self.active()?;
let strokes: Vec<&StrokeLayer> = self.edited_strokes(false)?.into_iter().map(|s| s.filter(|s| s.brush.is_some())).collect::<Option<_>>()?;
if strokes.is_empty() {
return None;
}
// The library is read only when every stroke names a brush.
let lib = vectorcraft_brush::library(&st.doc);
strokes.iter().all(|s| vectorcraft_brush::keeps_brush_size(&lib, s)).then(|| strokes.iter().any(|s| s.profile.is_some()))
}
/// Does any of the strokes that `stroke.set` edits without `ids` or `item` have a width
/// profile? The strokes are the ones [`Session::brushed_strokes_profiled`] reads, with or without
/// a brush. Type without an active Appearance row is left out, since `stroke.set` gives its
/// characters no profile. False with nothing selected, with an object inside a symbol instance
/// selected, and with a target that has no stroke row, which a profile from `stroke.set` would
/// give a plain stroke.
pub fn edited_strokes_profiled(&self) -> bool {
self.edited_strokes(true)
.and_then(|strokes| strokes.into_iter().collect::<Option<Vec<_>>>())
.is_some_and(|strokes| strokes.iter().any(|s| s.profile.is_some()))
}
/// The strokes that `stroke.set` edits without `ids` or `item`, one for each target, `None` for
/// a target without a stroke row (see [`Session::brushed_strokes_profiled`]). Type without an
/// active Appearance row is skipped with `skip_type`, and makes the result `None` without it.
fn edited_strokes(&self, skip_type: bool) -> Option<Vec<Option<&StrokeLayer>>> {
const C: &str = "stroke.set";
let st = self.active()?;
if st.selected_symbol_part().is_some() {
@@ -514,16 +540,14 @@ impl Session {
let n = st.doc.node(*id)?;
let row = each?.resolve(&n.appearance, false, C).ok()?;
if row.is_none() && matches!(n.kind, NodeKind::Text(_)) {
if skip_type {
continue;
}
return None;
}
strokes.push(n.appearance.stroke_at(row).filter(|s| s.brush.is_some())?);
strokes.push(n.appearance.stroke_at(row));
}
if strokes.is_empty() {
return None;
}
// The library is read only when every stroke names a brush.
let lib = vectorcraft_brush::library(&st.doc);
strokes.iter().all(|s| vectorcraft_brush::keeps_brush_size(&lib, s)).then(|| strokes.iter().any(|s| s.profile.is_some()))
Some(strokes)
}
}
+33
View File
@@ -253,6 +253,39 @@ fn brushed_strokes_profiled_reads_the_strokes_stroke_set_edits() {
assert_eq!(s.brushed_strokes_profiled(), None, "an object without a stroke row takes a plain stroke");
}
/// `edited_strokes_profiled` reads the same strokes, with or without a brush: one profiled member
/// counts, and a group's own uniform stroke, which `stroke.set` edits instead, hides its members'
/// profiles. With an object without a stroke row among the targets the answer is false, since a
/// profile from `stroke.set` would give that object a plain stroke. Type without an Appearance row
/// is left out.
#[test]
fn edited_strokes_profiled_reads_the_strokes_stroke_set_edits() {
let mut s = session();
let (a, b) = (rect(&mut s, 100.0), rect(&mut s, 250.0));
run(&mut s, "select.set", json!({"ids": [a.0, b.0]}));
assert!(!s.edited_strokes_profiled(), "neither has a profile");
run(&mut s, "stroke.set", json!({"ids": [b.0], "profile": "lens"}));
run(&mut s, "select.set", json!({"ids": [a.0, b.0]}));
assert!(s.edited_strokes_profiled(), "the second one has a profile");
let g = NodeId(run(&mut s, "object.group", json!({"ids": [a.0, b.0]}))["id"].as_u64().unwrap());
run(&mut s, "select.set", json!({"ids": [g.0]}));
assert!(s.edited_strokes_profiled(), "a group without its own stroke: its members'");
run(&mut s, "appearance.addStroke", json!({"ids": [g.0]}));
run(&mut s, "select.set", json!({"ids": [g.0]}));
assert!(!s.edited_strokes_profiled(), "the group's own uniform stroke");
let c = rect(&mut s, 400.0);
run(&mut s, "appearance.removeItem", json!({"ids": [c.0], "index": 1}));
run(&mut s, "select.set", json!({"ids": [b.0]}));
assert!(s.edited_strokes_profiled(), "the profiled member alone");
run(&mut s, "select.set", json!({"ids": [b.0, c.0]}));
assert!(!s.edited_strokes_profiled(), "an object without a stroke row");
let t = NodeId(run(&mut s, "text.create", json!({"x": 10, "y": 50, "text": "Hi"}))["id"].as_u64().unwrap());
run(&mut s, "select.set", json!({"ids": [t.0, b.0]}));
assert!(s.edited_strokes_profiled(), "type is left out");
run(&mut s, "select.set", json!({"ids": []}));
assert!(!s.edited_strokes_profiled(), "nothing selected");
}
/// A compound shape's own stroke is the one `stroke.set` edits: brushed members do not count.
#[test]
fn brushed_strokes_profiled_reads_a_compound_shapes_own_stroke() {
+23 -1
View File
@@ -999,13 +999,35 @@ fn effect_delete(app: &mut VectorcraftApp, ui: &mut Ui, id: vectorcraft_doc::Nod
}
}
/// Whether a stroke that `stroke.set` edits has a width profile
/// ([`vectorcraft_engine::Session::edited_strokes_profiled`]), cached per document revision and
/// active Appearance row. False while the Type tool edits text or the Live Paint Bucket is active,
/// when the list edits the stroke the panel shows.
fn edited_strokes_profiled(app: &VectorcraftApp, ctx: &egui::Context) -> bool {
if super::character::text_editing(app).is_some() || app.session.bucket_paints() {
return false;
}
let Some(st) = app.session.active() else { return false };
let key = (st.uid, st.revision, app.session.appearance_item());
match pstate::<Option<((u64, u64, Option<usize>), bool)>>(ctx, "props-edited-profiled") {
Some((k, v)) if k == key => v,
_ => {
let v = app.session.edited_strokes_profiled();
set_pstate(ctx, "props-edited-profiled", Some((key, v)));
v
}
}
}
/// The stroke's Variable Width Profile (the Control bar's list), shown while the Width tool is in
/// use or the stroke has a variable width, as the Properties panel overview places it
/// (<https://helpx.adobe.com/illustrator/desktop/get-started/learn-the-basics/properties-panel-overview.html>).
/// The row also shows when the shown stroke is uniform and another stroke the list edits has a
/// variable width ([`edited_strokes_profiled`]), so that Uniform can remove it.
fn width_profile_row(app: &mut VectorcraftApp, ui: &mut Ui) {
let stroke = super::current_stroke(app);
let profile = stroke.as_ref().and_then(|s| s.profile.as_ref());
if app.session.tool_id() != "width" && WidthProfile::id_of(profile) == "uniform" {
if app.session.tool_id() != "width" && WidthProfile::id_of(profile) == "uniform" && !edited_strokes_profiled(app, ui.ctx()) {
return;
}
ui.horizontal(|ui| {
@@ -1535,6 +1535,46 @@ fn the_width_profile_of_a_brushed_stroke_offers_only_uniform() {
assert_eq!(profile, None);
}
/// Two selected strokes, the shown one uniform and the other with a variable width: the Width
/// Profile row still shows, and its Uniform removes the other stroke's profile. With brushes on both
/// strokes the list holds only Uniform. Once both are uniform the row is hidden again.
#[test]
fn the_width_profile_shows_while_another_selected_stroke_has_a_variable_width() {
for brushed in [false, true] {
let mut app = new_app();
let a = app.run("shape.line", json!({"x1": 20, "y1": 100, "x2": 300, "y2": 100})).unwrap()["id"].clone();
let b = app.run("shape.line", json!({"x1": 20, "y1": 160, "x2": 300, "y2": 160})).unwrap()["id"].clone();
app.run("select.set", json!({"ids": [b]})).unwrap();
app.run("stroke.set", json!({"profile": "lens"})).unwrap();
if brushed {
app.run("brush.apply", json!({"ids": [a, b], "name": "3 pt. Round"})).unwrap();
}
app.run("select.set", json!({"ids": [a, b]})).unwrap();
assert_eq!(super::super::current_stroke(&app).and_then(|s| s.profile), None, "the shown stroke is uniform");
let ctx = egui::Context::default();
let texts = tall(&mut app, &ctx, vec![]);
assert!(shows(&texts, "Profile:"), "brushed {brushed}: {texts:?}");
let spacing = ctx.global_style().spacing.item_spacing.x;
let texts = press(&mut app, &ctx, text_at(&texts, "Profile:").right_center() + vec2(spacing + 50.0, 0.0));
assert_eq!(shows(&texts, "Taper Start"), !brushed, "{texts:?}");
press(&mut app, &ctx, text_at(&texts, "Uniform").center());
let profile = app
.session
.active()
.unwrap()
.doc
.node(vectorcraft_doc::NodeId(b.as_u64().unwrap()))
.unwrap()
.appearance
.stroke()
.unwrap()
.profile
.clone();
assert_eq!(profile, None, "brushed {brushed}");
assert!(!shows(&tall(&mut app, &ctx, vec![]), "Profile:"), "brushed {brushed}: every stroke is uniform");
}
}
/// With Direct Selection, a path whose corner is selected shows that corner's kind and radius;
/// each edit sets that corner alone in one undo step. Not with the Selection tool, nor with the
/// whole path selected; a live rectangle keeps its own Corner Radius row instead.