VectorCraft: An open-source, vector art tool written by scratch in pure Rust
Review: Graph Design dialog as Illustrator's (preview, New Design, Rename, Delete Design, Paste Design, Select Unused)
IHAGI-c62aceb205c08
diff --git a/crates/engine/src/cmd/graph.rs b/crates/engine/src/cmd/graph.rsindex 1c490b36f..97d0cdf7a 100644--- a/crates/engine/src/cmd/graph.rs+++ b/crates/engine/src/cmd/graph.rs@@ -52,7 +52,7 @@ pub fn specs() -> Vec<CommandSpec> {"Design…",["Object", "Graph"],None,- "{save?: name (the selected art becomes a graph design; put a rectangle at the back to set the size it draws at), paste?: name (a copy of the design's art into the document, selected, to edit and save again), delete?: name (graphs drawing it go back to their default marks)}; no params → {designs: [names]}",+ "{new?: name|true (New Design: the selected art becomes a graph design, named \"New Design\" when true; put a rectangle at the back to set the size it draws at), rename?: name, to?: new name (the graphs drawing it follow), paste?: name (Paste Design: a copy of the design's art into the document, selected, to edit and save again), delete?: name|[names] (graphs drawing them go back to their default marks)}; no params or selectUnused → {designs: [names], unused: [the names no graph draws with]}",has_doc,design),@@ -1092,16 +1092,47 @@ fn refresh_graphs_using(d: &mut Document, name: &str) -> Result<()> {Ok(())}+/// The designs no graph's series draw with (Select Unused).+fn unused_designs(d: &Document) -> Vec<String> {+ let mut used = std::collections::HashSet::new();+ d.walk(|n| {+ if let Some(g) = n.graph.as_deref() {+ used.extend(g.series_markers.iter().flatten().cloned());+ }+ });+ d.graph_designs.iter().map(|x| x.name.clone()).filter(|n| !used.contains(n)).collect()+}++/// Design names from param `key`: one name or a list of names.+fn names_param(p: &Value, key: &str, cmd: &str) -> Result<Option<Vec<String>>> {+ match p.get(key) {+ None => Ok(None),+ Some(Value::String(n)) => Ok(Some(vec![n.clone()])),+ Some(Value::Array(a)) if !a.is_empty() => a+ .iter()+ .map(|v| v.as_str().map(str::to_string).ok_or_else(|| bad(cmd, format!("`{key}` is a design name or a list of them"))))+ .collect::<Result<_>>()+ .map(Some),+ Some(_) => Err(bad(cmd, format!("`{key}` is a design name or a list of them"))),+ }+}+fn design(s: &mut Session, p: &Value) -> Result<Value> {const C: &str = "graph.design";- for key in ["save", "paste", "delete"] {+ for key in ["paste", "rename", "to"] {if p.get(key).is_some_and(|v| !v.is_string()) {return Err(bad(C, format!("`{key}` is a design name")));}}- if let Some(name) = str_param(p, "save") {- let name = GraphDesign::clean_name(name).ok_or_else(|| bad(C, "a design needs a name"))?;- if s.doc()?.doc.graph_designs.iter().any(|x| x.name == name) {+ let taken = |s: &Session, name: &str| s.doc().is_ok_and(|st| st.doc.graph_designs.iter().any(|x| x.name == name));+ // New Design: the selected art, named `new` or "New Design" (numbered when that's taken).+ if let Some(v) = p.get("new") {+ let name = match v {+ Value::String(n) => GraphDesign::clean_name(n).ok_or_else(|| bad(C, "a design needs a name"))?,+ Value::Bool(true) | Value::Null => super::unique_name("New Design", |n| taken(s, n)),+ _ => return Err(bad(C, "`new` is a design name, or true")),+ };+ if taken(s, &name) {return Err(bad(C, format!("there is already a design named `{name}`")));}if s.doc()?.doc.graph_designs.len() >= GraphDesign::MAX {@@ -1114,13 +1145,47 @@ fn design(s: &mut Session, p: &Value) -> Result<Value> {// A graph saved as a design is kept as the art it draws.let art = GraphDesign::plain_art(&art);let saved = name.clone();- s.edit("Graph Design", |d, _| {+ s.edit("New Design", |d, _| {let art = d.reid(&art);d.graph_designs.push(GraphDesign { name: saved.clone(), art: Arc::new(art) });refresh_graphs_using(d, &saved)})?;return Ok(json!({ "name": name }));}+ // Rename: the graphs drawing the design follow it to its new name.+ if let Some(old) = str_param(p, "rename") {+ if !taken(s, old) {+ return Err(bad(C, format!("no design named `{old}`")));+ }+ let to = str_param(p, "to").and_then(GraphDesign::clean_name).ok_or_else(|| bad(C, "`to` is the design's new name"))?;+ if to == old {+ return Ok(json!({ "name": to }));+ }+ if taken(s, &to) {+ return Err(bad(C, format!("there is already a design named `{to}`")));+ }+ let (old, new) = (old.to_string(), to.clone());+ s.edit("Rename Design", |d, _| {+ if let Some(x) = d.graph_designs.iter_mut().find(|x| x.name == old) {+ x.name = new.clone();+ }+ let mut graphs = vec![];+ d.walk(|n| {+ if n.graph.as_deref().is_some_and(|g| g.series_markers.iter().flatten().any(|m| *m == old)) {+ graphs.push(n.id);+ }+ });+ for id in graphs {+ if let Some(g) = d.node_mut(id).and_then(|n| n.graph.as_deref_mut()) {+ for m in g.series_markers.iter_mut().flatten().filter(|m| **m == old) {+ *m = new.clone();+ }+ }+ }+ Ok(())+ })?;+ return Ok(json!({ "name": to }));+ }if let Some(name) = str_param(p, "paste") {let art = s.doc()?@@ -1140,18 +1205,22 @@ fn design(s: &mut Session, p: &Value) -> Result<Value> {})?;return Ok(json!({ "id": id.0 }));}- if let Some(name) = str_param(p, "delete") {- if !s.doc()?.doc.graph_designs.iter().any(|x| x.name == name) {- return Err(bad(C, format!("no design named `{name}`")));+ if let Some(names) = names_param(p, "delete", C)? {+ if let Some(n) = names.iter().find(|n| !taken(s, n)) {+ return Err(bad(C, format!("no design named `{n}`")));}- let name = name.to_string();s.edit("Delete Design", |d, _| {- d.graph_designs.retain(|x| x.name != name);- refresh_graphs_using(d, &name)+ d.graph_designs.retain(|x| !names.contains(&x.name));+ for name in &names {+ refresh_graphs_using(d, name)?;+ }+ Ok(())})?;return ok();}- Ok(json!({ "designs": design_names(&s.doc()?.doc) }))+ // The list, with the designs no graph draws with (Select Unused picks those).+ let d = &s.doc()?.doc;+ Ok(json!({ "designs": design_names(d), "unused": unused_designs(d) }))}fn set_marker(s: &mut Session, p: &Value) -> Result<Value> {@@ -2491,7 +2560,7 @@ mod tests {let r = s.execute("shape.rectangle", &json!({"x": 600, "y": 600, "width": 10, "height": 10})).unwrap()["id"].as_u64().unwrap();let e = s.execute("shape.ellipse", &json!({"x": 595, "y": 600, "width": 20, "height": 10})).unwrap()["id"].as_u64().unwrap();s.execute("select.set", &json!({"ids": [r, e]})).unwrap();- s.execute("graph.design", &json!({"save": name})).unwrap();+ s.execute("graph.design", &json!({"new": name})).unwrap();}/// The marks of series `index` (legend swatch last) and their bounds.@@ -2562,12 +2631,12 @@ mod tests {fn graph_designs_are_saved_pasted_and_deleted() {let mut s = Session::new();s.execute("file.new", &json!({"width": 800, "height": 800})).unwrap();- assert!(s.execute("graph.design", &json!({"save": "Pill"})).is_err(), "nothing selected");+ assert!(s.execute("graph.design", &json!({"new": "Pill"})).is_err(), "nothing selected");save_design(&mut s, "Pill");let r = s.execute("shape.rectangle", &json!({"x": 0, "y": 0, "width": 10, "height": 10})).unwrap()["id"].as_u64().unwrap();s.execute("select.set", &json!({"ids": [r]})).unwrap();- assert!(s.execute("graph.design", &json!({"save": "Pill"})).is_err(), "the name is taken");- assert!(s.execute("graph.design", &json!({"save": " "})).is_err(), "no name");+ assert!(s.execute("graph.design", &json!({"new": "Pill"})).is_err(), "the name is taken");+ assert!(s.execute("graph.design", &json!({"new": " "})).is_err(), "no name");// Paste Design: a copy of the art, selected, with ids of its own.let pasted = NodeId(s.execute("graph.design", &json!({"paste": "Pill"})).unwrap()["id"].as_u64().unwrap());assert_eq!(s.doc().unwrap().selection.objects.to_vec(), [pasted]);@@ -2618,7 +2687,7 @@ mod tests {let id = graph(&mut s, "line");s.execute("graph.marker", &json!({"design": "Pill"})).unwrap();s.execute("select.set", &json!({"ids": [id.0]})).unwrap();- s.execute("graph.design", &json!({"save": "Chart"})).unwrap();+ s.execute("graph.design", &json!({"new": "Chart"})).unwrap();let art = s.doc().unwrap().doc.graph_designs[1].art.clone();let mut graphs = 0;art.walk(&mut |n| graphs += usize::from(n.graph.is_some() || n.series_index.is_some()));@@ -2645,7 +2714,7 @@ mod tests {.map(|i| s.execute("shape.rectangle", &json!({"x": i % 40, "y": i / 40, "width": 1, "height": 1})).unwrap()["id"].as_u64().unwrap()).collect();s.execute("select.set", &json!({"ids": ids})).unwrap();- s.execute("graph.design", &json!({"save": "Big"})).unwrap();+ s.execute("graph.design", &json!({"new": "Big"})).unwrap();let rows: Vec<Vec<f64>> = (0..200).map(|i| vec![i as f64]).collect();let id = NodeId(s.execute("graph.create", &json!({"type": "line", "x": 0, "y": 0, "width": 300, "height": 200, "rows": rows})).unwrap()["id"]@@ -2666,7 +2735,7 @@ mod tests {.map(|i| s.execute("shape.rectangle", &json!({"x": i % 40, "y": i / 40, "width": 1, "height": 1})).unwrap()["id"].as_u64().unwrap()).collect();s.execute("select.set", &json!({"ids": ids})).unwrap();- assert!(s.execute("graph.design", &json!({"save": "Huge"})).is_err());+ assert!(s.execute("graph.design", &json!({"new": "Huge"})).is_err());}#[test]@@ -2716,7 +2785,7 @@ mod tests {fn graph_design_params_are_names() {let mut s = Session::new();s.execute("file.new", &json!({"width": 800, "height": 800})).unwrap();- for p in [json!({"save": 5}), json!({"paste": null}), json!({"delete": ["a"]})] {+ for p in [json!({"new": 5}), json!({"paste": null}), json!({"delete": ["a"]})] {assert!(s.execute("graph.design", &p).is_err(), "{p}");}}@@ -2728,10 +2797,34 @@ mod tests {let r = s.execute("shape.rectangle", &json!({"x": 0, "y": 0, "width": 10, "height": 10})).unwrap()["id"].as_u64().unwrap();s.execute("paint.setFill", &json!({"ids": [r], "color": "#123456"})).unwrap();s.execute("select.set", &json!({"ids": [r]})).unwrap();- s.execute("graph.design", &json!({"save": "Blue"})).unwrap();+ s.execute("graph.design", &json!({"new": "Blue"})).unwrap();s.execute("edit.clear", &json!({})).unwrap();let mut seen = false;s.doc().unwrap().doc.visit_paints(&mut |p| seen |= p.color().is_some_and(|c| c.to_hex() == "#123456"));assert!(seen, "the colour is used by the design");}++ #[test]+ fn new_design_rename_delete_and_select_unused() {+ let mut s = Session::new();+ s.execute("file.new", &json!({"width": 800, "height": 800})).unwrap();+ let r = s.execute("shape.rectangle", &json!({"x": 0, "y": 0, "width": 10, "height": 10})).unwrap()["id"].as_u64().unwrap();+ s.execute("select.set", &json!({"ids": [r]})).unwrap();+ // New Design names it "New Design", numbered when that's taken.+ assert_eq!(s.execute("graph.design", &json!({"new": true})).unwrap()["name"], "New Design");+ assert_eq!(s.execute("graph.design", &json!({"new": true})).unwrap()["name"], "New Design 2");+ let id = graph(&mut s, "line");+ s.execute("graph.marker", &json!({"id": id.0, "design": "New Design"})).unwrap();+ let v = s.execute("graph.design", &json!({"selectUnused": true})).unwrap();+ assert_eq!(v["unused"], json!(["New Design 2"]));+ // Renaming a design the graph draws with: the graph follows, still drawing it.+ s.execute("graph.design", &json!({"rename": "New Design", "to": "Dot"})).unwrap();+ assert_eq!(spec(&s, id).series_markers, [Some("Dot".to_string()), Some("Dot".to_string())]);+ assert!(s.execute("graph.design", &json!({"rename": "Dot", "to": "New Design 2"})).is_err(), "taken");+ assert!(s.execute("graph.design", &json!({"rename": "Nope", "to": "X"})).is_err());+ // Delete several at once.+ s.execute("graph.design", &json!({"delete": ["Dot", "New Design 2"]})).unwrap();+ assert_eq!(s.execute("graph.design", &json!({})).unwrap()["designs"], json!([]));+ assert!(s.execute("graph.design", &json!({"delete": ["Nope"]})).is_err());+ }}diff --git a/crates/ui-egui/src/dialogs/graph_design.rs b/crates/ui-egui/src/dialogs/graph_design.rsindex 00188825d..19fe97bed 100644--- a/crates/ui-egui/src/dialogs/graph_design.rs+++ b/crates/ui-egui/src/dialogs/graph_design.rs@@ -1,11 +1,14 @@//! Object › Graph › Design… and Marker…: the document's graph designs in a list.//!-//! Graph Design: Save (Save Design) makes the selected art a design under the name typed, Paste (Paste Design) puts-//! a copy of the selected design into the document, Delete Design removes it (`graph.design`); each-//! runs at once and Close closes. Marker: the design (or the default marker) the selected graph-//! series draw their data points with; OK runs `graph.marker`.+//! Graph Design: the designs, a preview of the selected one, and New Design (the selected art as a+//! design named "New Design"), Rename (to the name typed), Delete Design (the selected designs),+//! Paste Design (a copy of the selected design into the document, selected, to edit) and Select+//! Unused (the designs no graph draws with), each run at once by `graph.design`; Close closes.+//! Marker: the design the selected graph series draw their data points with; OK runs+//! `graph.marker`.//!-//! Fields: `selected` (a design's name; empty for the default marker) and, in Graph Design, `name`.+//! Fields: `selected` (the selected designs' names; Marker: one name) and, in Graph Design, `name`+//! (the name Rename gives).use serde_json::{Value, json};@@ -17,6 +20,9 @@ use crate::{VectorcraftApp, widgets};pub const DESIGN: &str = "graphDesign";pub const MARKER: &str = "graphMarker";+/// The preview's size.+const PREVIEW: f32 = 120.0;+pub(super) const DESIGN_SPEC: DialogSpec = DialogSpec {heading: |_| tl!("Graph Design").into(),body: design_body,@@ -25,7 +31,7 @@ pub(super) const DESIGN_SPEC: DialogSpec = DialogSpec {Ok(Value::Null)},ok: None,- min_width: 380.0,+ min_width: 420.0,..DialogSpec::FORM};@@ -33,7 +39,11 @@ pub(super) const MARKER_SPEC: DialogSpec = DialogSpec {heading: |_| tl!("Graph Marker").into(),body: marker_body,confirm: |app, d| {- let design = Some(d.str("selected")).filter(|s| !s.is_empty());+ let design = d.str("selected");+ if design.is_empty() {+ app.ui.dialog = None;+ return Ok(Value::Null);+ }run_and_close(app, "graph.marker", json!({ "design": design }))},min_width: 300.0,@@ -43,15 +53,16 @@ pub(super) const MARKER_SPEC: DialogSpec = DialogSpec {/// Open Graph Design.pub fn open_design(app: &mut VectorcraftApp) -> Result<Value, String> {let names = names(app)?;- let first = names.first().cloned().unwrap_or_default();- app.ui.dialog = Some(Dialog::new(DESIGN, json!({ "selected": first, "name": "" })));+ let first: Vec<String> = names.first().cloned().into_iter().collect();+ let name = first.first().cloned().unwrap_or_default();+ app.ui.dialog = Some(Dialog::new(DESIGN, json!({ "selected": first, "name": name })));Ok(Value::Null)}-/// Open Marker for the selected graph series, on the design they draw with.+/// Open Marker for the selected graph series, on the design they draw with (else the first).pub fn open_marker(app: &mut VectorcraftApp) -> Result<Value, String> {let v = app.session.execute("graph.marker", &json!({})).map_err(|e| e.to_string())?;- let current = v["design"].as_str().unwrap_or_default();+ let current = v["design"].as_str().map(str::to_string).or_else(|| names(app).ok()?.first().cloned()).unwrap_or_default();app.ui.dialog = Some(Dialog::new(MARKER, json!({ "selected": current })));Ok(Value::Null)}@@ -62,55 +73,119 @@ fn names(app: &VectorcraftApp) -> Result<Vec<String>, String> {Ok(st.doc.graph_designs.iter().map(|d| d.name.clone()).collect())}-/// The designs as a list to pick from (with the default marker first when `default` is given).-fn list(ui: &mut egui::Ui, d: &mut Dialog, names: &[String], default: Option<&str>) {- widgets::list_box(ui, |ui| {- egui::ScrollArea::vertical().id_salt("graph-designs").min_scrolled_height(160.0).max_height(160.0).show(ui, |ui| {- ui.set_width(ui.available_width());- ui.set_min_height(160.0);- let entries = default.map(|label| ("", label)).into_iter().chain(names.iter().map(|n| (n.as_str(), n.as_str())));- for (value, label) in entries {- if ui.selectable_label(d.str("selected") == value, label).clicked() {- d.fields.insert("selected".into(), json!(value));- }+/// Graph Design's selected designs.+fn selected(d: &Dialog) -> Vec<String> {+ d.fields.get("selected").and_then(Value::as_array).map(|a| a.iter().filter_map(|v| v.as_str().map(str::to_string)).collect()).unwrap_or_default()+}++fn select(d: &mut Dialog, names: Vec<String>) {+ d.fields.insert("name".into(), json!(names.first().cloned().unwrap_or_default()));+ d.fields.insert("selected".into(), json!(names));+}++/// A design's art drawn in `r` (cached by the art's identity).+fn preview(ui: &egui::Ui, app: &VectorcraftApp, name: &str, r: egui::Rect) {+ use std::cell::RefCell;+ use std::collections::HashMap;+ thread_local! {+ static RENDERER: RefCell<vectorcraft_render::Renderer> = RefCell::new(vectorcraft_render::Renderer::new());+ static CACHE: crate::graphics::TexCache<HashMap<usize, egui::TextureHandle>> = crate::graphics::TexCache::default();+ }+ let Some(st) = app.session.active() else { return };+ let Some(art) = st.doc.graph_designs.iter().find(|x| x.name == name).map(|x| x.art.clone()) else { return };+ let key = std::sync::Arc::as_ptr(&art) as usize;+ let px = (r.width() * ui.ctx().pixels_per_point()).round() as u32;+ let tex = CACHE.with(|c| c.borrow().get(&key).cloned()).or_else(|| {+ let img = RENDERER.with(|rr| rr.borrow_mut().render_node_thumbnail(&st.doc, &art, px.max(16), Some([255, 255, 255, 255])))?;+ let color = egui::ColorImage::from_rgba_premultiplied([img.width as usize, img.height as usize], &img.pixels);+ let tex = ui.ctx().load_texture(format!("graph-design-{key}"), color, egui::TextureOptions::LINEAR);+ CACHE.with(|c| {+ let mut c = c.borrow_mut();+ if c.len() > 200 {+ c.clear();}+ c.insert(key, tex.clone());});+ Some(tex)});+ if let Some(t) = tex {+ ui.painter().image(t.id(), r, egui::Rect::from_min_max(egui::pos2(0.0, 0.0), egui::pos2(1.0, 1.0)), egui::Color32::WHITE);+ }}fn design_body(app: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) -> bool {let names = names(app).unwrap_or_default();- list(ui, d, &names, None);- let selected = d.str("selected").to_string();- let chosen = names.contains(&selected);- let mut run = None;- ui.add_space(6.0);- ui.horizontal(|ui| {- ui.spacing_mut().item_spacing.x = 4.0;- if ui.add_enabled_ui(chosen, |ui| widgets::flat_button(ui, tl!("Paste"), 64.0)).inner.clicked() {- run = Some(json!({ "paste": selected }));- }- if ui.add_enabled_ui(chosen, |ui| widgets::flat_button(ui, tl!("Delete"), 64.0)).inner.clicked() {- run = Some(json!({ "delete": selected }));- }- });- ui.add_space(10.0);+ let chosen: Vec<String> = selected(d).into_iter().filter(|n| names.contains(n)).collect();+ let one = chosen.first().cloned();let has_art = app.session.active().is_some_and(|st| !st.selection.is_empty());- ui.horizontal(|ui| {- widgets::dim_label(ui, tl!("Name:"));- form::text(ui, d, "name", 170.0);- let named = !d.str("name").trim().is_empty();- let save = ui.add_enabled_ui(has_art && named, |ui| widgets::flat_button(ui, tl!("Save"), 64.0)).inner;- if save.clicked() {- run = Some(json!({ "save": d.str("name") }));- }+ let mut run = None;+ ui.horizontal_top(|ui| {+ ui.vertical(|ui| {+ ui.set_width(220.0);+ // Click picks a design; Cmd/Ctrl-click adds or removes one.+ widgets::list_box(ui, |ui| {+ egui::ScrollArea::vertical().id_salt("graph-designs").min_scrolled_height(160.0).max_height(160.0).show(ui, |ui| {+ ui.set_width(ui.available_width());+ ui.set_min_height(160.0);+ for n in &names {+ if ui.selectable_label(chosen.contains(n), n.as_str()).clicked() {+ let mut now = chosen.clone();+ if ui.input(|i| i.modifiers.command) {+ if let Some(k) = now.iter().position(|x| x == n) {+ now.remove(k);+ } else {+ now.push(n.clone());+ }+ } else {+ now = vec![n.clone()];+ }+ select(d, now);+ }+ }+ });+ });+ ui.add_space(6.0);+ ui.horizontal(|ui| {+ widgets::dim_label(ui, tl!("Name:"));+ form::text(ui, d, "name", 150.0);+ });+ });+ ui.add_space(10.0);+ ui.vertical(|ui| {+ let (r, _) = ui.allocate_exact_size(egui::vec2(PREVIEW, PREVIEW), egui::Sense::hover());+ ui.painter().rect_stroke(r, 0.0, egui::Stroke::new(1.0, egui::Color32::from_gray(160)), egui::StrokeKind::Inside);+ if let Some(n) = &one {+ preview(ui, app, n, r.shrink(4.0));+ }+ ui.add_space(6.0);+ let button =+ |ui: &mut egui::Ui, on: bool, label: &str| ui.add_enabled_ui(on, |ui| widgets::flat_button(ui, label, PREVIEW)).inner.clicked();+ if button(ui, has_art, tl!("New Design")) {+ run = Some(json!({ "new": true }));+ }+ let to = d.str("name");+ if button(ui, chosen.len() == 1 && !to.trim().is_empty(), tl!("Rename")) {+ run = one.clone().map(|n| json!({ "rename": n, "to": to }));+ }+ if button(ui, !chosen.is_empty(), tl!("Delete Design")) {+ run = Some(json!({ "delete": chosen }));+ }+ if button(ui, chosen.len() == 1, tl!("Paste Design")) {+ run = one.clone().map(|n| json!({ "paste": n }));+ }+ if button(ui, !names.is_empty(), tl!("Select Unused")) {+ run = Some(json!({ "selectUnused": true }));+ }+ });});if let Some(p) = run {match app.run("graph.design", p.clone()) {Ok(r) => {if let Some(n) = r["name"].as_str() {- d.fields.insert("selected".into(), json!(n));- d.fields.insert("name".into(), json!(""));+ select(d, vec![n.to_string()]);+ }+ if let Some(unused) = r["unused"].as_array().filter(|_| p.get("selectUnused").is_some()) {+ select(d, unused.iter().filter_map(|v| v.as_str().map(str::to_string)).collect());}// Paste Design leaves the copy selected to edit, as the dialog closes.if p.get("paste").is_some() {@@ -125,7 +200,17 @@ fn design_body(app: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) -> bfn marker_body(app: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) -> bool {let names = names(app).unwrap_or_default();- list(ui, d, &names, Some(tl!("Default")));+ widgets::list_box(ui, |ui| {+ egui::ScrollArea::vertical().id_salt("graph-markers").min_scrolled_height(160.0).max_height(160.0).show(ui, |ui| {+ ui.set_width(ui.available_width());+ ui.set_min_height(160.0);+ for n in &names {+ if ui.selectable_label(d.str("selected") == *n, n.as_str()).clicked() {+ d.fields.insert("selected".into(), json!(n));+ }+ }+ });+ });false}@@ -143,16 +228,22 @@ mod tests {out.textures_delta.clear();}- #[test]- fn the_graph_menu_opens_both_dialogs_and_they_draw() {+ fn app_with_design() -> VectorcraftApp {let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());app.run("file.new", json!({"width": 400, "height": 300})).unwrap();let r = app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 10, "height": 10})).unwrap()["id"].as_u64().unwrap();app.run("select.set", json!({"ids": [r]})).unwrap();- app.run("graph.design", json!({"save": "Box"})).unwrap();+ app.run("graph.design", json!({"new": true})).unwrap();+ app+ }++ #[test]+ fn the_graph_menu_opens_both_dialogs_and_they_draw_with_a_preview() {+ let mut app = app_with_design();crate::menus::invoke(&mut app, "graph.design", json!({}));- assert_eq!(app.ui.dialog.as_ref().map(|d| d.kind.as_str()), Some(super::DESIGN));- assert_eq!(app.ui.dialog.as_ref().unwrap().str("selected"), "Box");+ let d = app.ui.dialog.as_ref().unwrap();+ assert_eq!(d.kind, super::DESIGN);+ assert_eq!((super::selected(d), d.str("name")), (vec!["New Design".to_string()], "New Design".to_string()));frame(&mut app);frame(&mut app);assert!(app.ui.dialog.is_some());@@ -169,31 +260,16 @@ mod tests {}#[test]- fn graph_design_saves_and_marker_applies_a_design() {- let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());- app.run("file.new", json!({"width": 400, "height": 300})).unwrap();- let r = app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 10, "height": 10})).unwrap()["id"].as_u64().unwrap();- app.run("select.set", json!({"ids": [r]})).unwrap();- super::open_design(&mut app).unwrap();- let mut d = app.ui.dialog.take().unwrap();- d.fields.insert("name".into(), json!("Box"));- // What Save Design runs.- app.run("graph.design", json!({"save": d.str("name")})).unwrap();+ fn marker_lists_the_designs_and_applies_the_one_picked() {+ let mut app = app_with_design();let g = app.run("graph.create", json!({"type": "line", "x": 100, "y": 100, "width": 200, "height": 100})).unwrap()["id"].as_u64().unwrap();app.run("select.set", json!({"ids": [g]})).unwrap();super::open_marker(&mut app).unwrap();- let mut d: Dialog = app.ui.dialog.take().unwrap();- assert_eq!(d.str("selected"), "", "the default marker");- d.fields.insert("selected".into(), json!("Box"));+ let d: Dialog = app.ui.dialog.take().unwrap();+ assert_eq!(d.str("selected"), "New Design", "the first design");(super::MARKER_SPEC.confirm)(&mut app, &d).unwrap();- let v = app.session.execute("graph.marker", &json!({})).unwrap();- assert_eq!(v["design"], "Box");- // Back to the default.+ assert_eq!(app.session.execute("graph.marker", &json!({})).unwrap()["design"], "New Design");super::open_marker(&mut app).unwrap();- let mut d: Dialog = app.ui.dialog.take().unwrap();- assert_eq!(d.str("selected"), "Box");- d.fields.insert("selected".into(), json!(""));- (super::MARKER_SPEC.confirm)(&mut app, &d).unwrap();- assert!(app.session.execute("graph.marker", &json!({})).unwrap()["design"].is_null());+ assert_eq!(app.ui.dialog.as_ref().unwrap().str("selected"), "New Design");}}diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsvindex 0398c73c1..a9a9a8cef 100644--- a/crates/ui-egui/src/i18n/cs.tsv+++ b/crates/ui-egui/src/i18n/cs.tsv@@ -18,6 +18,10 @@# tests): the product name, language names, OpenType, the built-in workspace names and the# bracketed perspective grid preset names. Keep placeholders, ellipses and the leading/trailing# spaces of fragments when editing.+ New Design Nový návrh+ Delete Design Odstranit návrh+ Paste Design Vložit návrh+ Select Unused Vybrat nepoužitéGlowing Edges… Zářící okraje…About VectorCraft O aplikaci VectorCraftAlign to Path Zarovnat k cestědiff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsvindex 1fdf248e6..3f156dbfc 100644--- a/crates/ui-egui/src/i18n/de.tsv+++ b/crates/ui-egui/src/i18n/de.tsv@@ -1106,6 +1106,10 @@Graph Type DiagrammtypGraph Design DiagrammdesignGraph Marker Diagrammmarkierung+ New Design Neues Design+ Delete Design Design löschen+ Paste Design Design einfügen+ Select Unused Nicht verwendete auswählenGraphic Style GrafikstilGraphic Style Libraries Grafikstil-BibliothekenGraphic Style Libraries Menu Menü „Grafikstil-Bibliotheken“diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsvindex 294ced0c7..c88884d5e 100644--- a/crates/ui-egui/src/i18n/es.tsv+++ b/crates/ui-egui/src/i18n/es.tsv@@ -1123,6 +1123,10 @@Graph Type Tipo de gráficoGraph Design Diseño de gráficoGraph Marker Marcador de gráfico+ New Design Nuevo diseño+ Delete Design Eliminar diseño+ Paste Design Pegar diseño+ Select Unused Seleccionar no utilizadosGraphic Style Estilo gráficoGraphic Style Libraries Bibliotecas de estilos gráficosGraphic Style Libraries Menu Menú Bibliotecas de estilos gráficosdiff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsvindex b308c9863..f593d3682 100644--- a/crates/ui-egui/src/i18n/fr.tsv+++ b/crates/ui-egui/src/i18n/fr.tsv@@ -1122,6 +1122,10 @@Graph Type Type de grapheGraph Design Conception de grapheGraph Marker Marqueur de graphe+ New Design Nouvelle conception+ Delete Design Supprimer la conception+ Paste Design Coller la conception+ Select Unused Sélectionner les éléments inutilisésGraphic Style Style graphiqueGraphic Style Libraries Bibliothèques de styles graphiquesGraphic Style Libraries Menu Menu Bibliothèques de styles graphiquesdiff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsvindex c2d1272ba..fe0301287 100644--- a/crates/ui-egui/src/i18n/it.tsv+++ b/crates/ui-egui/src/i18n/it.tsv@@ -1122,6 +1122,10 @@Graph Type Tipo di graficoGraph Design Design del graficoGraph Marker Indicatore del grafico+ New Design Nuovo design+ Delete Design Elimina design+ Paste Design Incolla design+ Select Unused Seleziona non utilizzatiGraphic Style Stile graficoGraphic Style Libraries Librerie stili graficiGraphic Style Libraries Menu Menu Librerie stili graficidiff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsvindex 51239814e..f9dff52e9 100644--- a/crates/ui-egui/src/i18n/ja.tsv+++ b/crates/ui-egui/src/i18n/ja.tsv@@ -2986,6 +2986,10 @@Graph Type グラフの種類Graph Design グラフのデザインGraph Marker グラフのマーカー+ New Design 新規デザイン+ Delete Design デザインを削除+ Paste Design デザインをペースト+ Select Unused 未使用を選択Graphic Style Libraries Menu グラフィックスタイルライブラリメニューGraphics グラフィックスGreek & Cyrillic ギリシャ文字とキリル文字diff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsvindex 27bd6417e..2aa71419c 100644--- a/crates/ui-egui/src/i18n/ru.tsv+++ b/crates/ui-egui/src/i18n/ru.tsv@@ -1120,6 +1120,10 @@Graph Type Тип диаграммыGraph Design Дизайн диаграммыGraph Marker Маркер диаграммы+ New Design Новый дизайн+ Delete Design Удалить дизайн+ Paste Design Вставить дизайн+ Select Unused Выбрать неиспользуемыеGraphic Style Графический стильGraphic Style Libraries Библиотеки графических стилейGraphic Style Libraries Menu Меню «Библиотеки графических стилей»diff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsvindex ace68cfe9..0de258502 100644--- a/crates/ui-egui/src/i18n/uk.tsv+++ b/crates/ui-egui/src/i18n/uk.tsv@@ -1116,6 +1116,10 @@Graph Type Тип діаграмиGraph Design Дизайн діаграмиGraph Marker Маркер діаграми+ New Design Новий дизайн+ Delete Design Видалити дизайн+ Paste Design Вставити дизайн+ Select Unused Вибрати невикористаніGraphic Style Графічний стильGraphic Style Libraries Бібліотеки графічних стилівGraphic Style Libraries Menu Меню "Бібліотеки графічних стилів"diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsvindex 04bfa3559..d68a27316 100644--- a/crates/ui-egui/src/i18n/zh-hans.tsv+++ b/crates/ui-egui/src/i18n/zh-hans.tsv@@ -1073,6 +1073,10 @@Graph Type 图表类型Graph Design 图表设计Graph Marker 图表标记+ New Design 新建设计+ Delete Design 删除设计+ Paste Design 粘贴设计+ Select Unused 选择未使用项Graphic Style 图形样式Graphic Style Libraries 图形样式库Graphic Style Libraries Menu 图形样式库菜单diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsvindex 7cf089f9b..7d5f613c3 100644--- a/crates/ui-egui/src/i18n/zh-hant.tsv+++ b/crates/ui-egui/src/i18n/zh-hant.tsv@@ -1097,6 +1097,10 @@Graph Type 圖表類型Graph Design 圖表設計Graph Marker 圖表標記+ New Design 新增設計+ Delete Design 刪除設計+ Paste Design 貼上設計+ Select Unused 選取未使用項目Graphic Style 繪圖樣式Graphic Style Libraries 繪圖樣式資料庫Graphic Style Libraries Menu 繪圖樣式資料庫選單diff --git a/docs/target-app-parity.md b/docs/target-app-parity.mdindex 8151249e6..7468d7419 100644--- a/docs/target-app-parity.md+++ b/docs/target-app-parity.md@@ -414,7 +414,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur- **Live Corners:** drag a live rectangle's corner widgets (Selection or Direct Selection) to round all corners, with a radius readout; with Direct Selection, select corner anchors to show and round just those corners (#381). Each corner keeps its own radius and kind (Round, Inverted Round, Chamfer): Alt-click a widget to cycle the kind, double-click it for the Corners dialog, and the Properties and Transform radius fields set the selected corners (`object.setLiveShape {corners, radius, kind}`). Corners stay circular when the rectangle is scaled unevenly or along its own sides when rotated (the radius keeps its size, or scales by the mean scale with Scale Corners on); only a shear distorts them. On a rectangle that isn't square every corner is the same circle: a radius past half the shorter side stops there for all of them, the widgets sit on the corners as drawn and turn the edited corners red at that limit, CSS export writes the drawn radii, and rectangles saved stretched by older versions get circular corners when their corners are next set (#442). Live Corners work on any path's corners too, as on a rectangle's (#511): a star's, a live polygon's (which also shows them to the Selection tool, has a Corner Radius field in the Properties and Transform panels and keeps its radius as its sides change) and a pen path's, wherever two sides meet at an angle at an anchor that isn't smooth: curved sides too, trimmed to what the cut leaves of them (#1144). Direct Selection shows the widgets of every corner, or of the corners holding selected anchors; each corner is a circle tangent to both sides, drawn no larger than takes its cut halfway along its shorter side; a path keeps its uncut outline so its corners stay editable, and the same command, dialog, angle preference and View › Hide Corner Widget apply.- **Pen:** Alt pressed in the middle of dragging out an anchor splits its handles and keeps the curve already shaped into it (only the outgoing handle follows the pointer); Space held while dragging out an anchor moves it, handles and all. A press on the first anchor of the path being drawn closes it whatever the drag then does: the drag shapes the closing curve (symmetric handles, Alt breaks them) and the release closes the path wherever it ends (#501). Clicking the last anchor of the path being drawn retracts its outgoing handle (convert cursor), and dragging from it pulls out a new one on its own. Auto Add/Delete: over a selected path, a click on a segment adds an anchor and a click on an anchor deletes it (add and delete cursors); Shift held, or Preferences › General › Disable Auto Add/Delete, starts a new path instead. Alt held over a handle end or an anchor of a selected path (the one being drawn too) works as the Anchor Point tool, with its convert cursor: dragging a handle moves it alone, clicking a smooth anchor makes it a corner, dragging an anchor pulls out new symmetric handles, dragging a segment reshapes it; drawing then goes on. Cmd (Ctrl) held drags with the selection tool chosen last, Direct Selection until one is (handles, anchors and segments of the path being drawn or another), and the Pen then goes on drawing its path while that stays selected; the pointer shows that tool's while Cmd is held. The same holds for agents (`pointer_gesture` with `mods.cmd`), as the borrowing now lives in the engine (#494).- **Path editing (#494):** the handles shown are the handles that drag: Direct Selection drags those of a path selected as a whole (as the Pen leaves it), the Anchor Point tool and Pen+Alt no longer grab handles that Show handles when multiple anchors are selected hides, a handle shorter than the tolerance leaves its anchor to be picked, and the anchor tools pick within Selection & Anchor Display › Tolerance. A dragged segment keeps a smooth anchor at either end smooth. With Direct Selection, the Pen, the Curvature and the anchor tools, a path selected as a whole shows all its anchors selected, and the Control bar and the Properties panel offer Convert (corner, smooth) for them too; Remove and Cut wait for anchors direct-selected (#504). A handle drag gathers its snap targets once per drag (it took 21 ms per pointer move on a 20,000-path document, now 1 ms; `vectorcraft-cli perf` measures handle and segment drags on a 5,000-anchor path).- - **Graphs:** Column, Stacked Column, Bar, Stacked Bar, Line, Area, Scatter, Pie and Radar graph tools with Graph Data and Graph Type. A series starts in greyscale; Group Selection's fill and stroke are kept separately on the graph and reapplied when its data, type or size changes, and through save, open and undo. Graph Type's Override Calculated Values (both `axisMin` and `axisMax`) uses exactly that value-axis range, split into the tick count (5 when automatic). Line graphs take Edge-to-Edge Lines (off by default: the points sit at the centres of their categories; graphs saved before the option keep their edge-to-edge lines), and radar graphs follow Mark Data Points and Connect Data Points. Blank cells (an empty CSV cell or `null`) are values left out, not zeros: columns, bars and stacked segments skip them, lines and scatter lines break around them and the value axis ignores them, while area, pie and radar draw them as 0; a number in straight quotes is a label, and the data window writes it back quoted. Graph types combine: Graph Type on series picked with Group Selection (or `series` indexes) draws them as their own type, with column, stacked column, line and area mixing on the vertical value axis and bar and stacked bar on the horizontal one; stacked columns take one slot of the cluster, lines draw in front of columns and areas behind. The value axis goes on the left, the right or both sides (column, stacked column, line, area and scatter graphs; bar graphs keep theirs along the bottom), and Separate Scales gives the series assigned to the right axis a scale of their own with its own tick values. Each value axis takes tick marks of no, short or full (across the plot) length and a count per division, and a prefix and suffix for its numbers; the category axis takes tick marks too (none by default), at or between its labels. Graph designs: Object › Graph › Design saves the selected art as a named design, pastes a copy back to edit and deletes it, and Marker draws the data points and legend swatches of line, scatter and radar series with a design, scaled so its backmost object fills the default marker's square. Column designs remain open.+ - **Graphs:** Column, Stacked Column, Bar, Stacked Bar, Line, Area, Scatter, Pie and Radar graph tools with Graph Data and Graph Type. A series starts in greyscale; Group Selection's fill and stroke are kept separately on the graph and reapplied when its data, type or size changes, and through save, open and undo. Graph Type's Override Calculated Values (both `axisMin` and `axisMax`) uses exactly that value-axis range, split into the tick count (5 when automatic). Line graphs take Edge-to-Edge Lines (off by default: the points sit at the centres of their categories; graphs saved before the option keep their edge-to-edge lines), and radar graphs follow Mark Data Points and Connect Data Points. Blank cells (an empty CSV cell or `null`) are values left out, not zeros: columns, bars and stacked segments skip them, lines and scatter lines break around them and the value axis ignores them, while area, pie and radar draw them as 0; a number in straight quotes is a label, and the data window writes it back quoted. Graph types combine: Graph Type on series picked with Group Selection (or `series` indexes) draws them as their own type, with column, stacked column, line and area mixing on the vertical value axis and bar and stacked bar on the horizontal one; stacked columns take one slot of the cluster, lines draw in front of columns and areas behind. The value axis goes on the left, the right or both sides (column, stacked column, line, area and scatter graphs; bar graphs keep theirs along the bottom), and Separate Scales gives the series assigned to the right axis a scale of their own with its own tick values. Each value axis takes tick marks of no, short or full (across the plot) length and a count per division, and a prefix and suffix for its numbers; the category axis takes tick marks too (none by default), at or between its labels. Graph designs: Object › Graph › Design lists the designs with a preview of the selected one, and New Design (the selected art), Rename, Delete Design, Paste Design (a copy back to edit) and Select Unused, and Marker draws the data points and legend swatches of line, scatter and radar series with a design, scaled so its backmost object fills the default marker's square. Column designs remain open.- **Other:** Eyedropper, Gradient annotator, Artboard (Alt-drag duplicates an artboard, and its art with Move/Copy Artwork with Artboard on; Copy, Cut and Paste take the artboard with its art, Paste right of the last artboard, Paste in Place where it was, into this or another document, #446; Object › Artboards › Rearrange All Artboards lays them out in a grid by row or by column, in one row or one column, left to right or right to left, from the menu, the Artboards panel or Properties' Rearrange All, #681; Scale Artwork with Artboard, in the Control bar and Properties beside Move Artwork with Artboard, resizes the artboard proportionally with the art fully inside it and its guides, strokes and corners per the Scale preferences, #602), Measure, Type, Hand, Zoom, Rotate View.- **Editing type:** double-clicking type with a selection tool switches to the Type tool with the caret where it was clicked.- **Temporary tools:** Cmd with any other tool drags with the selection tool used last (Selection, Direct Selection or Group Selection). Held Space pans and Cmd+Space zooms (Cmd+Alt+Space out) whatever the tool.