From 4d21ac66006a4b869f59431d651951a15f5514aa Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 17 Nov 2026 19:10:24 -0800 Subject: [PATCH 1/2] Width Point Edit: Side 1 and Side 2 apply to every selected width point Double-clicking one of several Shift-selected width points with the Width tool now keeps the selection and opens Width Point Edit for all of them; a double-click on an unselected point still edits that point alone. ui.widthPointEdit takes {id, indices} for the same dialog, and refuses an empty, malformed or out-of-range list, or indices given with index or t. Either half of a discontinuous point brings the other. Side 1, Side 2 and Total Width show a value only where every selected point has it, and are blank otherwise. A side width typed in sets that side of every point and keeps each point's other side (both sides with the link on); Total Width scales each point's own two sides. With a discontinuous point among them, Incoming and Outgoing edit its two halves and both edit the continuous points. OK sets them all with one stroke.widthProfile.set, one undo step, and nothing when no width changed; Delete removes them all. With Adjust Adjoining Width Points, each changed point changes the nearest unselected point before and after it in proportion to its change since the dialog opened. OK and Delete are refused when the points moved or changed since the dialog opened. Help page: https://helpx.adobe.com/illustrator/using/stroke-object.html describes Shift-clicking to select several width points and setting Side 1 and Side 2 for all of them in Width Point Edit. The blank fields, keeping each point's other side, per-point Total Width and the adjoining rule for several points are VectorCraft's own. --- crates/mcp/src/ui_catalog.rs | 2 +- crates/tools/src/distort/width.rs | 102 +++- crates/ui-egui/src/dialogs.rs | 7 +- crates/ui-egui/src/dialogs/width_point.rs | 436 +++++++++++++++++- .../ui-egui/src/dialogs/width_point/tests.rs | 312 +++++++++++++ crates/ui-egui/src/i18n/bg.tsv | 1 + crates/ui-egui/src/i18n/bs.tsv | 1 + crates/ui-egui/src/i18n/ca.tsv | 1 + crates/ui-egui/src/i18n/cs.tsv | 1 + crates/ui-egui/src/i18n/da.tsv | 1 + crates/ui-egui/src/i18n/de.tsv | 1 + crates/ui-egui/src/i18n/el.tsv | 1 + crates/ui-egui/src/i18n/es.tsv | 1 + crates/ui-egui/src/i18n/fi.tsv | 1 + crates/ui-egui/src/i18n/fr.tsv | 1 + crates/ui-egui/src/i18n/hi.tsv | 1 + crates/ui-egui/src/i18n/hu.tsv | 1 + crates/ui-egui/src/i18n/id.tsv | 1 + crates/ui-egui/src/i18n/it.tsv | 1 + crates/ui-egui/src/i18n/ja.tsv | 1 + crates/ui-egui/src/i18n/ka.tsv | 1 + crates/ui-egui/src/i18n/ko.tsv | 1 + crates/ui-egui/src/i18n/nl.tsv | 1 + crates/ui-egui/src/i18n/pl.tsv | 1 + crates/ui-egui/src/i18n/pt-br.tsv | 1 + crates/ui-egui/src/i18n/ru.tsv | 1 + crates/ui-egui/src/i18n/sv.tsv | 1 + crates/ui-egui/src/i18n/tr.tsv | 1 + crates/ui-egui/src/i18n/uk.tsv | 1 + crates/ui-egui/src/i18n/vi.tsv | 1 + crates/ui-egui/src/i18n/zh-hans.tsv | 1 + crates/ui-egui/src/i18n/zh-hant.tsv | 1 + crates/ui-egui/src/menus/ui_commands.rs | 2 +- docs/control-protocol.md | 13 + docs/mcp.md | 7 + docs/target-app-parity.md | 1 + 36 files changed, 895 insertions(+), 14 deletions(-) diff --git a/crates/mcp/src/ui_catalog.rs b/crates/mcp/src/ui_catalog.rs index b6da21331e..2853a9189c 100644 --- a/crates/mcp/src/ui_catalog.rs +++ b/crates/mcp/src/ui_catalog.rs @@ -1306,7 +1306,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.widthPointEdit", "Width Point Edit…", "", - "{id, index?: existing width point, t?: 0..1 for a new point, adjustAdjoining?: bool (false)} open Width Point Edit on path `id` (dialog `widthPoint`: side1, side2 (pt), linked, adjustAdjoining; double-clicking the stroke opens it too, Shift on a width point enabling adjoining adjustment): OK runs stroke.widthPoint.set; discard: true (Delete) removes an existing point or discards a prospective point", + "{id, index?: existing width point, indices?: [i…] several existing width points, t?: 0..1 for a new point (give only one of index, indices and t), adjustAdjoining?: bool (false)} open Width Point Edit on path `id` (dialog `widthPoint`: side1, side2 (pt), linked, adjustAdjoining; for several points also totalWidth, and side1, side2 and totalWidth are null where the points differ; double-clicking the stroke opens it too, on one of several Shift-selected width points for all of them, Shift on a width point enabling adjoining adjustment): OK runs stroke.widthPoint.set, for several points one stroke.widthProfile.set (none when nothing changed); discard: true (Delete) removes the existing points or discards a prospective point", ), ( "ui.corners", diff --git a/crates/tools/src/distort/width.rs b/crates/tools/src/distort/width.rs index 4ebbac4981..3de5f416f6 100644 --- a/crates/tools/src/distort/width.rs +++ b/crates/tools/src/distort/width.rs @@ -7,8 +7,9 @@ //! either onto another width point makes a discontinuous point (the width steps there). Shift-click //! adds width points to the selection (or takes them out), and dragging one of several selected //! points moves or widens them all. Double-clicking a stroke opens Width Point Edit (the -//! `widthPoint` dialog), editing a hit point or creating one on confirmation. Delete/Backspace -//! removes the selected width points. +//! `widthPoint` dialog), editing a hit point or creating one on confirmation; on one of several +//! selected points it edits all of them (`indices`). Delete/Backspace removes the selected width +//! points. //! //! Gestures preview `stroke.widthPoint.set {id, t, left, right, index?}` (side widths in points), //! `stroke.widthPoint.copy {id, index, t}` or, for several points, `stroke.widthProfile.set {ids, @@ -107,6 +108,9 @@ pub struct WidthTool { selected: Option<(NodeId, Vec)>, /// The selected width points when the button went down: a dropped press puts them back. before_press: Option<(NodeId, Vec)>, + /// The width points selected before a click on one of them selected just that one, and + /// whether the button has gone down again since: a double-click on that point edits them all. + before_click: Option<((NodeId, Vec), bool)>, } /// The object whose stroke path `id` draws with: its compound path, if it is a member of one. @@ -302,16 +306,40 @@ impl Tool for WidthTool { } PointerKind::TripleClick => vec![], PointerKind::DoubleClick => { + // The double-click's first click selected just the point under it: the points + // selected before it are selected again. + let before_click = self.before_click.take().and_then(|(sel, pressed)| pressed.then_some(sel)); let Some(spot) = Self::spot_at(cx, p) else { return vec![] }; let Some((w, _)) = Self::hit(cx, &spot, p) else { self.selected = Some((spot.owner, vec![spot.t])); return vec![Action::Dialog("widthPoint".into(), json!({"id": spot.owner.0, "t": spot.t}))]; }; - self.selected = Some((spot.owner, vec![w.t])); - vec![Action::Dialog("widthPoint".into(), json!({"id": spot.owner.0, "index": w.index, "adjustAdjoining": ev.mods.shift}))] + if let Some((owner, ts)) = before_click + && owner == spot.owner + && self.is_selected(owner, w.t) + && ts.iter().any(|t| (t - w.t).abs() <= SAME_T) + { + self.selected = Some((owner, ts)); + } + // A selected point edits every selected point; another one edits itself alone. + if !self.is_selected(spot.owner, w.t) { + self.selected = Some((spot.owner, vec![w.t])); + } + let indices = self.selected_indices(cx, spot.owner); + let profile = stroke_of(cx.doc, spot.owner).and_then(|s| s.profile.as_ref()); + let several = profile.is_some_and(|pr| indices.iter().any(|i| (pr.points[*i].0 - w.t).abs() > SAME_T)); + let mut params = json!({"id": spot.owner.0, "adjustAdjoining": ev.mods.shift}); + if several { + params["indices"] = json!(indices); + } else { + params["index"] = json!(w.index); + } + vec![Action::Dialog("widthPoint".into(), params)] } PointerKind::Down => { self.before_press = self.selected.clone(); + // Only the press right after the click counts as the double-click's second one. + self.before_click = self.before_click.take().filter(|(_, pressed)| !pressed).map(|(sel, _)| (sel, true)); let Some(spot) = Self::spot_at(cx, p) else { if !ev.mods.shift { self.selected = None; @@ -385,7 +413,14 @@ impl Tool for WidthTool { let dt = d.t - d.spot.t; self.selected = match (d.group.is_some(), d.moved, self.selected.take()) { // A click on one of several selected points selects just that one. - (true, false, _) if !ev.mods.shift => Some((d.spot.owner, vec![d.spot.t])), + (true, false, sel) if !ev.mods.shift => { + // Only a selection of several places: a discontinuous point alone also + // drags as a group, and its click must not replace the remembered one. + if let Some(sel) = sel.filter(|(_, ts)| ts.len() > 1) { + self.before_click = Some((sel, false)); + } + Some((d.spot.owner, vec![d.spot.t])) + } // Points moved together stay selected. (true, _, Some((id, ts))) if d.mode == Mode::Move => Some((id, ts.into_iter().map(|t| (t + dt).clamp(0.0, 1.0)).collect())), (true, _, sel) => sel, @@ -796,4 +831,61 @@ mod tests { assert!(t.pointer(&c, &ev(PointerKind::DoubleClick, 120.0, 250.0, mods)).is_empty(), "not on a stroked path"); } } + + #[test] + fn double_click_on_one_of_several_selected_points_edits_them_all() { + let (d, id) = doc_three_points(); + let (s, p) = (Selection::default(), paint()); + let c = cx(&d, &s, &p); + let (none, shift) = (Mods::default(), Mods { shift: true, ..Default::default() }); + let click = |t: &mut WidthTool, x: f64, mods: Mods| { + t.pointer(&c, &ev(PointerKind::Down, x, 200.0, mods)); + t.pointer(&c, &ev(PointerKind::Up, x, 200.0, mods)); + }; + // The events a double-click sends: two clicks, then the double-click. + let double_click = |t: &mut WidthTool, x: f64, mods: Mods| { + click(t, x, mods); + click(t, x, mods); + match t.pointer(&c, &ev(PointerKind::DoubleClick, x, 200.0, mods)).as_slice() { + [Action::Dialog(kind, v)] if kind == "widthPoint" => v.clone(), + acts => panic!("expected Width Point Edit: {acts:?}"), + } + }; + for mods in [none, shift] { + let mut t = WidthTool::default(); + click(&mut t, 150.0, none); + click(&mut t, 250.0, shift); + let v = double_click(&mut t, 250.0, mods); + assert_eq!((&v["id"], &v["indices"]), (&json!(id.0), &json!([1, 3])), "{mods:?}"); + assert!(v.get("index").is_none()); + assert_eq!(v["adjustAdjoining"], json!(mods.shift)); + assert_eq!(t.selected_indices(&c, id), vec![1, 3], "the selection is kept"); + // A point outside the selection edits itself alone, and is selected alone. + let v = double_click(&mut t, 200.0, none); + assert_eq!(v["index"], json!(2)); + assert!(v.get("indices").is_none()); + assert_eq!(t.selected_indices(&c, id), vec![2]); + } + // A discontinuous point among them keeps both halves, and double-clicking it keeps the others. + let (mut d2, _) = doc_line(); + let points = vec![(0.0, 1.0, 1.0), (0.25, 1.0, 1.0), (0.5, 1.0, 1.0), (0.5, 2.0, 2.0), (0.75, 1.0, 1.0), (1.0, 1.0, 1.0)]; + d2.node_mut(id).unwrap().appearance.stroke_mut().unwrap().profile = Some(WidthProfile { points }); + let c2 = cx(&d2, &s, &p); + let mut t = WidthTool::default(); + for (x, mods) in [(150.0, none), (200.0, shift), (200.0, none), (200.0, none)] { + t.pointer(&c2, &ev(PointerKind::Down, x, 200.0, mods)); + t.pointer(&c2, &ev(PointerKind::Up, x, 200.0, mods)); + } + let acts = t.pointer(&c2, &ev(PointerKind::DoubleClick, 200.0, 200.0, none)); + let [Action::Dialog(_, v)] = acts.as_slice() else { panic!("expected Width Point Edit: {acts:?}") }; + assert_eq!(v["indices"], json!([1, 2, 3])); + // A click on one of the selected points, then a double-click on it later, edits that point. + let mut t = WidthTool::default(); + click(&mut t, 150.0, none); + click(&mut t, 250.0, shift); + click(&mut t, 250.0, none); + click(&mut t, 200.0, none); + let v = double_click(&mut t, 250.0, none); + assert_eq!(v["index"], json!(3)); + } } diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index 9e54eb12f6..fad4dfac9b 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -597,7 +597,8 @@ pub fn accepts_field(d: &Dialog, field: &str) -> bool { /// Options setting set this way for several rows is sent to every row (Template also sets Lock /// and Dim Images, as its checkbox does). A DXF Options preset set this way sets its fields, as /// one picked from its menu does, and the preset it shows follows the DXF options set this way. -/// A Graph Data Column Width set this way sets every column, as Cell Style's does. +/// A Graph Data Column Width set this way sets every column, as Cell Style's does. A Width Point +/// Edit side width set this way for several points sets it on every point, as typing it does. pub fn set_field(d: &mut Dialog, field: String, value: Value) { if d.kind == brush_options::KIND { brush_art_options::note_set(d, &field); @@ -616,6 +617,7 @@ pub fn set_field(d: &mut Dialog, field: String, value: Value) { } let dxf = (d.kind == dxf_options::KIND).then(|| field.clone()); let graph = (d.kind == graph_data::KIND).then(|| field.clone()); + let width = (d.kind == width_point::KIND).then(|| field.clone()); d.fields.insert(field, value); if let Some(field) = dxf { dxf_options::note_set(d, &field); @@ -623,6 +625,9 @@ pub fn set_field(d: &mut Dialog, field: String, value: Value) { if let Some(field) = graph { graph_data::note_set(d, &field); } + if let Some(field) = width { + width_point::note_set(d, &field); + } } /// The fields `ui.dialog.set` can set on `d`, sorted: those it holds other than its `__` ones, the diff --git a/crates/ui-egui/src/dialogs/width_point.rs b/crates/ui-egui/src/dialogs/width_point.rs index b0881b9082..4acf0d2d3b 100644 --- a/crates/ui-egui/src/dialogs/width_point.rs +++ b/crates/ui-egui/src/dialogs/width_point.rs @@ -16,10 +16,24 @@ //! `linked`, `adjustAdjoining`; for a discontinuous point also `outIndex`, `outSide1`, `outSide2`, //! `outLinked` (the outgoing half) and `single` (`""`, `"incoming"` or `"outgoing"`); Delete sets //! `discard: true` and confirms. +//! +//! Opened on several selected width points (`indices`), the dialog edits all of them. Side 1, +//! Side 2 and Total Width show a value only where every point has it, and are blank otherwise. A +//! side width typed in sets that side of every point (both sides with the link on) and leaves the +//! other side of each point as it was; Total Width scales each point's own two sides to that total. +//! Turning the link on changes no width. When the points include a discontinuous one, Incoming +//! edits the incoming halves and Outgoing the outgoing halves, and both edit the continuous points. +//! With Adjust Adjoining Width Points, each changed point changes the nearest unselected point +//! before and after it in proportion, measured from the widths the points had when the dialog +//! opened. OK sets them all in one `stroke.widthProfile.set` (one undo step, none when nothing +//! changed), and Delete removes them all. The fields are `id`, `indices` (every selected profile +//! entry, both halves of a discontinuous point), `side1`, `side2`, `totalWidth` (null when the +//! points differ), `linked`, `adjustAdjoining`, and with a discontinuous point `outSide1`, +//! `outSide2`, `outTotalWidth` and `outLinked`. use egui::vec2; use serde_json::{Value, json}; -use vectorcraft_doc::Unit; +use vectorcraft_doc::{Unit, WidthProfile}; use vectorcraft_engine::doc::NodeId; use vectorcraft_engine::width_point_pair; @@ -31,6 +45,25 @@ use crate::{VectorcraftApp, widgets}; /// The dialog kind of Width Point Edit. pub const KIND: &str = "widthPoint"; +/// Width points closer than this (in t) are at the same place, as the engine counts them. +const SAME_T: f64 = 1e-6; + +/// Side widths (points) closer than this show as one value. +const SAME_WIDTH: f64 = 1e-6; + +/// The working side widths of several points being edited. +const POINTS: &str = "__points"; +/// Their side widths when the dialog opened. +const OPEN: &str = "__open"; +/// Whether they include a discontinuous point (two sets of side widths shown). +const DISCONTINUOUS: &str = "__discontinuous"; + +/// The fields of each set of side widths of several points: Side 1, Side 2, Total Width and the +/// link, for the incoming set and the outgoing set. +const MANY: [[&str; 4]; 2] = [["side1", "side2", "totalWidth", "linked"], ["outSide1", "outSide2", "outTotalWidth", "outLinked"]]; +/// The number fields that show them. +const MANY_IDS: [[&str; 3]; 2] = [["wp-side1", "wp-side2", "wp-total"], ["wp-out-side1", "wp-out-side2", "wp-out-total"]]; + pub(super) const SPEC: DialogSpec = DialogSpec { heading: |_| tl!("Width Point Edit").into(), body, confirm, discard: Some("Delete"), min_width: 300.0, ..DialogSpec::FORM }; @@ -51,18 +84,256 @@ fn halves(app: &VectorcraftApp, id: u64, index: usize) -> Option<(usize, usize)> pair(index).or_else(|| index.checked_sub(1).and_then(pair)) } +/// One of several width points being edited: its profile index, its place, its side widths +/// (points) and the sets of side widths that edit it, `[incoming, outgoing]` (both for a continuous +/// point). +#[derive(Clone, Copy, Debug, PartialEq)] +struct Entry { + index: usize, + t: f64, + left: f64, + right: f64, + sets: [bool; 2], +} + +/// The entries held in field `key`. +fn entries(d: &Dialog, key: &str) -> Vec { + let entry = |e: &Value| { + let e = e.as_array()?; + let index = usize::try_from(e.first()?.as_u64()?).ok()?; + let (t, left, right) = (e.get(1)?.as_f64()?, e.get(2)?.as_f64()?, e.get(3)?.as_f64()?); + Some(Entry { index, t, left, right, sets: [e.get(4)?.as_bool()?, e.get(5)?.as_bool()?] }) + }; + d.fields.get(key).and_then(Value::as_array).map_or_else(Vec::new, |a| a.iter().filter_map(entry).collect()) +} + +fn entries_json(es: &[Entry]) -> Value { + json!(es.iter().map(|e| json!([e.index, e.t, e.left, e.right, e.sets[0], e.sets[1]])).collect::>()) +} + +/// What set `set` of `es` shows: Side 1, Side 2 and Total Width, each none where the points differ. +fn shown(es: &[Entry], set: usize) -> [Option; 3] { + let common = |f: fn(&Entry) -> f64| { + let mut values = es.iter().filter(|e| e.sets[set]).map(f); + let first = values.next()?; + values.all(|v| (v - first).abs() <= SAME_WIDTH).then_some(first) + }; + [common(|e| e.left), common(|e| e.right), common(|e| e.left + e.right)] +} + +/// Keep `es` as the working widths of `d`, and show them in its fields. +fn store(d: &mut Dialog, es: &[Entry]) { + d.fields.insert(POINTS.into(), entries_json(es)); + let sets = if d.bool(DISCONTINUOUS) { 2 } else { 1 }; + for (set, keys) in MANY.iter().enumerate().take(sets) { + for (key, value) in keys.iter().zip(shown(es, set)) { + d.fields.insert((*key).into(), json!(value)); + } + } +} + +/// A change typed into one set of side widths of several points. +#[derive(Clone, Copy, Debug)] +enum Edit { + Side1(f64), + Side2(f64), + Total(f64), +} + +/// Apply `edit` to every point that set `set` edits: a side width replaces that side (both sides +/// with `linked`), and Total Width scales each point's two sides to it (equal halves from nothing). +fn apply(es: &mut [Entry], set: usize, edit: Edit, linked: bool) { + for e in es.iter_mut().filter(|e| e.sets[set]) { + let (l, r) = match edit { + Edit::Side1(v) => (v, if linked { v } else { e.right }), + Edit::Side2(v) => (if linked { v } else { e.left }, v), + Edit::Total(v) => { + let sum = e.left + e.right; + if sum > 1e-9 { (e.left / sum * v, e.right / sum * v) } else { (v / 2.0, v / 2.0) } + } + }; + (e.left, e.right) = (l.max(0.0), r.max(0.0)); + } +} + +/// The number in field `key` (none when it is null or absent). +fn number(d: &Dialog, key: &str) -> Result, String> { + let v = match d.fields.get(key) { + None | Some(Value::Null) => return Ok(None), + Some(Value::Number(n)) => n.as_f64(), + Some(Value::String(s)) => Unit::Points.parse(s), + Some(_) => None, + }; + match v { + Some(v) if v.is_finite() && (0.0..=1.0e5).contains(&v) => Ok(Some(v)), + _ => Err("invalid stroke widths".into()), + } +} + +/// The widths OK sets on several points: the working widths, with any value set straight into a +/// field (`ui.dialog.set`) that they do not show yet applied as typing it would, Total Width before +/// the sides. +fn edited(d: &Dialog) -> Result, String> { + let mut es = entries(d, POINTS); + let sets = if d.bool(DISCONTINUOUS) { 2 } else { 1 }; + let before: Vec<_> = (0..sets).map(|set| shown(&es, set)).collect(); + for (set, shown) in before.iter().enumerate() { + let [k1, k2, kt, kl] = MANY[set]; + for (key, at) in [(kt, 2), (k1, 0), (k2, 1)] { + let Some(v) = number(d, key)? else { continue }; + if shown[at].is_some_and(|s| (s - v).abs() <= SAME_WIDTH) { + continue; + } + let edit = match at { + 0 => Edit::Side1(v), + 1 => Edit::Side2(v), + _ => Edit::Total(v), + }; + apply(&mut es, set, edit, d.bool(kl)); + } + } + Ok(es) +} + +/// After `ui.dialog.set` sets `field` of several points' dialog: a side width or Total Width applies +/// as typing it does, so a value equal to the one shown still sets that side of every point (both +/// sides with the link on). A null or unreadable value is left for OK to skip or refuse. +pub(super) fn note_set(d: &mut Dialog, field: &str) { + if !d.fields.contains_key(OPEN) { + return; + } + let sets = if d.bool(DISCONTINUOUS) { 2 } else { 1 }; + for (set, keys) in MANY.iter().enumerate().take(sets) { + let Some(at) = keys[..3].iter().position(|k| *k == field) else { continue }; + let Ok(Some(v)) = number(d, field) else { return }; + let edit = match at { + 0 => Edit::Side1(v), + 1 => Edit::Side2(v), + _ => Edit::Total(v), + }; + let mut es = entries(d, POINTS); + apply(&mut es, set, edit, d.bool(keys[3])); + store(d, &es); + return; + } +} + +/// Width `v` of a point next to one whose width changes from `o` to `n`: in proportion, or by as +/// much from nothing, as `stroke.widthPoint.set` changes adjoining points. +fn scale(v: f64, o: f64, n: f64) -> f64 { + let width = if o > 1e-9 { + let product = v * n; + if product.is_finite() { product / o } else { (v.max(n) / o) * v.min(n) } + } else { + v + n - o + }; + width.max(0.0) +} + +/// What the width points `indices` (a JSON array) of `id` name. +enum Target { + /// One point, or the two halves of one discontinuous point: its first profile index. + One(usize), + /// Several places: every profile entry, in order. + Several(Vec), +} + +/// The outgoing half that pairs with each width point, as [`width_point_pair`] pairs them: point +/// `a` and the next one are the two halves of a discontinuous point when they are the only points +/// within [`SAME_T`] of `a`'s place. Each point counts the points at its place in the sorted +/// places, stopping at three. +fn pairs(points: &[(f64, f64, f64)]) -> Vec> { + let mut ts: Vec = points.iter().map(|q| q.0).filter(|t| !t.is_nan()).collect(); + ts.sort_by(f64::total_cmp); + let near = |a: usize, b: usize| (points[b].0 - points[a].0).abs() <= SAME_T; + (0..points.len()) + .map(|a| { + if a + 1 >= points.len() || !near(a, a + 1) || (a > 0 && near(a, a - 1)) { + return None; + } + let t = points[a].0; + let from = ts.partition_point(|&s| s < t - 2.0 * SAME_T); + let at = ts[from..].iter().take_while(|&&s| s <= t + 2.0 * SAME_T).filter(|&&s| (s - t).abs() <= SAME_T).take(3).count(); + (at == 2).then_some(a + 1) + }) + .collect() +} + +/// The width points `indices` of `id` names, each discontinuous point's two halves together. +fn target(app: &VectorcraftApp, id: u64, indices: &Value) -> Result { + const NONE: &str = "no such width point"; + let st = app.session.active().and_then(|s| s.doc.node(NodeId(id))).and_then(|n| n.appearance.stroke()).ok_or(NONE)?; + let points = st.profile.as_ref().map_or(&[][..], |p| &p.points[..]); + let list = indices.as_array().filter(|a| !a.is_empty()).ok_or(NONE)?; + let mut picked = list + .iter() + .map(|v| v.as_u64().and_then(|i| usize::try_from(i).ok()).filter(|i| *i < points.len())) + .collect::>>() + .ok_or(NONE)?; + picked.sort_unstable(); + picked.dedup(); + // The other half of each discontinuous point, paired as `stroke.widthPoint.set` pairs them. + let pairs = pairs(points); + let outgoing = |i: usize| i.checked_sub(1).is_some_and(|a| pairs[a] == Some(i)); + let halves: Vec = picked.iter().flat_map(|&i| [pairs[i], i.checked_sub(1).filter(|_| outgoing(i))]).flatten().collect(); + picked.extend(halves); + picked.sort_unstable(); + picked.dedup(); + // One point, or the two halves of one discontinuous point. + if picked.len() == 1 || (picked.len() == 2 && pairs[picked[0]] == Some(picked[1])) { + return Ok(Target::One(picked[0])); + } + if !(st.width.is_finite() && st.width > 0.0) { + return Err("object has no weighted stroke".into()); + } + let half = st.width / 2.0; + let entry = |i: usize| { + let (t, l, r) = points[i]; + Entry { index: i, t, left: l * half, right: r * half, sets: [!outgoing(i), pairs[i].is_none()] } + }; + Ok(Target::Several(picked.into_iter().map(entry).collect())) +} + +/// Open Width Point Edit on the several width points `es` of `id`. +fn open_several(app: &mut VectorcraftApp, id: u64, es: &[Entry], adjust: bool) { + let discontinuous = es.iter().any(|e| e.sets != [true, true]); + let indices: Vec = es.iter().map(|e| e.index).collect(); + let mut d = + Dialog::new(KIND, json!({"id": id, "indices": indices, "adjustAdjoining": adjust, DISCONTINUOUS: discontinuous, OPEN: entries_json(es)})); + for (set, keys) in MANY.iter().enumerate().take(if discontinuous { 2 } else { 1 }) { + let linked = es.iter().filter(|e| e.sets[set]).all(|e| (e.left - e.right).abs() < 1e-9); + d.fields.insert(keys[3].into(), json!(linked)); + } + store(&mut d, es); + app.ui.dialog = Some(d); +} + /// Open Width Point Edit for `index`, or a prospective point at fraction `t` without an index -/// (`{id, index?, t?, adjustAdjoining?}`). Opening only samples the stroke: confirmation creates -/// the point. Adjoining adjustment defaults to false. Either half of a discontinuous point opens -/// both. +/// (`{id, index?, t?, adjustAdjoining?}`), or for several existing points (`{id, indices, +/// adjustAdjoining?}`). Opening only samples the stroke: confirmation creates the point. +/// Adjoining adjustment defaults to false. Either half of a discontinuous point opens both. pub fn open(app: &mut VectorcraftApp, p: &Value) -> Result { let id = p.get("id").and_then(Value::as_u64).ok_or("give the path `id`")?; let doc = &app.session.active().ok_or("no document")?.doc; let id = vectorcraft_tools::distort::stroke_owner(doc, NodeId(id)).0; - let index = match p.get("index").filter(|v| !v.is_null()) { + let given = |key: &str| p.get(key).is_some_and(|v| !v.is_null()); + let mut index = match p.get("index").filter(|v| !v.is_null()) { Some(v) => Some(v.as_u64().and_then(|i| usize::try_from(i).ok()).ok_or("no such width point")?), None => None, }; + if let Some(indices) = p.get("indices").filter(|v| !v.is_null()) { + if given("index") || given("t") { + return Err("give only one of `index`, `indices` and `t`".into()); + } + match target(app, id, indices)? { + Target::One(i) => index = Some(i), + Target::Several(es) => { + let adjust = p.get("adjustAdjoining").and_then(Value::as_bool).unwrap_or(false); + open_several(app, id, &es, adjust); + return Ok(Value::Null); + } + } + } let pair = index.and_then(|i| halves(app, id, i)); let index = pair.map_or(index, |(a, _)| Some(a)); let (t, l, r) = if let Some(index) = index { @@ -143,10 +414,58 @@ fn sides(ui: &mut egui::Ui, d: &mut Dialog, unit: Unit, keys: [&str; 3], ids: [& } } +/// Set `set` of the side widths of several points: Side 1 with its link, Side 2 and Total Width, +/// blank where the points differ. A value typed in changes every point the set edits; the link only +/// changes how later values apply. +fn sides_of_several(ui: &mut egui::Ui, d: &mut Dialog, unit: Unit, set: usize) { + let [k1, k2, kt, kl] = MANY[set]; + let ids = MANY_IDS[set]; + let value = |key: &str| number(d, key).ok().flatten(); + let (s1, s2, total, linked) = (value(k1), value(k2), value(kt), d.bool(kl)); + let mut edit = None; + grid(ui, |ui| { + label(ui, tl!("Side 1:")); + ui.horizontal(|ui| { + if let Some(v) = widgets::num_field(ui, ids[0], s1, unit, 90.0) { + edit = Some(Edit::Side1(v)); + } + if widgets::icon_button(ui, if linked { "link" } else { "link-2-off" }, tl!("Keep both sides the same width"), linked, 22.0).clicked() { + d.fields.insert(kl.into(), json!(!linked)); + } + }); + ui.end_row(); + label(ui, tl!("Side 2:")); + if let Some(v) = widgets::num_field(ui, ids[1], s2, unit, 90.0) { + edit = Some(Edit::Side2(v)); + } + ui.end_row(); + label(ui, tl!("Total Width:")); + if let Some(v) = widgets::num_field(ui, ids[2], total, unit, 90.0) { + edit = Some(Edit::Total(v)); + } + ui.end_row(); + }); + if let Some(edit) = edit { + // Values set straight into the fields count first, so typing does not lose them. + let mut es = edited(d).unwrap_or_else(|_| entries(d, POINTS)); + apply(&mut es, set, edit, linked); + store(d, &es); + } +} + fn body(app: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) -> bool { let unit = app.session.stroke_unit(); let incoming = (["side1", "side2", "linked"], ["wp-side1", "wp-side2", "wp-total"]); - if paired(d) { + if d.fields.contains_key(OPEN) { + if d.bool(DISCONTINUOUS) { + widgets::section_header(ui, tl!("Incoming")); + ui.push_id("wp-incoming", |ui| sides_of_several(ui, d, unit, 0)); + widgets::section_header(ui, tl!("Outgoing")); + ui.push_id("wp-outgoing", |ui| sides_of_several(ui, d, unit, 1)); + } else { + sides_of_several(ui, d, unit, 0); + } + } else if paired(d) { widgets::section_header(ui, tl!("Incoming")); ui.push_id("wp-incoming", |ui| sides(ui, d, unit, incoming.0, incoming.1)); widgets::section_header(ui, tl!("Outgoing")); @@ -172,7 +491,112 @@ fn body(app: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) -> bool { false } +/// `id`'s width profile and the stroke's half weight, when the points `open` are still where and as +/// wide as when the dialog opened. +fn opened_profile(app: &VectorcraftApp, id: u64, open: &[Entry]) -> Result<(WidthProfile, f64), String> { + const NONE: &str = "no such width point"; + let st = app.session.active().and_then(|s| s.doc.node(NodeId(id))).and_then(|n| n.appearance.stroke()).ok_or(NONE)?; + let half = st.width / 2.0; + if !(half.is_finite() && half > 0.0) { + return Err("object has no weighted stroke".into()); + } + let profile = st.profile.clone().ok_or(NONE)?; + if open.is_empty() || !open.windows(2).all(|w| w[0].index < w[1].index) { + return Err(NONE.into()); + } + for o in open { + let &(t, l, r) = profile.points.get(o.index).ok_or(NONE)?; + if (t - o.t).abs() > SAME_T || (l * half - o.left).abs() > SAME_WIDTH || (r * half - o.right).abs() > SAME_WIDTH { + return Err(NONE.into()); + } + } + Ok((profile, half)) +} + +/// `id`'s width profile, as width factors `[t, left, right]`, with the selected points `open` set to +/// `new` (side widths in points). With `adjust`, each changed point also changes the nearest +/// unselected point at another place before it (unless it is the outgoing half of a discontinuous +/// point) and after it (unless it is the incoming half) in proportion. Every change is measured +/// from the widths when the dialog opened, and a point next to two changed points takes both +/// changes, in path order. +fn edited_profile(app: &VectorcraftApp, id: u64, open: &[Entry], new: &[Entry], adjust: bool) -> Result, String> { + let (WidthProfile { points: old }, half) = opened_profile(app, id, open)?; + if open.len() != new.len() || open.iter().zip(new).any(|(o, e)| o.index != e.index) { + return Err("no such width point".into()); + } + let mut points = old.clone(); + let selected = |j: usize| open.binary_search_by_key(&j, |o| o.index).is_ok(); + // The nearest unselected point before and after each point. + let (mut prev, mut next) = (vec![None; old.len()], vec![None; old.len()]); + let mut last = None; + for (j, p) in prev.iter_mut().enumerate() { + *p = last; + if !selected(j) { + last = Some(j); + } + } + last = None; + for (j, n) in next.iter_mut().enumerate().rev() { + *n = last; + if !selected(j) { + last = Some(j); + } + } + for (o, e) in open.iter().zip(new).filter(|_| adjust) { + if o.left == e.left && o.right == e.right { + continue; + } + // The point's place; both halves of a discontinuous point measure from the incoming half's. + let t = old[if o.sets[0] { o.index } else { o.index.saturating_sub(1) }].0; + // The nearest unselected point farther than SAME_T from that place on one side. + let nearest = |side: &[Option]| { + let mut j = side[o.index]; + while let Some(k) = j + && (old[k].0 - t).abs() <= SAME_T + { + j = side[k]; + } + j + }; + let before = nearest(&prev).filter(|_| o.sets[0]); + let after = nearest(&next).filter(|_| o.sets[1]); + for j in before.into_iter().chain(after) { + let q = &mut points[j]; + (q.1, q.2) = (scale(q.1, o.left / half, e.left / half), scale(q.2, o.right / half, e.right / half)); + } + } + for e in new { + (points[e.index].1, points[e.index].2) = (e.left / half, e.right / half); + } + if points.iter().any(|q| !q.1.is_finite() || !q.2.is_finite()) { + return Err("invalid stroke widths".into()); + } + Ok(points.into_iter().map(|(t, l, r)| [t, l, r]).collect()) +} + +/// OK or Delete on several width points. +fn confirm_several(app: &mut VectorcraftApp, d: &Dialog) -> Result { + let id = d.fields.get("id").and_then(Value::as_u64).ok_or("no such width point")?; + let open = entries(d, OPEN); + if d.bool("discard") { + opened_profile(app, id, &open)?; + let indices: Vec = open.iter().map(|e| e.index).collect(); + return run_and_close(app, "stroke.widthPoint.remove", json!({"id": id, "indices": indices})); + } + let new = edited(d)?; + if open.len() == new.len() && open.iter().zip(&new).all(|(o, e)| o.index == e.index && o.left == e.left && o.right == e.right) { + // Nothing changed: no command and no undo step. + app.ui.dialog = None; + return Ok(Value::Null); + } + let points = edited_profile(app, id, &open, &new, d.bool("adjustAdjoining"))?; + run_and_close(app, "stroke.widthProfile.set", json!({"ids": [id], "points": points})) +} + fn confirm(app: &mut VectorcraftApp, d: &Dialog) -> Result { + if d.fields.contains_key(OPEN) { + return confirm_several(app, d); + } let (id, index) = (d.fields.get("id").cloned().unwrap_or_default(), d.fields.get("index").cloned().unwrap_or_default()); let out = d.fields.get("outIndex").filter(|_| paired(d)).cloned(); if d.bool("discard") { diff --git a/crates/ui-egui/src/dialogs/width_point/tests.rs b/crates/ui-egui/src/dialogs/width_point/tests.rs index bf32a6124f..d939cb5a6c 100644 --- a/crates/ui-egui/src/dialogs/width_point/tests.rs +++ b/crates/ui-egui/src/dialogs/width_point/tests.rs @@ -573,3 +573,315 @@ fn a_compound_member_edits_both_halves_of_its_owners_point() { // halved) halves the end's Side 2. assert_eq!(points(&app, owner), vec![(0.0, 2.0, 1.0), (0.5, 1.6, 0.8), (0.5, 0.4, 0.6), (1.0, 1.0, 0.5)]); } + +/// [`app`]'s line with width points at a quarter (4 + 2 pt), the middle (4 + 4 pt) and three +/// quarters (2 + 6 pt). +fn three_app() -> (VectorcraftApp, u64) { + let (mut app, id) = app(); + let points = json!([[0, 1, 1], [0.25, 0.8, 0.4], [0.5, 0.8, 0.8], [0.75, 0.4, 1.2], [1, 1, 1]]); + app.run("stroke.widthProfile.set", json!({"ids": [id], "points": points})).unwrap(); + app.session.doc_mut().unwrap().mark_saved(); + (app, id) +} + +/// Open Width Point Edit on the points at a quarter and three quarters, set `fields` and press OK. +fn ok_on_two(fields: &[(&str, Value)]) -> (VectorcraftApp, u64) { + let (mut app, id) = three_app(); + app.run("ui.widthPointEdit", json!({"id": id, "indices": [3, 1, 3]})).unwrap(); + let d = app.ui.dialog.as_mut().unwrap(); + for (key, value) in fields { + d.fields.insert((*key).into(), value.clone()); + } + super::super::confirm(&mut app).unwrap(); + assert!(app.ui.dialog.is_none()); + (app, id) +} + +#[test] +fn several_points_show_blank_fields_where_they_differ() { + let (mut app, id) = three_app(); + app.run("ui.widthPointEdit", json!({"id": id, "indices": [3, 1, 3]})).unwrap(); + let d = app.ui.dialog.as_ref().unwrap(); + assert_eq!(d.fields["indices"], json!([1, 3])); + for key in ["side1", "side2", "totalWidth"] { + assert!(d.fields[key].is_null(), "{key}: {:?}", d.fields[key]); + } + assert!(!d.bool("linked")); + assert!(d.fields.get("outSide1").is_none()); + let shown = frame(&mut app); + for s in ["Side 1:", "Side 2:", "Total Width:", "Adjust Adjoining Width Points", "Delete"] { + assert_eq!(shown.iter().filter(|t| *t == s).count(), 1, "{s} in {shown:?}"); + } + // Points with the same widths show them. + app.run("ui.widthPointEdit", json!({"id": id, "indices": [1, 2]})).unwrap(); + let d = app.ui.dialog.as_ref().unwrap(); + assert_eq!((d.fields["side1"].clone(), d.fields["side2"].clone(), d.fields["totalWidth"].clone()), (json!(4.0), Value::Null, Value::Null)); +} + +#[test] +fn a_side_width_sets_that_side_of_every_selected_point() { + let (app, id) = ok_on_two(&[("side1", json!(5))]); + assert_eq!(points(&app, id), vec![(0.0, 1.0, 1.0), (0.25, 1.0, 0.4), (0.5, 0.8, 0.8), (0.75, 1.0, 1.2), (1.0, 1.0, 1.0)]); + let (app, id) = ok_on_two(&[("side2", json!("3 pt"))]); + assert_eq!(points(&app, id), vec![(0.0, 1.0, 1.0), (0.25, 0.8, 0.6), (0.5, 0.8, 0.8), (0.75, 0.4, 0.6), (1.0, 1.0, 1.0)]); + // With the link on, a side width sets both sides. + let (app, id) = ok_on_two(&[("linked", json!(true)), ("side1", json!(3))]); + assert_eq!(points(&app, id), vec![(0.0, 1.0, 1.0), (0.25, 0.6, 0.6), (0.5, 0.8, 0.8), (0.75, 0.6, 0.6), (1.0, 1.0, 1.0)]); + // Total Width scales each point's own two sides. + let (app, id) = ok_on_two(&[("totalWidth", json!(12))]); + assert_eq!(points(&app, id), vec![(0.0, 1.0, 1.0), (0.25, 1.6, 0.8), (0.5, 0.8, 0.8), (0.75, 0.6, 1.8), (1.0, 1.0, 1.0)]); +} + +#[test] +fn ok_on_several_points_is_one_undo_step() { + let (mut app, id) = three_app(); + app.run("shape.rectangle", json!({"x": 20, "y": 20, "width": 20, "height": 20})).unwrap(); + app.run("edit.undo", json!({})).unwrap(); + let before = app.session.doc().unwrap().doc.clone(); + let history = creation_history(&app); + // Cancel, and OK with nothing changed, change nothing and keep redo. + for ok in [false, true] { + app.run("ui.widthPointEdit", json!({"id": id, "indices": [1, 3]})).unwrap(); + if ok { + super::super::confirm(&mut app).unwrap(); + } else { + app.ui.dialog.as_mut().unwrap().fields.insert("side1".into(), json!(9)); + super::super::cancel(&mut app); + } + assert!(app.ui.dialog.is_none()); + assert_eq!(app.session.doc().unwrap().doc, before); + assert_eq!(creation_history(&app), history); + } + app.run("ui.widthPointEdit", json!({"id": id, "indices": [1, 3]})).unwrap(); + app.ui.dialog.as_mut().unwrap().fields.insert("side1".into(), json!(5)); + super::super::confirm(&mut app).unwrap(); + assert_eq!(creation_history(&app), (history.0 + 1, 0, true)); + let after = app.session.doc().unwrap().doc.clone(); + app.run("edit.undo", json!({})).unwrap(); + assert_eq!(app.session.doc().unwrap().doc, before); + app.run("edit.redo", json!({})).unwrap(); + assert_eq!(app.session.doc().unwrap().doc, after); +} + +#[test] +fn a_side_width_set_by_control_applies_even_when_it_is_the_value_shown() { + // Side 1 is 4 pt at both points; with the link on, setting it to 4 pt sets Side 2 to 4 pt too. + let (mut app, id) = three_app(); + app.run("ui.widthPointEdit", json!({"id": id, "indices": [1, 2]})).unwrap(); + let d = app.ui.dialog.as_mut().unwrap(); + super::super::set_field(d, "linked".into(), json!(true)); + super::super::set_field(d, "side1".into(), json!(4)); + assert_eq!((d.fields["side1"].clone(), d.fields["side2"].clone()), (json!(4.0), json!(4.0))); + super::super::confirm(&mut app).unwrap(); + assert_eq!(points(&app, id), vec![(0.0, 1.0, 1.0), (0.25, 0.8, 0.8), (0.5, 0.8, 0.8), (0.75, 0.4, 1.2), (1.0, 1.0, 1.0)]); +} + +#[test] +fn adjoining_points_follow_every_changed_point_once() { + // Side 1 doubles at a quarter and quadruples at three quarters: the start doubles, the end + // quadruples and the middle, next to both, takes both. + let (app, id) = ok_on_two(&[("adjustAdjoining", json!(true)), ("side1", json!(8))]); + assert_eq!(points(&app, id), vec![(0.0, 2.0, 1.0), (0.25, 1.6, 0.4), (0.5, 6.4, 0.8), (0.75, 1.6, 1.2), (1.0, 4.0, 1.0)]); +} + +#[test] +fn delete_removes_every_selected_point() { + let (mut app, id) = three_app(); + let before = app.session.doc().unwrap().doc.clone(); + let history = creation_history(&app); + app.run("ui.widthPointEdit", json!({"id": id, "indices": [1, 3]})).unwrap(); + app.ui.dialog.as_mut().unwrap().fields.insert("discard".into(), json!(true)); + super::super::confirm(&mut app).unwrap(); + assert_eq!(points(&app, id), vec![(0.0, 1.0, 1.0), (0.5, 0.8, 0.8), (1.0, 1.0, 1.0)]); + assert_eq!(creation_history(&app).0, history.0 + 1); + app.run("edit.undo", json!({})).unwrap(); + assert_eq!(app.session.doc().unwrap().doc, before); +} + +#[test] +fn several_points_with_a_discontinuous_one_edit_each_set() { + let (mut app, id) = app(); + let profile = json!([[0, 1, 1], [0.25, 0.8, 0.4], [0.5, 0.8, 0.8], [0.5, 0.4, 1.2], [1, 1, 1]]); + app.run("stroke.widthProfile.set", json!({"ids": [id], "points": profile})).unwrap(); + // One half of the discontinuous point brings the other. + app.run("ui.widthPointEdit", json!({"id": id, "indices": [1, 2]})).unwrap(); + let d = app.ui.dialog.as_ref().unwrap(); + assert_eq!(d.fields["indices"], json!([1, 2, 3])); + // Incoming: the quarter (4 + 2) and the incoming half (4 + 4); outgoing: the quarter and the + // outgoing half (2 + 6). + assert_eq!((d.fields["side1"].clone(), d.fields["side2"].clone()), (json!(4.0), Value::Null)); + assert_eq!((d.fields["outSide1"].clone(), d.fields["outSide2"].clone()), (Value::Null, Value::Null)); + let shown = frame(&mut app); + for s in ["Incoming", "Outgoing"] { + assert!(shown.iter().any(|t| t == s), "{s} in {shown:?}"); + } + assert_eq!(shown.iter().filter(|t| *t == "Side 1:").count(), 2); + app.ui.dialog.as_mut().unwrap().fields.insert("outSide2".into(), json!(5)); + super::super::confirm(&mut app).unwrap(); + assert_eq!(points(&app, id), vec![(0.0, 1.0, 1.0), (0.25, 0.8, 1.0), (0.5, 0.8, 0.8), (0.5, 0.4, 1.0), (1.0, 1.0, 1.0)]); +} + +/// Three width points each within 1e-6 of the next, but the outer two farther apart: with several +/// points selected, the first two are the halves of one discontinuous point and the third is a +/// continuous point, as `stroke.widthPoint.set` pairs them. +#[test] +fn several_points_in_a_chain_pair_as_the_engine_pairs_them() { + let (mut app, id) = app(); + let chain = json!([[0, 1, 1], [0.5, 0.8, 0.8], [0.50000075, 0.4, 1.2], [0.5000015, 0.6, 0.6], [1, 1, 1]]); + app.run("stroke.widthProfile.set", json!({"ids": [id], "points": chain})).unwrap(); + app.run("ui.widthPointEdit", json!({"id": id, "indices": [2, 3]})).unwrap(); + let d = app.ui.dialog.as_mut().unwrap(); + assert_eq!(d.fields["indices"], json!([1, 2, 3])); + d.fields.insert("side1".into(), json!(5)); + d.fields.insert("outSide2".into(), json!(5)); + super::super::confirm(&mut app).unwrap(); + assert!(app.ui.dialog.is_none()); + // Incoming: the incoming half and the continuous point, both linked; outgoing: the outgoing + // half and the continuous point. + assert_eq!(points(&app, id), vec![(0.0, 1.0, 1.0), (0.5, 1.0, 1.0), (0.50000075, 0.4, 1.0), (0.5000015, 1.0, 1.0), (1.0, 1.0, 1.0)]); +} + +/// Three width points within 1e-6 of one another are no discontinuous point: selected together, +/// the dialog edits all three, and a discontinuous point alone still opens the one-point dialog. +#[test] +fn several_points_at_nearly_one_place_edit_them_all() { + let (mut app, id) = app(); + let profile = json!([[0, 1, 1], [0.5, 0.8, 0.8], [0.5000005, 0.4, 0.4], [0.5000009, 0.6, 0.6], [1, 1, 1]]); + app.run("stroke.widthProfile.set", json!({"ids": [id], "points": profile})).unwrap(); + app.run("ui.widthPointEdit", json!({"id": id, "indices": [1, 2, 3]})).unwrap(); + let d = app.ui.dialog.as_mut().unwrap(); + assert_eq!(d.fields["indices"], json!([1, 2, 3])); + d.fields.insert("linked".into(), json!(false)); + d.fields.insert("side2".into(), json!(5)); + super::super::confirm(&mut app).unwrap(); + assert!(app.ui.dialog.is_none()); + assert_eq!(points(&app, id), vec![(0.0, 1.0, 1.0), (0.5, 0.8, 1.0), (0.5000005, 0.4, 1.0), (0.5000009, 0.6, 1.0), (1.0, 1.0, 1.0)]); + let (mut app, id) = pair_app(); + let pair = app.session.active().unwrap().doc.node(NodeId(id)).unwrap().appearance.stroke().unwrap().profile.clone().unwrap(); + let a = (0..pair.points.len()).find(|&a| width_point_pair(&pair.points, a).is_some()).unwrap(); + app.run("ui.widthPointEdit", json!({"id": id, "indices": [a + 1, a]})).unwrap(); + let d = app.ui.dialog.as_ref().unwrap(); + assert_eq!((d.fields["index"].clone(), d.fields["outIndex"].clone()), (json!(a), json!(a + 1))); +} + +/// With Adjust Adjoining Width Points, the outgoing half of a discontinuous point measures its +/// neighbors from the point's place, as `stroke.widthPoint.set` does: a point within 1e-6 of the +/// outgoing half but not of the place is the point after the pair. +#[test] +fn several_points_adjust_the_point_after_a_pair_from_its_place() { + let (mut app, id) = app(); + let profile = json!([[0, 1, 1], [0.25, 0.8, 0.8], [0.5, 0.8, 0.8], [0.5000009, 0.4, 0.4], [0.5000018, 0.6, 0.6], [1, 1, 1]]); + app.run("stroke.widthProfile.set", json!({"ids": [id], "points": profile})).unwrap(); + app.run("ui.widthPointEdit", json!({"id": id, "indices": [1, 3], "adjustAdjoining": true})).unwrap(); + let d = app.ui.dialog.as_mut().unwrap(); + assert_eq!(d.fields["indices"], json!([1, 2, 3])); + d.fields.insert("outSide1".into(), json!(4)); + super::super::confirm(&mut app).unwrap(); + assert!(app.ui.dialog.is_none()); + // The outgoing set is linked, so both sides of the outgoing half double, and so do both sides + // of the point after the pair; the end keeps its widths. + assert_eq!( + points(&app, id), + vec![(0.0, 1.0, 1.0), (0.25, 0.8, 0.8), (0.5, 0.8, 0.8), (0.5000009, 0.8, 0.8), (0.5000018, 1.2, 1.2), (1.0, 1.0, 1.0)] + ); +} + +#[test] +fn pairs_match_the_engine() { + let profiles: [&[(f64, f64, f64)]; 5] = [ + &[], + &[(0.5, 1.0, 1.0)], + &[(0.0, 1.0, 1.0), (0.5, 1.0, 1.0), (0.5, 1.0, 1.0), (1.0, 1.0, 1.0)], + &[(0.0, 1.0, 1.0), (0.5, 1.0, 1.0), (0.5, 1.0, 1.0), (0.5, 1.0, 1.0), (1.0, 1.0, 1.0)], + &[ + (0.5, 1.0, 1.0), + (0.50000075, 1.0, 1.0), + (0.5000015, 1.0, 1.0), + (0.5000024, 1.0, 1.0), + (f64::NAN, 1.0, 1.0), + (0.7, 1.0, 1.0), + (0.7, 1.0, 1.0), + ], + ]; + for points in profiles { + let engine: Vec> = (0..points.len()).map(|a| width_point_pair(points, a)).collect(); + assert_eq!(pairs(points), engine, "{points:?}"); + } +} + +#[test] +fn double_clicking_one_of_several_selected_points_and_typing_edits_them_all() { + let (mut app, id) = three_app(); + let view = app.view_info(); + app.select_tool("width"); + let send = |app: &mut VectorcraftApp, kind: PointerKind, x: f64, shift: bool| { + let mut ev = PointerEvent::new(kind, x, 150.0); + ev.mods.shift = shift; + crate::canvas::dispatch(app, &ev, view); + }; + for (x, shift) in [(150.0, false), (250.0, true)] { + send(&mut app, PointerKind::Down, x, shift); + send(&mut app, PointerKind::Up, x, shift); + } + for kind in [PointerKind::Down, PointerKind::Up, PointerKind::Down, PointerKind::Up, PointerKind::DoubleClick] { + send(&mut app, kind, 150.0, false); + } + assert_eq!(app.ui.dialog.as_ref().expect("Width Point Edit opened").fields["indices"], json!([1, 3])); + let ctx = egui::Context::default(); + crate::theme::install_fonts(&ctx); + crate::theme::apply(&ctx, Default::default()); + for _ in 0..5 { + creation_dialog_frame(&mut app, &ctx, vec![]); + } + // The blank Side 1 has the focus: typing sets Side 1 of both points. + creation_dialog_frame(&mut app, &ctx, vec![egui::Event::Text("5 pt".into())]); + creation_dialog_click(&mut app, &ctx, "OK"); + assert!(app.ui.dialog.is_none()); + assert_eq!(points(&app, id), vec![(0.0, 1.0, 1.0), (0.25, 1.0, 0.4), (0.5, 0.8, 0.8), (0.75, 1.0, 1.2), (1.0, 1.0, 1.0)]); +} + +#[test] +fn several_points_refuse_bad_indices() { + let (mut app, id) = three_app(); + let before = app.session.doc().unwrap().doc.clone(); + let history = creation_history(&app); + for p in [ + json!({"id": id, "indices": []}), + json!({"id": id, "indices": [1, -1]}), + json!({"id": id, "indices": [1, 1.5]}), + json!({"id": id, "indices": [1, "3"]}), + json!({"id": id, "indices": [1, 99]}), + json!({"id": id, "indices": 1}), + json!({"id": id, "indices": [1, 3], "index": 1}), + json!({"id": id, "indices": [1, 3], "t": 0.5}), + ] { + assert!(app.run("ui.widthPointEdit", p.clone()).is_err(), "{p}"); + assert!(app.ui.dialog.is_none(), "{p}"); + assert_eq!(app.session.doc().unwrap().doc, before); + assert_eq!(creation_history(&app), history); + } + // A point moved since the dialog opened is refused at OK, even with its widths unchanged. + app.run("ui.widthPointEdit", json!({"id": id, "indices": [1, 3]})).unwrap(); + app.run("stroke.widthPoint.set", json!({"id": id, "index": 1, "t": 0.3, "left": 4, "right": 2})).unwrap(); + let moved = app.session.doc().unwrap().doc.clone(); + app.ui.dialog.as_mut().unwrap().fields.insert("side1".into(), json!(5)); + assert!(super::super::confirm(&mut app).is_err()); + assert_eq!(app.session.doc().unwrap().doc, moved); + app.run("edit.undo", json!({})).unwrap(); + // So is Delete after a point was added before them. + app.run("ui.widthPointEdit", json!({"id": id, "indices": [1, 3]})).unwrap(); + app.run("stroke.widthPoint.set", json!({"id": id, "t": 0.1, "left": 5, "right": 5})).unwrap(); + let added = app.session.doc().unwrap().doc.clone(); + app.ui.dialog.as_mut().unwrap().fields.insert("discard".into(), json!(true)); + assert!(super::super::confirm(&mut app).is_err()); + assert_eq!(app.session.doc().unwrap().doc, added); + app.run("edit.undo", json!({})).unwrap(); + // A value that is not a width is refused at OK, and the dialog stays open. + app.run("ui.widthPointEdit", json!({"id": id, "indices": [1, 3]})).unwrap(); + for bad in [json!(-1), json!("wide"), json!(1.0e6)] { + app.ui.dialog.as_mut().unwrap().fields.insert("side1".into(), bad.clone()); + assert!(super::super::confirm(&mut app).is_err(), "{bad}"); + assert!(app.ui.dialog.is_some()); + assert_eq!(app.session.doc().unwrap().doc, before); + } +} diff --git a/crates/ui-egui/src/i18n/bg.tsv b/crates/ui-egui/src/i18n/bg.tsv index c4c9b173fc..f6c6375071 100644 --- a/crates/ui-egui/src/i18n/bg.tsv +++ b/crates/ui-egui/src/i18n/bg.tsv @@ -5059,6 +5059,7 @@ axis Both И двете @msg onto must name a panel floating in another group onto трябва да указва панел, плаващ в друга група @msg below and above must name a panel floating in another group below и above трябва да указват панел, плаващ в друга група @msg give only one of onto, below and above задайте само едно от onto, below и above +@msg give only one of `index`, `indices` and `t` задайте само едно от `index`, `indices` и `t` @msg column must be true or a number from 1 column трябва да е true или число от 1 нататък @msg x and y must both be numbers x и y трябва да са числа @msg "{0}" is not a colour: write it as #rrggbb "{0}" не е цвят: запишете го като #rrggbb diff --git a/crates/ui-egui/src/i18n/bs.tsv b/crates/ui-egui/src/i18n/bs.tsv index 35a6849e94..85f71c13ac 100644 --- a/crates/ui-egui/src/i18n/bs.tsv +++ b/crates/ui-egui/src/i18n/bs.tsv @@ -5478,6 +5478,7 @@ imageTrace Outline Obris @msg onto must name a panel floating in another group onto mora navesti panel koji pluta u drugoj grupi @msg below and above must name a panel floating in another group below i above moraju navesti panel koji pluta u drugoj grupi @msg give only one of onto, below and above navedite samo jedno od onto, below i above +@msg give only one of `index`, `indices` and `t` navedite samo jedno od `index`, `indices` i `t` @msg column must be true or a number from 1 column mora biti true ili broj od 1 @msg x and y must both be numbers x i y moraju oba biti brojevi @msg "{0}" is not a colour: write it as #rrggbb "{0}" nije boja: napišite je kao #rrggbb diff --git a/crates/ui-egui/src/i18n/ca.tsv b/crates/ui-egui/src/i18n/ca.tsv index e1657921f4..7eb27d2d79 100644 --- a/crates/ui-egui/src/i18n/ca.tsv +++ b/crates/ui-egui/src/i18n/ca.tsv @@ -6015,6 +6015,7 @@ liquify-list-end {0}, {1} {0} i {1} @msg give corners of the path: anchors where its sides meet at an angle doneu les cantonades del traçat: punts d’ancoratge on els seus costats es troben en angle @msg give horizontal or vertical doneu horitzontal o vertical @msg give only one of onto, below and above doneu només un de onto, below i above +@msg give only one of `index`, `indices` and `t` doneu només un de `index`, `indices` i `t` @msg give the path `id` doneu l’`id` del traçat @msg give the path `id` and the width point `index` doneu el `id` del traçat i l’`index` del punt d’amplada @msg Global Edit works on paths, compound paths, symbol instances and groups of them L’edició global funciona amb traçats, traçats compostos, instàncies de símbol i grups d’aquests objectes diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsv index d1f49616cf..b3b729425f 100644 --- a/crates/ui-egui/src/i18n/cs.tsv +++ b/crates/ui-egui/src/i18n/cs.tsv @@ -5776,6 +5776,7 @@ liquify-list-end {0}, {1} {0} a {1} @msg onto must name a panel floating in another group onto musí určovat panel plovoucí v jiné skupině @msg below and above must name a panel floating in another group below a above musí určovat panel plovoucí v jiné skupině @msg give only one of onto, below and above zadejte jen jedno z onto, below a above +@msg give only one of `index`, `indices` and `t` zadejte jen jedno z `index`, `indices` a `t` @msg column must be true or a number from 1 column musí být true nebo číslo od 1 @msg x and y must both be numbers x i y musí být čísla @msg "{0}" is not a colour: write it as #rrggbb „{0}“ není barva: zapište ji jako #rrggbb diff --git a/crates/ui-egui/src/i18n/da.tsv b/crates/ui-egui/src/i18n/da.tsv index 7be089384e..1107d4dfe7 100644 --- a/crates/ui-egui/src/i18n/da.tsv +++ b/crates/ui-egui/src/i18n/da.tsv @@ -7905,6 +7905,7 @@ imageTrace Outline Kontur @msg onto must name a panel floating in another group onto skal angive et panel, der flyder i en anden gruppe @msg below and above must name a panel floating in another group below og above skal angive et panel, der flyder i en anden gruppe @msg give only one of onto, below and above angiv kun én af onto, below og above +@msg give only one of `index`, `indices` and `t` angiv kun én af `index`, `indices` og `t` @msg column must be true or a number from 1 column skal være true eller et tal fra 1 @msg x and y must both be numbers x og y skal begge være tal @msg "{0}" is not a colour: write it as #rrggbb "{0}" er ikke en farve: skriv den som #rrggbb diff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsv index 518c312c5b..6efee09eac 100644 --- a/crates/ui-egui/src/i18n/de.tsv +++ b/crates/ui-egui/src/i18n/de.tsv @@ -5379,6 +5379,7 @@ liquify-list-end {0}, {1} {0} und {1} @msg onto must name a panel floating in another group onto muss ein Bedienfeld nennen, das in einer anderen Gruppe schwebt @msg below and above must name a panel floating in another group below und above müssen ein Bedienfeld nennen, das in einer anderen Gruppe schwebt @msg give only one of onto, below and above nur eines von onto, below und above angeben +@msg give only one of `index`, `indices` and `t` nur eines von `index`, `indices` und `t` angeben @msg column must be true or a number from 1 column muss true oder eine Zahl ab 1 sein @msg x and y must both be numbers x und y müssen beide Zahlen sein @msg "{0}" is not a colour: write it as #rrggbb "{0}" ist keine Farbe: Schreiben Sie sie als #rrggbb diff --git a/crates/ui-egui/src/i18n/el.tsv b/crates/ui-egui/src/i18n/el.tsv index 32480d4f66..3bb5eceeb4 100644 --- a/crates/ui-egui/src/i18n/el.tsv +++ b/crates/ui-egui/src/i18n/el.tsv @@ -5431,6 +5431,7 @@ digits Malayalam Μαλαγιάλαμ @msg onto must name a panel floating in another group το onto πρέπει να ορίζει πίνακα που αιωρείται σε άλλη ομάδα @msg below and above must name a panel floating in another group τα below και above πρέπει να ορίζουν πίνακα που αιωρείται σε άλλη ομάδα @msg give only one of onto, below and above δώστε μόνο ένα από τα onto, below και above +@msg give only one of `index`, `indices` and `t` δώστε μόνο ένα από τα `index`, `indices` και `t` @msg column must be true or a number from 1 το column πρέπει να είναι true ή αριθμός από 1 και πάνω @msg x and y must both be numbers τα x και y πρέπει να είναι αριθμοί @msg "{0}" is not a colour: write it as #rrggbb το "{0}" δεν είναι χρώμα: γράψτε το ως #rrggbb diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsv index cc8eb4d0d5..4312873e09 100644 --- a/crates/ui-egui/src/i18n/es.tsv +++ b/crates/ui-egui/src/i18n/es.tsv @@ -5484,6 +5484,7 @@ liquify-list-end {0}, {1} {0}, {1} @msg onto must name a panel floating in another group onto debe nombrar un panel que flote en otro grupo @msg below and above must name a panel floating in another group below y above deben nombrar un panel que flote en otro grupo @msg give only one of onto, below and above indica solo uno de onto, below y above +@msg give only one of `index`, `indices` and `t` indica solo uno de `index`, `indices` y `t` @msg column must be true or a number from 1 column debe ser true o un número desde 1 @msg x and y must both be numbers x e y deben ser números @msg "{0}" is not a colour: write it as #rrggbb "{0}" no es un color: escríbelo como #rrggbb diff --git a/crates/ui-egui/src/i18n/fi.tsv b/crates/ui-egui/src/i18n/fi.tsv index 42996a4107..edc89ca20a 100644 --- a/crates/ui-egui/src/i18n/fi.tsv +++ b/crates/ui-egui/src/i18n/fi.tsv @@ -5700,6 +5700,7 @@ liquify-list-end {0}, {1} {0} ja {1} @msg onto must name a panel floating in another group onto-arvon on nimettävä toisessa ryhmässä kelluva paneeli @msg below and above must name a panel floating in another group below- ja above-arvojen on nimettävä toisessa ryhmässä kelluva paneeli @msg give only one of onto, below and above anna vain yksi arvoista onto, below ja above +@msg give only one of `index`, `indices` and `t` anna vain yksi arvoista `index`, `indices` ja `t` @msg column must be true or a number from 1 column-arvon on oltava true tai luku 1:stä alkaen @msg x and y must both be numbers x:n ja y:n on molempien oltava lukuja @msg "{0}" is not a colour: write it as #rrggbb "{0}" ei ole väri: kirjoita se muodossa #rrggbb diff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsv index 96b007cbe5..81d00d3c24 100644 --- a/crates/ui-egui/src/i18n/fr.tsv +++ b/crates/ui-egui/src/i18n/fr.tsv @@ -5442,6 +5442,7 @@ liquify-list-end {0}, {1} {0} et {1} @msg onto must name a panel floating in another group onto doit désigner un panneau flottant dans un autre groupe @msg below and above must name a panel floating in another group below et above doivent désigner un panneau flottant dans un autre groupe @msg give only one of onto, below and above indiquez un seul de onto, below et above +@msg give only one of `index`, `indices` and `t` indiquez un seul de `index`, `indices` et `t` @msg column must be true or a number from 1 column doit être true ou un nombre à partir de 1 @msg x and y must both be numbers x et y doivent tous deux être des nombres @msg "{0}" is not a colour: write it as #rrggbb « {0} » n’est pas une couleur : écrivez-la sous la forme #rrggbb diff --git a/crates/ui-egui/src/i18n/hi.tsv b/crates/ui-egui/src/i18n/hi.tsv index 1d66fd3f60..0b1364a7c7 100644 --- a/crates/ui-egui/src/i18n/hi.tsv +++ b/crates/ui-egui/src/i18n/hi.tsv @@ -7305,6 +7305,7 @@ liquify-list-end {0}, {1} {0} और {1} @msg give one of assets, layers, selection or fullDocument assets, layers, selection या fullDocument में से एक दें @msg give only one of onto, above, below, icon and a column place केवल ऊपर, नीचे, आइकन और एक स्तंभ स्थान देने के लिए @msg give only one of onto, below and above नीचे और ऊपर केवल एक देना +@msg give only one of `index`, `indices` and `t` `index`, `indices` और `t` में से केवल एक दें @msg give origin: [x, y], or reset: true origin: [x, y] दें, या reset: true @msg give overprintFill, overprintStroke, showCenter, imageMap, url or note overprintFill, overprintStroke, showCenter, imageMap, url या नोट @msg give path (a file) or folder पाथ (एक फ़ाइल) या फ़ोल्डर देना diff --git a/crates/ui-egui/src/i18n/hu.tsv b/crates/ui-egui/src/i18n/hu.tsv index bfaf6595a4..9231679642 100644 --- a/crates/ui-egui/src/i18n/hu.tsv +++ b/crates/ui-egui/src/i18n/hu.tsv @@ -5583,6 +5583,7 @@ liquify-list-end {0}, {1} {0} és {1} @msg give corners of the path: anchors where its sides meet at an angle add meg az útvonal sarkait: azokat a horgonypontokat, ahol az oldalai szögben találkoznak @msg give horizontal or vertical add meg a horizontal vagy a vertical értéket @msg give only one of onto, below and above az onto, below és above közül csak egyet adj meg +@msg give only one of `index`, `indices` and `t` az `index`, `indices` és `t` közül csak egyet adj meg @msg give the path `id` and the width point `index` add meg az útvonal `id` és a szélességi pont `index` értékét @msg gradient “{name}” isn't defined in the file: a plain colour stands in for it a színátmenet nincs megadva a fájlban: „{name}”; helyette egyszínű kitöltés áll @msg group must be true or false a group értéke true vagy false lehet diff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsv index ab7574d1b4..e6aac2ea6e 100644 --- a/crates/ui-egui/src/i18n/id.tsv +++ b/crates/ui-egui/src/i18n/id.tsv @@ -5149,6 +5149,7 @@ imageTrace Outline Kontur @msg onto must name a panel floating in another group onto harus menyebutkan panel yang mengambang di grup lain @msg below and above must name a panel floating in another group below dan above harus menyebutkan panel yang mengambang di grup lain @msg give only one of onto, below and above berikan hanya satu dari onto, below, dan above +@msg give only one of `index`, `indices` and `t` berikan hanya satu dari `index`, `indices`, dan `t` @msg column must be true or a number from 1 column harus true atau angka mulai dari 1 @msg x and y must both be numbers x dan y harus keduanya angka @msg "{0}" is not a colour: write it as #rrggbb "{0}" bukan warna: tulis sebagai #rrggbb diff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsv index e027397aa1..7a9e50e005 100644 --- a/crates/ui-egui/src/i18n/it.tsv +++ b/crates/ui-egui/src/i18n/it.tsv @@ -5512,6 +5512,7 @@ liquify-list-end {0}, {1} {0} e {1} @msg onto must name a panel floating in another group onto deve indicare un pannello mobile in un altro gruppo @msg below and above must name a panel floating in another group below e above devono indicare un pannello mobile in un altro gruppo @msg give only one of onto, below and above indica solo uno tra onto, below e above +@msg give only one of `index`, `indices` and `t` indica solo uno tra `index`, `indices` e `t` @msg column must be true or a number from 1 column deve essere true o un numero da 1 @msg x and y must both be numbers x e y devono essere entrambi numeri @msg "{0}" is not a colour: write it as #rrggbb "{0}" non è un colore: scrivilo come #rrggbb diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsv index edfb3f603d..ea42ad1623 100644 --- a/crates/ui-egui/src/i18n/ja.tsv +++ b/crates/ui-egui/src/i18n/ja.tsv @@ -5273,6 +5273,7 @@ swatch Bright Violet ビビッドバイオレット @msg onto must name a panel floating in another group onto には、別のグループでフローティングしているパネルを指定してください @msg below and above must name a panel floating in another group below と above には別のグループでフローティングしているパネルを指定してください @msg give only one of onto, below and above onto、below、above のうち 1 つだけを指定してください +@msg give only one of `index`, `indices` and `t` `index`、`indices`、`t` のうち 1 つだけを指定してください @msg column must be true or a number from 1 column には true または 1 以上の数値を指定してください @msg unknown panel `{raw}` `{raw}` は不明なパネルです @msg `{panel}` has no display sizes to cycle `{panel}` には切り替える表示サイズがありません diff --git a/crates/ui-egui/src/i18n/ka.tsv b/crates/ui-egui/src/i18n/ka.tsv index 6113bfc54c..34808a6747 100644 --- a/crates/ui-egui/src/i18n/ka.tsv +++ b/crates/ui-egui/src/i18n/ka.tsv @@ -7256,6 +7256,7 @@ font-technology Variable ცვლადი @msg onto must name a panel floating in another group onto უნდა ასახელებდეს სხვა ჯგუფში მცურავ პანელს @msg below and above must name a panel floating in another group below და above უნდა ასახელებდეს სხვა ჯგუფში მცურავ პანელს @msg give only one of onto, below and above მიუთითეთ მხოლოდ ერთი: onto, below ან above +@msg give only one of `index`, `indices` and `t` მიუთითეთ მხოლოდ ერთი: `index`, `indices` ან `t` @msg column must be true or a number from 1 column უნდა იყოს true ან რიცხვი 1-დან @msg x and y must both be numbers x და y ორივე რიცხვი უნდა იყოს @msg "{0}" is not a colour: write it as #rrggbb "{0}" ფერი არ არის: ჩაწერეთ #rrggbb სახით diff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsv index ddbdb73519..13b77189ac 100644 --- a/crates/ui-egui/src/i18n/ko.tsv +++ b/crates/ui-egui/src/i18n/ko.tsv @@ -5200,6 +5200,7 @@ theme Appearance 외관 @msg onto must name a panel floating in another group onto는 다른 그룹에 떠 있는 패널을 지정해야 합니다 @msg below and above must name a panel floating in another group below와 above는 다른 그룹에 떠 있는 패널을 지정해야 합니다 @msg give only one of onto, below and above onto, below, above 중 하나만 지정하세요 +@msg give only one of `index`, `indices` and `t` `index`, `indices`, `t` 중 하나만 지정하세요 @msg column must be true or a number from 1 column은 true이거나 1 이상의 숫자여야 합니다 @msg unknown panel `{raw}` 알 수 없는 패널 `{raw}` @msg `{panel}` has no display sizes to cycle `{panel}`에는 전환할 표시 크기가 없습니다 diff --git a/crates/ui-egui/src/i18n/nl.tsv b/crates/ui-egui/src/i18n/nl.tsv index 52280d9c6b..05116fbb23 100644 --- a/crates/ui-egui/src/i18n/nl.tsv +++ b/crates/ui-egui/src/i18n/nl.tsv @@ -5779,6 +5779,7 @@ imageTrace Outline Contour @msg onto must name a panel floating in another group onto moet een zwevend paneel in een andere groep benoemen @msg below and above must name a panel floating in another group below en above moeten een zwevend paneel in een andere groep benoemen @msg give only one of onto, below and above geef slechts één van onto, below en above +@msg give only one of `index`, `indices` and `t` geef slechts één van `index`, `indices` en `t` @msg column must be true or a number from 1 column moet true zijn of een getal vanaf 1 @msg x and y must both be numbers x en y moeten allebei getallen zijn @msg "{0}" is not a colour: write it as #rrggbb "{0}" is geen kleur: schrijf het als #rrggbb diff --git a/crates/ui-egui/src/i18n/pl.tsv b/crates/ui-egui/src/i18n/pl.tsv index 4f0d60b51f..87ded1f414 100644 --- a/crates/ui-egui/src/i18n/pl.tsv +++ b/crates/ui-egui/src/i18n/pl.tsv @@ -5602,6 +5602,7 @@ liquify-list-end {0}, {1} {0} i {1} @msg onto must name a panel floating in another group onto musi wskazywać panel pływający w innej grupie @msg below and above must name a panel floating in another group below i above muszą wskazywać panel pływający w innej grupie @msg give only one of onto, below and above podaj tylko jedno z: onto, below, above +@msg give only one of `index`, `indices` and `t` podaj tylko jedno z: `index`, `indices`, `t` @msg column must be true or a number from 1 column musi mieć wartość true lub liczbę od 1 @msg x and y must both be numbers x i y muszą być liczbami @msg "{0}" is not a colour: write it as #rrggbb "{0}" nie jest kolorem: zapisz go jako #rrggbb diff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsv index 0d3a38037e..9ba24be2cc 100644 --- a/crates/ui-egui/src/i18n/pt-br.tsv +++ b/crates/ui-egui/src/i18n/pt-br.tsv @@ -4783,6 +4783,7 @@ axis Both Ambos @msg onto must name a panel floating in another group onto deve nomear um painel flutuante em outro grupo @msg below and above must name a panel floating in another group below e above devem nomear um painel flutuante em outro grupo @msg give only one of onto, below and above informe apenas um entre onto, below e above +@msg give only one of `index`, `indices` and `t` informe apenas um entre `index`, `indices` e `t` @msg column must be true or a number from 1 column deve ser true ou um número a partir de 1 @msg x and y must both be numbers x e y devem ser números @msg "{0}" is not a colour: write it as #rrggbb "{0}" não é uma cor: escreva-a como #rrggbb diff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsv index d995df8349..312fc51704 100644 --- a/crates/ui-egui/src/i18n/ru.tsv +++ b/crates/ui-egui/src/i18n/ru.tsv @@ -5508,6 +5508,7 @@ liquify-list-end {0}, {1} {0} и {1} @msg onto must name a panel floating in another group onto должен называть панель, плавающую в другой группе @msg below and above must name a panel floating in another group below и above должны называть панель, плавающую в другой группе @msg give only one of onto, below and above укажите только один из onto, below и above +@msg give only one of `index`, `indices` and `t` укажите только один из `index`, `indices` и `t` @msg column must be true or a number from 1 column должен быть true или числом от 1 @msg x and y must both be numbers x и y должны быть числами @msg "{0}" is not a colour: write it as #rrggbb «{0}» не является цветом: запишите его как #rrggbb diff --git a/crates/ui-egui/src/i18n/sv.tsv b/crates/ui-egui/src/i18n/sv.tsv index 928d85a7d3..df275146ca 100644 --- a/crates/ui-egui/src/i18n/sv.tsv +++ b/crates/ui-egui/src/i18n/sv.tsv @@ -5372,6 +5372,7 @@ liquify-list-end {0}, {1} {0} och {1} @msg onto must name a panel floating in another group onto måste ange en panel som flyter i en annan grupp @msg below and above must name a panel floating in another group below och above måste ange en panel som flyter i en annan grupp @msg give only one of onto, below and above ange bara en av onto, below och above +@msg give only one of `index`, `indices` and `t` ange bara en av `index`, `indices` och `t` @msg column must be true or a number from 1 column måste vara true eller ett tal från 1 @msg x and y must both be numbers x och y måste båda vara tal @msg "{0}" is not a colour: write it as #rrggbb "{0}" är inte en färg: skriv den som #rrggbb diff --git a/crates/ui-egui/src/i18n/tr.tsv b/crates/ui-egui/src/i18n/tr.tsv index a4a40055e6..da4ef790aa 100644 --- a/crates/ui-egui/src/i18n/tr.tsv +++ b/crates/ui-egui/src/i18n/tr.tsv @@ -5201,6 +5201,7 @@ liquify-list-end {0}, {1} {0} ve {1} @msg onto must name a panel floating in another group onto başka bir grupta yüzen bir paneli adlandırmalıdır @msg below and above must name a panel floating in another group below ve above başka bir grupta yüzen bir paneli adlandırmalıdır @msg give only one of onto, below and above onto, below ve above değerlerinden yalnızca birini verin +@msg give only one of `index`, `indices` and `t` `index`, `indices` ve `t` değerlerinden yalnızca birini verin @msg column must be true or a number from 1 column true veya 1'den başlayan bir sayı olmalıdır @msg x and y must both be numbers x ve y'nin her ikisi de sayı olmalıdır @msg "{0}" is not a colour: write it as #rrggbb "{0}" bir renk değildir: #rrggbb olarak yazın diff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsv index ee0e19b530..c6fa5bfcff 100644 --- a/crates/ui-egui/src/i18n/uk.tsv +++ b/crates/ui-egui/src/i18n/uk.tsv @@ -5496,6 +5496,7 @@ liquify-list-end {0}, {1} {0} і {1} @msg onto must name a panel floating in another group onto має називати панель, що плаває в іншій групі @msg below and above must name a panel floating in another group below і above мають називати панель, що плаває в іншій групі @msg give only one of onto, below and above вкажіть лише один із onto, below і above +@msg give only one of `index`, `indices` and `t` вкажіть лише один із `index`, `indices` і `t` @msg column must be true or a number from 1 column має бути true або числом від 1 @msg x and y must both be numbers x і y мають бути числами @msg "{0}" is not a colour: write it as #rrggbb "{0}" не є кольором: запишіть його як #rrggbb diff --git a/crates/ui-egui/src/i18n/vi.tsv b/crates/ui-egui/src/i18n/vi.tsv index 3989702763..c65fb8c1a1 100644 --- a/crates/ui-egui/src/i18n/vi.tsv +++ b/crates/ui-egui/src/i18n/vi.tsv @@ -5259,6 +5259,7 @@ liquify-list-end {0}, {1} {0} và {1} @msg give corners of the path: anchors where its sides meet at an angle hãy cung cấp các góc của đường dẫn: điểm neo nơi các cạnh gặp nhau tạo góc @msg give horizontal or vertical hãy chọn ngang hoặc dọc @msg give only one of onto, below and above chỉ cung cấp một trong onto, below và above +@msg give only one of `index`, `indices` and `t` chỉ cung cấp một trong `index`, `indices` và `t` @msg give the path `id` and the width point `index` hãy cung cấp `id` đường dẫn và `index` điểm chiều rộng @msg gradient “{name}” isn't defined in the file: a plain colour stands in for it chuyển sắc “{name}” không được định nghĩa trong tệp: một màu đơn thay thế @msg group must be true or false group phải là true hoặc false diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsv index ee850ca586..119d6977b4 100644 --- a/crates/ui-egui/src/i18n/zh-hans.tsv +++ b/crates/ui-egui/src/i18n/zh-hans.tsv @@ -4954,6 +4954,7 @@ imageTrace Outline 轮廓 @msg onto must name a panel floating in another group onto 必须指定浮动在另一个组中的面板 @msg below and above must name a panel floating in another group below 和 above 必须指定浮动在另一个组中的面板 @msg give only one of onto, below and above onto、below 和 above 只能给出一个 +@msg give only one of `index`, `indices` and `t` `index`、`indices` 和 `t` 只能给出一个 @msg column must be true or a number from 1 column 必须是 true 或从 1 开始的数字 @msg unknown panel `{raw}` 未知面板 `{raw}` @msg `{panel}` has no display sizes to cycle `{panel}` 没有可切换的显示大小 diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsv index 4b620e3162..8fffc9146f 100644 --- a/crates/ui-egui/src/i18n/zh-hant.tsv +++ b/crates/ui-egui/src/i18n/zh-hant.tsv @@ -2490,6 +2490,7 @@ file-filter Templates 範本 @msg onto must name a panel floating in another group onto 必須指定浮動在另一個群組中的面板 @msg below and above must name a panel floating in another group below 和 above 必須指定浮動在另一個群組中的面板 @msg give only one of onto, below and above onto、below 和 above 只能提供其中一個 +@msg give only one of `index`, `indices` and `t` `index`、`indices` 和 `t` 只能提供其中一個 @msg column must be true or a number from 1 column 必須是 true 或從 1 起算的數字 @msg unknown panel `{raw}` 未知的面板 `{raw}` @msg `{panel}` has no display sizes to cycle `{panel}` 沒有可切換的顯示大小 diff --git a/crates/ui-egui/src/menus/ui_commands.rs b/crates/ui-egui/src/menus/ui_commands.rs index 677b804720..6bc224a4db 100644 --- a/crates/ui-egui/src/menus/ui_commands.rs +++ b/crates/ui-egui/src/menus/ui_commands.rs @@ -1307,7 +1307,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.widthPointEdit", "Width Point Edit…", "", - "{id, index?: existing width point, t?: 0..1 for a new point, adjustAdjoining?: bool (false)} open Width Point Edit on path `id` (dialog `widthPoint`: side1, side2 (pt), linked, adjustAdjoining; double-clicking the stroke opens it too, Shift on a width point enabling adjoining adjustment): OK runs stroke.widthPoint.set; discard: true (Delete) removes an existing point or discards a prospective point", + "{id, index?: existing width point, indices?: [i…] several existing width points, t?: 0..1 for a new point (give only one of index, indices and t), adjustAdjoining?: bool (false)} open Width Point Edit on path `id` (dialog `widthPoint`: side1, side2 (pt), linked, adjustAdjoining; for several points also totalWidth, and side1, side2 and totalWidth are null where the points differ; double-clicking the stroke opens it too, on one of several Shift-selected width points for all of them, Shift on a width point enabling adjoining adjustment): OK runs stroke.widthPoint.set, for several points one stroke.widthProfile.set (none when nothing changed); discard: true (Delete) removes the existing points or discards a prospective point", ), ( "ui.corners", diff --git a/docs/control-protocol.md b/docs/control-protocol.md index e599f9800f..29b1a9ad98 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -595,6 +595,19 @@ value: true}` then confirm (the Delete button) removes the point with `stroke.wi Either half of a discontinuous point opens both: `index` is the incoming half, and `outIndex`, `outSide1`, `outSide2` and `outLinked` hold the outgoing half; `single` (`""`, `"incoming"` or `"outgoing"`) is Single Width Only. Confirm sets both halves in one `stroke.widthPoint.set` (one undo step), and Delete removes both. +`ui.widthPointEdit {id, indices: [i…]}` opens it on several existing width points, as double-clicking one of several +Shift-selected width points does. `indices` must be a nonempty array of profile indices; repeated indices count once, +either half of a discontinuous point brings the other, and an index that is not a nonnegative whole number or not a +width point of the stroke is an error, as is giving `indices` with `index` or `t`. When the indices name one width point +(both halves of a discontinuous point count as one) it opens as `index` would. The fields are `indices` (every profile entry edited, in order), `side1`, `side2` and +`totalWidth` (null where the points differ), `linked` and `adjustAdjoining`, and with a discontinuous point among them +`outSide1`, `outSide2`, `outTotalWidth` and `outLinked` for the outgoing halves; the continuous points take both sets. +A side width set there replaces that side of every point (both sides with `linked`), and leaves each point's other side +as it was; `totalWidth` scales each point's own two sides to that total; a null field changes nothing. Confirm runs one +`stroke.widthProfile.set` (one undo step), or nothing when no width changed, and Delete removes every point with +`stroke.widthPoint.remove {id, indices}`. With `adjustAdjoining`, each changed point changes the nearest unselected +point at another place before and after it in proportion to its change since the dialog opened; a point next to two +changed points takes both changes. These rules for several points are VectorCraft's own. Corners: double-clicking a Live Corners widget with the Selection or Direct Selection tool, or `ui.corners {id?, corners?}`, opens the `corners` dialog for a path's corners (the Direct-Selected ones, else every corner; fields `id`, diff --git a/docs/mcp.md b/docs/mcp.md index b45ff0563d..ca58fe8bc6 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -7243,6 +7243,13 @@ continuous point. Indices that are not the two halves of one discontinuous point included), another `t`, or another `single` value are errors that leave the document and its undo history unchanged. Width Point Edit on either half shows both halves as Incoming and Outgoing, with Single Width Only, and its Delete removes both. +`ui.widthPointEdit {id, indices: [i…]}` (or double-clicking one of several Shift-selected width points) opens Width +Point Edit on several points: Side 1, Side 2 and Total Width are blank (null) where the points differ, a side width +typed in sets that side of every point and keeps each point's other side, and Total Width scales each point's own two +sides. OK sets them all with one `stroke.widthProfile.set` (one undo step, none when nothing changed), and Delete +removes them all; with a discontinuous point among them, Incoming and Outgoing edit its two halves and both edit the +continuous points. Malformed or out-of-range `indices`, or `indices` with `index` or `t`, are errors that open no +dialog. `document.inspect` reports a path's `strokeOptions.widthPoints` (`[t, left, right]`, factors of half the weight; null for a uniform stroke). `stroke.widthPoint.remove {id, index | indices}` deletes points; `stroke.widthProfile.set {ids, points}` replaces them all, as dragging several Shift-selected points with the Width tool does in one undo step. diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index db7068cd52..90d10a5e44 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -774,6 +774,7 @@ since 2026-10-01. - **Tabs indent markers on threaded frames:** when a marker drag gives the paragraphs of a threaded story values of their own, the Tabs panel sends one `text.setFormat {paragraphIndents}` with an entry for each paragraph of the story, whatever order the frames were selected in with the Selection tool, so the story flows through its frames again once rather than once for each paragraph, and a drag that changes no paragraph runs nothing; a paragraph that runs on from one frame into the next gets one entry, after Type tool Select All too. A selected story is one text: with the Selection tool, a marker drag on any of its frames sets every paragraph of the story, in its locked and hidden frames too. Tests `panels::tabs::tests::indent_markers_on_selected_threaded_frames_follow_the_story_and_set_a_split_paragraph_once`, `indent_markers_over_many_threaded_paragraphs_send_one_format_command`, `indent_markers_after_select_all_list_a_split_paragraph_once`, `indent_markers_on_some_threaded_frames_list_the_whole_story_once`, `indent_markers_on_one_threaded_frame_set_its_locked_and_hidden_frames`, `cmd::threads::tests::paragraph_indents_flow_a_threaded_story_once_as_one_command_per_paragraph_would`, `paragraph_indents_over_thousands_of_paragraphs_flow_the_story_once` and `paragraph_indents_check_every_entry_and_skip_a_change_that_changes_nothing`, and `cmd::typecmd::area_tests::set_format_refuses_a_param_of_the_wrong_type`. Public reference: [Indent text](https://helpx.adobe.com/illustrator/desktop/design-with-text/edit-format-text/indent-text.html). - **Width Point Edit:** Shift-double-click enables Adjust Adjoining Width Points; plain double-click and direct opening retain the default. Tool dispatch and headless dialog tests cover neighboring widths, Undo/Redo and Cancel. Public reference: [Variable-width strokes](https://helpx.adobe.com/illustrator/using/stroke-object.html). - **Width Point Edit on a discontinuous point:** opening the dialog on either half shows both sets of side widths, Incoming and Outgoing, each with Side 1, Side 2, Total Width and its own link; OK sets both halves in one `stroke.widthPoint.set` and one undo step, and Delete removes both. Single Width Only keeps the incoming or the outgoing widths as one continuous point. With Adjust Adjoining Width Points, the nearest point before follows the incoming change and the nearest point after follows the outgoing change; the group layout and that rule are VectorCraft's own. Tests `dialogs::width_point::tests::either_half_of_a_discontinuous_point_shows_both_sets_of_side_widths`, `ok_sets_both_halves_of_a_discontinuous_point_in_one_step`, `delete_removes_both_halves_of_a_discontinuous_point`, `single_width_only_keeps_the_chosen_half_as_one_point` and `a_compound_member_edits_both_halves_of_its_owners_point`, and `tests::widthpoints::paired_set_*` and `single_width_only_leaves_one_continuous_point`. Public references: [Apply stroke on an object](https://helpx.adobe.com/illustrator/using/stroke-object.html), which describes editing the widths before and after a discontinuous point in that dialog, and an [archived user guide, p. 161](https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf#page=167), which describes keeping either the incoming or the outgoing width to leave one continuous point. +- **Width Point Edit on several selected width points:** double-clicking one of several Shift-selected width points keeps the selection and opens the dialog for all of them (`ui.widthPointEdit {id, indices}`); a double-click on an unselected point edits that point alone. Side 1 and Side 2 typed in apply to every selected point, and OK changes them all in one undo step (none when nothing changed); Delete removes them all. Fields show a value only where every point has it and are blank otherwise; a side width replaces that side of each point and keeps its other side, Total Width scales each point's own sides, Adjust Adjoining Width Points changes the nearest unselected points, and with a discontinuous point Incoming and Outgoing edit its halves; these rules are VectorCraft's own. Tests `distort::width::tests::double_click_on_one_of_several_selected_points_edits_them_all` and `dialogs::width_point::tests::several_points_*`, `a_side_width_sets_that_side_of_every_selected_point`, `ok_on_several_points_is_one_undo_step`, `adjoining_points_follow_every_changed_point_once`, `delete_removes_every_selected_point` and `double_clicking_one_of_several_selected_points_and_typing_edits_them_all`. Public references: [Apply stroke on an object](https://helpx.adobe.com/illustrator/using/stroke-object.html), which describes Shift-clicking to select several width points and setting Side 1 and Side 2 for all of them in Width Point Edit, and an [archived user guide, p. 161](https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf#page=167), which describes the same dialog for several points. Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a feature lands. - **New ruler guides (G1):** Alt swaps orientation while dragging from either ruler, following the [public shortcut reference](https://helpx.adobe.com/illustrator/using/default-keyboard-shortcuts.html). Preview, snapping and final placement use the current axis. Tool and egui event tests exercise both rulers, modifier changes, cancellation and one-step Undo/Redo; existing-guide Alt-copy and ruler-origin gestures are unchanged. From adc2b873db29dc120242abc960446ac420fbb217 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 18 Nov 2026 17:23:25 -0800 Subject: [PATCH 2/2] Width Point Edit: OK and Delete check the points and document they opened on - OK and Delete on one or several existing points are refused when those points changed in any way since the dialog opened (place, widths, stroke weight, or pairing as a discontinuous point), or when another document is active. - OK with no width changed checks the selection before it closes. - An untouched Total Width above 100000 pt no longer blocks OK; a value set above 100000 pt is still refused. - A width set into a field that OK refuses stays there when another field is set afterward, and a negative width typed for several points is refused at OK instead of becoming 0. - `ui.widthPointEdit` refuses `index` together with `t`. - Double-clicking a selected width point passes every selected entry, so points at nearly one place are all edited. --- crates/tools/src/distort/width.rs | 19 +- crates/ui-egui/src/dialogs/width_point.rs | 142 +++++++++++---- .../ui-egui/src/dialogs/width_point/tests.rs | 162 ++++++++++++++++++ docs/control-protocol.md | 5 +- docs/mcp.md | 12 +- 5 files changed, 298 insertions(+), 42 deletions(-) diff --git a/crates/tools/src/distort/width.rs b/crates/tools/src/distort/width.rs index 23e7bdf263..b2050dbbdf 100644 --- a/crates/tools/src/distort/width.rs +++ b/crates/tools/src/distort/width.rs @@ -392,11 +392,11 @@ impl Tool for WidthTool { if !self.is_selected(spot.owner, w.t) { self.selected = Some((spot.owner, vec![w.t])); } + // Every selected entry goes to the dialog, which opens one point (or the two + // halves of a discontinuous point) as `index` would. let indices = self.selected_indices(cx, spot.owner); - let profile = stroke_of(cx.doc, spot.owner).and_then(|s| s.profile.as_ref()); - let several = profile.is_some_and(|pr| indices.iter().any(|i| (pr.points[*i].0 - w.t).abs() > SAME_T)); let mut params = json!({"id": spot.owner.0, "adjustAdjoining": ev.mods.shift}); - if several { + if indices.len() > 1 { params["indices"] = json!(indices); } else { params["index"] = json!(w.index); @@ -1120,6 +1120,19 @@ mod tests { let acts = t.pointer(&c2, &ev(PointerKind::DoubleClick, 200.0, 200.0, none)); let [Action::Dialog(_, v)] = acts.as_slice() else { panic!("expected Width Point Edit: {acts:?}") }; assert_eq!(v["indices"], json!([1, 2, 3])); + // Three points at nearly one place are selected together and all go to the dialog. + let (mut d3, _) = doc_line(); + let points = vec![(0.0, 1.0, 1.0), (0.5, 1.0, 1.0), (0.5000005, 2.0, 2.0), (0.5000009, 3.0, 3.0), (1.0, 1.0, 1.0)]; + d3.node_mut(id).unwrap().appearance.stroke_mut().unwrap().profile = Some(WidthProfile { points }); + let c3 = cx(&d3, &s, &p); + let mut t = WidthTool::default(); + for _ in 0..2 { + t.pointer(&c3, &ev(PointerKind::Down, 200.0, 200.0, none)); + t.pointer(&c3, &ev(PointerKind::Up, 200.0, 200.0, none)); + } + let acts = t.pointer(&c3, &ev(PointerKind::DoubleClick, 200.0, 200.0, none)); + let [Action::Dialog(_, v)] = acts.as_slice() else { panic!("expected Width Point Edit: {acts:?}") }; + assert_eq!(v["indices"], json!([1, 2, 3])); // A click on one of the selected points, then a double-click on it later, edits that point. let mut t = WidthTool::default(); click(&mut t, 150.0, none); diff --git a/crates/ui-egui/src/dialogs/width_point.rs b/crates/ui-egui/src/dialogs/width_point.rs index 4acf0d2d3b..56caf05845 100644 --- a/crates/ui-egui/src/dialogs/width_point.rs +++ b/crates/ui-egui/src/dialogs/width_point.rs @@ -30,6 +30,9 @@ //! entry, both halves of a discontinuous point), `side1`, `side2`, `totalWidth` (null when the //! points differ), `linked`, `adjustAdjoining`, and with a discontinuous point `outSide1`, //! `outSide2`, `outTotalWidth` and `outLinked`. +//! +//! OK and Delete on existing points, one or several, are refused when those points changed since +//! the dialog opened or another document is active. use egui::vec2; use serde_json::{Value, json}; @@ -57,6 +60,11 @@ const POINTS: &str = "__points"; const OPEN: &str = "__open"; /// Whether they include a discontinuous point (two sets of side widths shown). const DISCONTINUOUS: &str = "__discontinuous"; +/// The uid of the document the dialog opened in. +const DOC: &str = "__doc"; +/// The place and side widths `[t, left, right]` (points) of the existing point the one-point dialog +/// opened on, and of the outgoing half of a discontinuous point. +const AT: &str = "__at"; /// The fields of each set of side widths of several points: Side 1, Side 2, Total Width and the /// link, for the incoming set and the outgoing set. @@ -74,6 +82,11 @@ fn point(app: &VectorcraftApp, id: u64, index: usize) -> Option<(f64, f64, f64)> st.profile.as_ref()?.points.get(index).map(|&(t, l, r)| (t, l * half, r * half)) } +/// Width point `index` of `id` as [`point`] reads it, as an array. +fn entry_at(app: &VectorcraftApp, id: u64, index: usize) -> Option<[f64; 3]> { + point(app, id, index).map(|(t, l, r)| [t, l, r]) +} + /// The incoming and outgoing halves of the discontinuous point that width point `index` of `id` /// belongs to, or none when it is a continuous point. The halves are paired by /// [`width_point_pair`], as `stroke.widthPoint.set` pairs them, so either half finds the same pair. @@ -121,12 +134,19 @@ fn shown(es: &[Entry], set: usize) -> [Option; 3] { [common(|e| e.left), common(|e| e.right), common(|e| e.left + e.right)] } -/// Keep `es` as the working widths of `d`, and show them in its fields. -fn store(d: &mut Dialog, es: &[Entry]) { +/// Keep `es` as the working widths of `d`, and show them in its fields. A value set straight into a +/// field other than `typed` that OK refuses, and that is not the value the field showed, stays for +/// OK to refuse. +fn store(d: &mut Dialog, es: &[Entry], typed: Option<&str>) { + let old = entries(d, POINTS); d.fields.insert(POINTS.into(), entries_json(es)); let sets = if d.bool(DISCONTINUOUS) { 2 } else { 1 }; for (set, keys) in MANY.iter().enumerate().take(sets) { - for (key, value) in keys.iter().zip(shown(es, set)) { + for ((key, value), was) in keys.iter().zip(shown(es, set)).zip(shown(&old, set)) { + let showed = reading(d, key).ok().flatten().zip(was).is_some_and(|(v, s)| (v - s).abs() <= SAME_WIDTH); + if Some(*key) != typed && number(d, key).is_err() && !showed { + continue; + } d.fields.insert((*key).into(), json!(value)); } } @@ -156,8 +176,8 @@ fn apply(es: &mut [Entry], set: usize, edit: Edit, linked: bool) { } } -/// The number in field `key` (none when it is null or absent). -fn number(d: &Dialog, key: &str) -> Result, String> { +/// The width in field `key`, any finite width from nothing up (none when it is null or absent). +fn reading(d: &Dialog, key: &str) -> Result, String> { let v = match d.fields.get(key) { None | Some(Value::Null) => return Ok(None), Some(Value::Number(n)) => n.as_f64(), @@ -165,14 +185,25 @@ fn number(d: &Dialog, key: &str) -> Result, String> { Some(_) => None, }; match v { - Some(v) if v.is_finite() && (0.0..=1.0e5).contains(&v) => Ok(Some(v)), + Some(v) if v.is_finite() && v >= 0.0 => Ok(Some(v)), _ => Err("invalid stroke widths".into()), } } +/// The largest side width or Total Width a value typed in can set (points). +const MAX_WIDTH: f64 = 1.0e5; + +/// The number in field `key` that a value typed in can set (none when it is null or absent). +fn number(d: &Dialog, key: &str) -> Result, String> { + match reading(d, key)? { + Some(v) if v > MAX_WIDTH => Err("invalid stroke widths".into()), + v => Ok(v), + } +} + /// The widths OK sets on several points: the working widths, with any value set straight into a /// field (`ui.dialog.set`) that they do not show yet applied as typing it would, Total Width before -/// the sides. +/// the sides. A value the field shows changes nothing, even a Total Width above [`MAX_WIDTH`]. fn edited(d: &Dialog) -> Result, String> { let mut es = entries(d, POINTS); let sets = if d.bool(DISCONTINUOUS) { 2 } else { 1 }; @@ -180,8 +211,13 @@ fn edited(d: &Dialog) -> Result, String> { for (set, shown) in before.iter().enumerate() { let [k1, k2, kt, kl] = MANY[set]; for (key, at) in [(kt, 2), (k1, 0), (k2, 1)] { - let Some(v) = number(d, key)? else { continue }; - if shown[at].is_some_and(|s| (s - v).abs() <= SAME_WIDTH) { + let Some(v) = reading(d, key)? else { continue }; + let same = shown[at].filter(|s| (s - v).abs() <= SAME_WIDTH); + // Only a value above the limit that the points already have passes it. + if v > MAX_WIDTH && !same.is_some_and(|s| s > MAX_WIDTH) { + return Err("invalid stroke widths".into()); + } + if same.is_some() { continue; } let edit = match at { @@ -197,7 +233,8 @@ fn edited(d: &Dialog) -> Result, String> { /// After `ui.dialog.set` sets `field` of several points' dialog: a side width or Total Width applies /// as typing it does, so a value equal to the one shown still sets that side of every point (both -/// sides with the link on). A null or unreadable value is left for OK to skip or refuse. +/// sides with the link on). A null or unreadable value is left for OK to skip or refuse, and a value +/// set later into another field keeps it. pub(super) fn note_set(d: &mut Dialog, field: &str) { if !d.fields.contains_key(OPEN) { return; @@ -213,7 +250,7 @@ pub(super) fn note_set(d: &mut Dialog, field: &str) { }; let mut es = entries(d, POINTS); apply(&mut es, set, edit, d.bool(keys[3])); - store(d, &es); + store(d, &es, Some(field)); return; } } @@ -298,13 +335,16 @@ fn target(app: &VectorcraftApp, id: u64, indices: &Value) -> Result = es.iter().map(|e| e.index).collect(); - let mut d = - Dialog::new(KIND, json!({"id": id, "indices": indices, "adjustAdjoining": adjust, DISCONTINUOUS: discontinuous, OPEN: entries_json(es)})); + let doc = app.session.active().map(|st| st.uid); + let mut d = Dialog::new( + KIND, + json!({"id": id, "indices": indices, "adjustAdjoining": adjust, DISCONTINUOUS: discontinuous, OPEN: entries_json(es), DOC: doc}), + ); for (set, keys) in MANY.iter().enumerate().take(if discontinuous { 2 } else { 1 }) { let linked = es.iter().filter(|e| e.sets[set]).all(|e| (e.left - e.right).abs() < 1e-9); d.fields.insert(keys[3].into(), json!(linked)); } - store(&mut d, es); + store(&mut d, es, None); app.ui.dialog = Some(d); } @@ -321,10 +361,10 @@ pub fn open(app: &mut VectorcraftApp, p: &Value) -> Result { Some(v) => Some(v.as_u64().and_then(|i| usize::try_from(i).ok()).ok_or("no such width point")?), None => None, }; + if ["index", "indices", "t"].iter().filter(|key| given(key)).count() > 1 { + return Err("give only one of `index`, `indices` and `t`".into()); + } if let Some(indices) = p.get("indices").filter(|v| !v.is_null()) { - if given("index") || given("t") { - return Err("give only one of `index`, `indices` and `t`".into()); - } match target(app, id, indices)? { Target::One(i) => index = Some(i), Target::Several(es) => { @@ -353,7 +393,10 @@ pub fn open(app: &mut VectorcraftApp, p: &Value) -> Result { (t, l, r) }; let adjust = p.get("adjustAdjoining").and_then(Value::as_bool).unwrap_or(false); - let mut fields = json!({"id": id, "index": index, "t": t, "side1": l, "side2": r, "linked": (l - r).abs() < 1e-9, "adjustAdjoining": adjust}); + let doc = app.session.active().map(|st| st.uid); + let at: Vec<_> = index.into_iter().chain(pair.map(|(_, out)| out)).filter_map(|i| entry_at(app, id, i)).collect(); + let linked = (l - r).abs() < 1e-9; + let mut fields = json!({"id": id, "index": index, "t": t, "side1": l, "side2": r, "linked": linked, "adjustAdjoining": adjust, DOC: doc, AT: at}); if let Some((_, out)) = pair { let (_, l, r) = point(app, id, out).ok_or("no such width point")?; for (key, value) in [ @@ -420,14 +463,14 @@ fn sides(ui: &mut egui::Ui, d: &mut Dialog, unit: Unit, keys: [&str; 3], ids: [& fn sides_of_several(ui: &mut egui::Ui, d: &mut Dialog, unit: Unit, set: usize) { let [k1, k2, kt, kl] = MANY[set]; let ids = MANY_IDS[set]; - let value = |key: &str| number(d, key).ok().flatten(); + let value = |key: &str| reading(d, key).ok().flatten(); let (s1, s2, total, linked) = (value(k1), value(k2), value(kt), d.bool(kl)); let mut edit = None; grid(ui, |ui| { label(ui, tl!("Side 1:")); ui.horizontal(|ui| { if let Some(v) = widgets::num_field(ui, ids[0], s1, unit, 90.0) { - edit = Some(Edit::Side1(v)); + edit = Some((Edit::Side1(v), k1)); } if widgets::icon_button(ui, if linked { "link" } else { "link-2-off" }, tl!("Keep both sides the same width"), linked, 22.0).clicked() { d.fields.insert(kl.into(), json!(!linked)); @@ -436,20 +479,25 @@ fn sides_of_several(ui: &mut egui::Ui, d: &mut Dialog, unit: Unit, set: usize) { ui.end_row(); label(ui, tl!("Side 2:")); if let Some(v) = widgets::num_field(ui, ids[1], s2, unit, 90.0) { - edit = Some(Edit::Side2(v)); + edit = Some((Edit::Side2(v), k2)); } ui.end_row(); label(ui, tl!("Total Width:")); if let Some(v) = widgets::num_field(ui, ids[2], total, unit, 90.0) { - edit = Some(Edit::Total(v)); + edit = Some((Edit::Total(v), kt)); } ui.end_row(); }); - if let Some(edit) = edit { + if let Some((Edit::Side1(v) | Edit::Side2(v) | Edit::Total(v), key)) = edit + && !(0.0..=MAX_WIDTH).contains(&v) + { + // Not a width it can set: the field keeps it for OK to refuse. + d.fields.insert(key.into(), if v.is_finite() { json!(v) } else { json!(v.to_string()) }); + } else if let Some((edit, key)) = edit { // Values set straight into the fields count first, so typing does not lose them. let mut es = edited(d).unwrap_or_else(|_| entries(d, POINTS)); apply(&mut es, set, edit, linked); - store(d, &es); + store(d, &es, Some(key)); } } @@ -491,8 +539,16 @@ fn body(app: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) -> bool { false } +/// Whether the document the dialog opened in is still the active one. +fn same_document(app: &VectorcraftApp, d: &Dialog) -> Result<(), String> { + match (d.fields.get(DOC).and_then(Value::as_u64), app.session.active()) { + (Some(uid), Some(st)) if st.uid == uid => Ok(()), + _ => Err("no such width point".into()), + } +} + /// `id`'s width profile and the stroke's half weight, when the points `open` are still where and as -/// wide as when the dialog opened. +/// wide as when the dialog opened, exactly. fn opened_profile(app: &VectorcraftApp, id: u64, open: &[Entry]) -> Result<(WidthProfile, f64), String> { const NONE: &str = "no such width point"; let st = app.session.active().and_then(|s| s.doc.node(NodeId(id))).and_then(|n| n.appearance.stroke()).ok_or(NONE)?; @@ -506,7 +562,8 @@ fn opened_profile(app: &VectorcraftApp, id: u64, open: &[Entry]) -> Result<(Widt } for o in open { let &(t, l, r) = profile.points.get(o.index).ok_or(NONE)?; - if (t - o.t).abs() > SAME_T || (l * half - o.left).abs() > SAME_WIDTH || (r * half - o.right).abs() > SAME_WIDTH { + // The entries were read from this profile at this weight, so an unchanged point compares equal. + if t != o.t || l * half != o.left || r * half != o.right { return Err(NONE.into()); } } @@ -578,8 +635,9 @@ fn edited_profile(app: &VectorcraftApp, id: u64, open: &[Entry], new: &[Entry], fn confirm_several(app: &mut VectorcraftApp, d: &Dialog) -> Result { let id = d.fields.get("id").and_then(Value::as_u64).ok_or("no such width point")?; let open = entries(d, OPEN); + same_document(app, d)?; + opened_profile(app, id, &open)?; if d.bool("discard") { - opened_profile(app, id, &open)?; let indices: Vec = open.iter().map(|e| e.index).collect(); return run_and_close(app, "stroke.widthPoint.remove", json!({"id": id, "indices": indices})); } @@ -593,18 +651,38 @@ fn confirm_several(app: &mut VectorcraftApp, d: &Dialog) -> Result) -> Result<(), String> { + const NONE: &str = "no such width point"; + let id = d.fields.get("id").and_then(Value::as_u64).ok_or(NONE)?; + let at: Vec<[f64; 3]> = d.fields.get(AT).cloned().and_then(|v| serde_json::from_value(v).ok()).ok_or(NONE)?; + let now: Vec<_> = std::iter::once(index).chain(out).map(|i| entry_at(app, id, i)).collect::>().ok_or(NONE)?; + // The widths are read at the stroke's current weight, so a changed weight changes them too, and + // a continuous point must still be one. + if now != at || halves(app, id, index) != out.map(|o| (index, o)) { + return Err(NONE.into()); + } + Ok(()) +} + fn confirm(app: &mut VectorcraftApp, d: &Dialog) -> Result { if d.fields.contains_key(OPEN) { return confirm_several(app, d); } let (id, index) = (d.fields.get("id").cloned().unwrap_or_default(), d.fields.get("index").cloned().unwrap_or_default()); let out = d.fields.get("outIndex").filter(|_| paired(d)).cloned(); + if d.bool("discard") && index.is_null() { + // Deleting a prospective point discards the dialog; no document point exists yet. + app.ui.dialog = None; + return Ok(Value::Null); + } + // OK and Delete act only on the document and the points the dialog opened on. + same_document(app, d)?; + if let Some(index) = index.as_u64().and_then(|i| usize::try_from(i).ok()) { + unchanged_point(app, d, index, out.as_ref().and_then(Value::as_u64).and_then(|i| usize::try_from(i).ok()))?; + } if d.bool("discard") { - if index.is_null() { - // Deleting a prospective point discards the dialog; no document point exists yet. - app.ui.dialog = None; - return Ok(Value::Null); - } let p = match out { Some(out) => json!({"id": id, "indices": [index, out]}), None => json!({"id": id, "index": index}), diff --git a/crates/ui-egui/src/dialogs/width_point/tests.rs b/crates/ui-egui/src/dialogs/width_point/tests.rs index d939cb5a6c..0653c5fb19 100644 --- a/crates/ui-egui/src/dialogs/width_point/tests.rs +++ b/crates/ui-egui/src/dialogs/width_point/tests.rs @@ -840,6 +840,24 @@ fn double_clicking_one_of_several_selected_points_and_typing_edits_them_all() { assert_eq!(points(&app, id), vec![(0.0, 1.0, 1.0), (0.25, 1.0, 0.4), (0.5, 0.8, 0.8), (0.75, 1.0, 1.2), (1.0, 1.0, 1.0)]); } +#[test] +fn a_negative_width_typed_for_several_points_is_refused() { + let (mut app, id) = three_app(); + let before = app.session.doc().unwrap().doc.clone(); + let ctx = egui::Context::default(); + crate::theme::install_fonts(&ctx); + crate::theme::apply(&ctx, Default::default()); + app.run("ui.widthPointEdit", json!({"id": id, "indices": [1, 3]})).unwrap(); + for _ in 0..5 { + creation_dialog_frame(&mut app, &ctx, vec![]); + } + // The blank Side 1 has the focus. + creation_dialog_frame(&mut app, &ctx, vec![egui::Event::Text("-3 pt".into())]); + creation_dialog_click(&mut app, &ctx, "OK"); + assert!(app.ui.dialog.is_some(), "OK refuses it and the dialog stays open"); + assert_eq!(app.session.doc().unwrap().doc, before); +} + #[test] fn several_points_refuse_bad_indices() { let (mut app, id) = three_app(); @@ -854,6 +872,7 @@ fn several_points_refuse_bad_indices() { json!({"id": id, "indices": 1}), json!({"id": id, "indices": [1, 3], "index": 1}), json!({"id": id, "indices": [1, 3], "t": 0.5}), + json!({"id": id, "index": 1, "t": 0.5}), ] { assert!(app.run("ui.widthPointEdit", p.clone()).is_err(), "{p}"); assert!(app.ui.dialog.is_none(), "{p}"); @@ -885,3 +904,146 @@ fn several_points_refuse_bad_indices() { assert_eq!(app.session.doc().unwrap().doc, before); } } + +#[test] +fn a_total_width_above_the_side_limit_does_not_block_ok() { + // Two points of 60000 + 60000 pt on the 10 pt stroke: Total Width shows 120000 pt. + let (mut app, id) = three_app(); + let wide = json!([[0, 1, 1], [0.25, 12000, 12000], [0.5, 0.8, 0.8], [0.75, 12000, 12000], [1, 1, 1]]); + app.run("stroke.widthProfile.set", json!({"ids": [id], "points": wide})).unwrap(); + let before = app.session.doc().unwrap().doc.clone(); + app.run("ui.widthPointEdit", json!({"id": id, "indices": [1, 3]})).unwrap(); + assert_eq!(app.ui.dialog.as_ref().unwrap().fields["totalWidth"], json!(120000.0)); + super::super::confirm(&mut app).unwrap(); + assert!(app.ui.dialog.is_none()); + assert_eq!(app.session.doc().unwrap().doc, before); + // A side width typed in applies with the total shown. + app.run("ui.widthPointEdit", json!({"id": id, "indices": [1, 3]})).unwrap(); + let d = app.ui.dialog.as_mut().unwrap(); + d.fields.insert("linked".into(), json!(false)); + super::super::set_field(d, "side1".into(), json!(5)); + super::super::confirm(&mut app).unwrap(); + assert!(app.ui.dialog.is_none()); + assert_eq!(points(&app, id), vec![(0.0, 1.0, 1.0), (0.25, 1.0, 12000.0), (0.5, 0.8, 0.8), (0.75, 1.0, 12000.0), (1.0, 1.0, 1.0)]); + // A value set above the limit is refused even next to the 100000 pt shown. + let (mut app, id) = three_app(); + let edge = json!([[0, 1, 1], [0.25, 20000, 0.4], [0.5, 0.8, 0.8], [0.75, 20000, 1.2], [1, 1, 1]]); + app.run("stroke.widthProfile.set", json!({"ids": [id], "points": edge})).unwrap(); + app.run("ui.widthPointEdit", json!({"id": id, "indices": [1, 3]})).unwrap(); + app.ui.dialog.as_mut().unwrap().fields.insert("side1".into(), json!(100000.0000005)); + assert!(super::super::confirm(&mut app).is_err()); +} + +#[test] +fn an_invalid_width_stays_for_ok_to_refuse() { + let (mut app, id) = three_app(); + let before = app.session.doc().unwrap().doc.clone(); + app.run("ui.widthPointEdit", json!({"id": id, "indices": [1, 3]})).unwrap(); + let d = app.ui.dialog.as_mut().unwrap(); + super::super::set_field(d, "side1".into(), json!("wide")); + super::super::set_field(d, "side2".into(), json!("3 pt")); + assert_eq!(d.fields["side1"], json!("wide")); + assert!(super::super::confirm(&mut app).is_err()); + assert!(app.ui.dialog.is_some()); + assert_eq!(app.session.doc().unwrap().doc, before); + // Corrected, it applies with the Side 2 already set. + super::super::set_field(app.ui.dialog.as_mut().unwrap(), "side1".into(), json!(5)); + super::super::confirm(&mut app).unwrap(); + assert_eq!(points(&app, id), vec![(0.0, 1.0, 1.0), (0.25, 1.0, 0.6), (0.5, 0.8, 0.8), (0.75, 1.0, 0.6), (1.0, 1.0, 1.0)]); +} + +#[test] +fn several_points_refuse_any_change_since_the_dialog_opened() { + let (mut app, id) = three_app(); + // A change too small to show in the fields. + app.run("ui.widthPointEdit", json!({"id": id, "indices": [1, 3]})).unwrap(); + let nudged = json!([[0, 1, 1], [0.25, 0.8000001, 0.4], [0.5, 0.8, 0.8], [0.75, 0.4, 1.2], [1, 1, 1]]); + app.run("stroke.widthProfile.set", json!({"ids": [id], "points": nudged})).unwrap(); + let changed = app.session.doc().unwrap().doc.clone(); + for field in ["side2", "discard"] { + let d = app.ui.dialog.as_mut().unwrap(); + d.fields.insert(field.into(), if field == "discard" { json!(true) } else { json!(5) }); + assert!(super::super::confirm(&mut app).is_err(), "{field}"); + assert_eq!(app.session.doc().unwrap().doc, changed); + } + app.run("edit.undo", json!({})).unwrap(); + // OK with no width changed still checks the points. + app.run("ui.widthPointEdit", json!({"id": id, "indices": [1, 3]})).unwrap(); + app.run("stroke.widthPoint.set", json!({"id": id, "index": 1, "t": 0.3, "left": 4, "right": 2})).unwrap(); + assert!(super::super::confirm(&mut app).is_err()); + assert!(app.ui.dialog.is_some()); +} + +/// Open a second document holding [`three_app`]'s line with the same id, and make it active. +fn second_document(app: &mut VectorcraftApp, id: u64) { + app.run("file.new", json!({"width": 400, "height": 300})).unwrap(); + let other = app.run("shape.line", json!({"x1": 100, "y1": 150, "x2": 300, "y2": 150})).unwrap()["id"].as_u64().unwrap(); + assert_eq!(other, id, "the same id in both documents"); + app.run("stroke.set", json!({"ids": [other], "weight": 10})).unwrap(); + let points = json!([[0, 1, 1], [0.25, 0.8, 0.4], [0.5, 0.8, 0.8], [0.75, 0.4, 1.2], [1, 1, 1]]); + app.run("stroke.widthProfile.set", json!({"ids": [other], "points": points})).unwrap(); +} + +#[test] +fn ok_and_delete_act_only_in_the_document_the_dialog_opened_in() { + for opened in [json!({"indices": [1, 3]}), json!({"index": 2})] { + for field in ["side1", "discard"] { + let (mut app, id) = three_app(); + let mut p = opened.clone(); + p["id"] = json!(id); + app.run("ui.widthPointEdit", p).unwrap(); + let d = app.ui.dialog.take(); + second_document(&mut app, id); + let other = app.session.doc().unwrap().doc.clone(); + app.ui.dialog = d; + let d = app.ui.dialog.as_mut().unwrap(); + d.fields.insert(field.into(), if field == "discard" { json!(true) } else { json!(5) }); + assert!(super::super::confirm(&mut app).is_err(), "{opened} {field}"); + assert_eq!(app.session.doc().unwrap().doc, other, "{opened} {field}"); + } + } +} + +#[test] +fn one_point_refuses_a_change_since_the_dialog_opened() { + for field in ["side1", "discard"] { + // A point added before the opened one moves it to the next index. + let (mut app, id) = app(); + app.run("ui.widthPointEdit", json!({"id": id, "index": 1})).unwrap(); + app.run("stroke.widthPoint.set", json!({"id": id, "t": 0.25, "left": 3, "right": 3})).unwrap(); + let added = app.session.doc().unwrap().doc.clone(); + let d = app.ui.dialog.as_mut().unwrap(); + d.fields.insert(field.into(), if field == "discard" { json!(true) } else { json!(5) }); + assert!(super::super::confirm(&mut app).is_err(), "{field}"); + assert_eq!(app.session.doc().unwrap().doc, added, "{field}"); + // The outgoing half of a discontinuous point changed. + let (mut app, id) = pair_app(); + app.run("ui.widthPointEdit", json!({"id": id, "index": 1})).unwrap(); + app.run("stroke.widthProfile.set", json!({"ids": [id], "points": [[0, 1, 1], [0.5, 0.8, 0.8], [0.5, 0.2, 1.2], [1, 1, 1]]})).unwrap(); + let changed = app.session.doc().unwrap().doc.clone(); + let d = app.ui.dialog.as_mut().unwrap(); + d.fields.insert(field.into(), if field == "discard" { json!(true) } else { json!(5) }); + assert!(super::super::confirm(&mut app).is_err(), "{field}"); + assert_eq!(app.session.doc().unwrap().doc, changed, "{field}"); + // The stroke weight changed. + let (mut app, id) = self::app(); + app.run("ui.widthPointEdit", json!({"id": id, "index": 1})).unwrap(); + app.run("stroke.set", json!({"ids": [id], "weight": 20})).unwrap(); + let heavier = app.session.doc().unwrap().doc.clone(); + let d = app.ui.dialog.as_mut().unwrap(); + d.fields.insert(field.into(), if field == "discard" { json!(true) } else { json!(5) }); + assert!(super::super::confirm(&mut app).is_err(), "{field}"); + assert_eq!(app.session.doc().unwrap().doc, heavier, "{field}"); + // A later point moved onto the opened one makes it one half of a discontinuous point. + let (mut app, id) = self::app(); + app.run("stroke.widthPoint.set", json!({"id": id, "t": 0.75, "left": 3, "right": 3})).unwrap(); + app.run("ui.widthPointEdit", json!({"id": id, "index": 1})).unwrap(); + app.run("stroke.widthPoint.set", json!({"id": id, "index": 2, "t": 0.5, "left": 3, "right": 3})).unwrap(); + let paired = app.session.doc().unwrap().doc.clone(); + assert_eq!(points(&app, id)[1], (0.5, 0.8, 0.8), "the opened point keeps its index"); + let d = app.ui.dialog.as_mut().unwrap(); + d.fields.insert(field.into(), if field == "discard" { json!(true) } else { json!(5) }); + assert!(super::super::confirm(&mut app).is_err(), "{field}"); + assert_eq!(app.session.doc().unwrap().doc, paired, "{field}"); + } +} diff --git a/docs/control-protocol.md b/docs/control-protocol.md index bdb55b4060..0b9afb37cd 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -610,7 +610,7 @@ sets both halves in one `stroke.widthPoint.set` (one undo step), and Delete remo `ui.widthPointEdit {id, indices: [i…]}` opens it on several existing width points, as double-clicking one of several Shift-selected width points does. `indices` must be a nonempty array of profile indices; repeated indices count once, either half of a discontinuous point brings the other, and an index that is not a nonnegative whole number or not a -width point of the stroke is an error, as is giving `indices` with `index` or `t`. When the indices name one width point +width point of the stroke is an error, as is giving more than one of `index`, `indices` and `t`. When the indices name one width point (both halves of a discontinuous point count as one) it opens as `index` would. The fields are `indices` (every profile entry edited, in order), `side1`, `side2` and `totalWidth` (null where the points differ), `linked` and `adjustAdjoining`, and with a discontinuous point among them `outSide1`, `outSide2`, `outTotalWidth` and `outLinked` for the outgoing halves; the continuous points take both sets. @@ -619,7 +619,8 @@ as it was; `totalWidth` scales each point's own two sides to that total; a null `stroke.widthProfile.set` (one undo step), or nothing when no width changed, and Delete removes every point with `stroke.widthPoint.remove {id, indices}`. With `adjustAdjoining`, each changed point changes the nearest unselected point at another place before and after it in proportion to its change since the dialog opened; a point next to two -changed points takes both changes. These rules for several points are VectorCraft's own. +changed points takes both changes. These rules for several points are VectorCraft's own. Confirm and Delete on existing +points, one or several, are refused when those points changed since the dialog opened or another document is active. Corners: double-clicking a Live Corners widget with the Selection or Direct Selection tool, or `ui.corners {id?, corners?}`, opens the `corners` dialog for a path's corners (the Direct-Selected ones, else every corner; fields `id`, diff --git a/docs/mcp.md b/docs/mcp.md index 5fce827462..2683fff05d 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -7812,11 +7812,13 @@ Width Point Edit on either half shows both halves as Incoming and Outgoing, with removes both. `ui.widthPointEdit {id, indices: [i…]}` (or double-clicking one of several Shift-selected width points) opens Width Point Edit on several points: Side 1, Side 2 and Total Width are blank (null) where the points differ, a side width -typed in sets that side of every point and keeps each point's other side, and Total Width scales each point's own two -sides. OK sets them all with one `stroke.widthProfile.set` (one undo step, none when nothing changed), and Delete -removes them all; with a discontinuous point among them, Incoming and Outgoing edit its two halves and both edit the -continuous points. Malformed or out-of-range `indices`, or `indices` with `index` or `t`, are errors that open no -dialog. +typed in sets that side of every point (both sides while the link is on, which it is when every point has equal sides; +turn it off to keep each point's other side), and Total Width scales each point's own two sides. OK sets them all with +one `stroke.widthProfile.set` (one undo step, none when nothing changed), and Delete removes them all; with a +discontinuous point among them, Incoming and Outgoing edit its two halves and both edit the continuous points. +Malformed or out-of-range `indices`, or more than one of `index`, `indices` and `t`, are errors that open no dialog. OK +and Delete on existing points are refused when those points changed since the dialog opened or another document is +active. `document.inspect` reports a path's `strokeOptions.widthPoints` (`[t, left, right]`, factors of half the weight; null for a uniform stroke). `stroke.widthPoint.remove {id, index | indices}` deletes points; `stroke.widthProfile.set {ids, points}` replaces them all, as dragging several Shift-selected points with the Width tool does in one undo step.