Skip to content

VectorCraft: An open-source, vector art tool written by scratch in pure Rust

Merge wp/B1

bflatasticefc0ac31d909
diff --cc crates/ui-egui/src/dialogs/mod.rs
index 91e55b372,2f50d3978..640e02fd2
--- a/crates/ui-egui/src/dialogs/mod.rs
+++ b/crates/ui-egui/src/dialogs/mod.rs
@@@ -15,9 -14,8 +15,10 @@@ mod document_setup
mod effect;
mod export_for_screens;
mod form;
+pub mod new_color_group;
+ mod gradient_stop;
mod new_document;
+pub mod new_swatch;
mod path_ops;
mod recolor;
mod save_changes;
@@@ -131,10 -128,7 +132,11 @@@ registry!
Shortcuts: ["shortcuts"] => DialogSpec::window(crate::shortcut_editor::show, |app, _| crate::shortcut_editor::confirm(app)),
Workspaces: ["newWorkspace", "manageWorkspaces"] => DialogSpec::window(crate::workspaces::show, |app, _| crate::workspaces::confirm(app)),
FindFont: ["findFont"] => DialogSpec::window(crate::find_font::show, |app, _| crate::find_font::confirm(app)),
+ SwatchOptions: [swatch_options::KIND] => swatch_options::SPEC,
+ Confirm: [confirm::KIND] => confirm::SPEC,
+ NewSwatch: [new_swatch::KIND] => new_swatch::SPEC,
+ NewColorGroup: [new_color_group::KIND] => new_color_group::SPEC,
+ GradientStop: ["gradientStop"] => gradient_stop::SPEC,
}
/// The spec for a `Dialog::kind` ([`DialogSpec::FORM`] when unregistered).
diff --cc crates/ui-egui/src/panels/mod.rs
index b6f319a3e,523e007de..f5772de16
--- a/crates/ui-egui/src/panels/mod.rs
+++ b/crates/ui-egui/src/panels/mod.rs
@@@ -266,26 -266,16 +266,16 @@@ pub(crate) fn recent_colors_row(app: &m
}
/// A colour as command JSON, keeping its model.
- pub(crate) fn color_json(c: &Color) -> Value {
- match *c {
- Color::Rgb { r, g, b } => json!([r, g, b]),
- Color::Cmyk { c, m, y, k } => json!({"c": c, "m": m, "y": y, "k": k}),
- Color::Gray { k } => json!({"gray": k}),
- }
- }
+ pub(crate) use vectorcraft_tools::params::color_json;
- /// Paint as command params (`{color}`, `{swatch}`, `{none}`, `{gradient}` or `{pattern}`).
-/// Paint as command params (`{color}`, `{none}` or `{gradient}`, lossless for gradients).
++/// Paint as command params (`{color}`, `{swatch}`, `{none}`, `{gradient}` (lossless) or `{pattern}`).
pub(crate) fn paint_params(p: &Paint) -> Value {
match p {
Paint::None => json!({"none": true}),
Paint::Solid { swatch: Some(n), .. } => json!({"swatch": n}),
Paint::Solid { color, .. } => json!({"color": color_json(color)}),
- Paint::Gradient(g) => json!({"gradient": {
- "kind": g.gradient.kind.label().to_lowercase(),
- "angle": g.angle,
- "stops": g.gradient.stops.iter().map(|s| json!({"offset": s.offset, "color": color_json(&s.color), "opacity": s.opacity})).collect::<Vec<_>>()
- }}),
+ Paint::Gradient(g) => json!({"gradient": vectorcraft_tools::params::gradient_params(g)}),
- Paint::Pattern { .. } => json!({"none": true}),
+ Paint::Pattern { pattern, .. } => json!({"pattern": pattern}),
}
}
@@@ -321,6 -311,6 +311,7 @@@ mod tests
let p = paint_params(&g);
assert_eq!(p["gradient"]["kind"], "linear");
assert_eq!(p["gradient"]["stops"].as_array().unwrap().len(), 2);
+ assert_eq!(paint_params(&vectorcraft_doc::pattern::pattern_paint("Dots")), json!({"pattern": "Dots"}));
+ assert_eq!(p["gradient"]["stops"][0]["midpoint"], json!(0.5));
}
}
diff --cc docs/control-protocol.md
index 394cca9bf,ab1ea821b..7f9934696
--- a/docs/control-protocol.md
+++ b/docs/control-protocol.md
@@@ -19,17 -19,4 +19,18 @@@
| `ui.render` | `{path?, scale?}` | render the artboard headlessly (PNG) |
| `ui.resize` / `ui.focus` | | |
| `app.open` / `app.save` / `app.export` / `app.quit` | `{path}` / `{path?}` / `{path?, format?, artboard?, range?, scale?, …}` | `app.open` reads every format `document.open` reads (see `document.formats`). `app.export` encodes through the engine's `document.export` (same options; the document keeps its path) and writes `path` through the host; without `path` it returns `{dataBase64, format, bytes}`, as headless mode does. `app.quit`, `file.close` and `file.closeAll` first open a `saveChanges` dialog for each modified document (they return `{"pending": "saveChanges"}`): `ui.dialog.confirm` saves, `ui.dialog.set {field: "discard", value: true}` then confirm discards, `ui.dialog.cancel` cancels the whole close or quit |
+ | `ui.dialog.*` on `gradientStop` | `{field: "color" \| "opacity" \| "location", value}` | double-clicking a stop on the Gradient tool's annotator opens its popover (fields `index`, `x`, `y`, `tab`); set `color` (hex), `opacity` or `location` (percentages) and `ui.dialog.confirm` to apply them to the selected stop. `gradient.selectStop {index}` picks the stop the annotator, the panels and Delete/←/→ (`ui.key`) act on |
+
+Swatch editors: `engine.execute` with `ui.swatchOptions {name}` opens the `swatchOptions` dialog for a colour swatch
+(fields `name`, `spot`, `global`, `mode`: `gray`/`rgb`/`hsb`/`cmyk`/`web`, `color`: `"#rrggbb"` or a colour object,
+`preview`), which previews on the canvas while open; `ui.dialog.confirm` applies it with `swatch.edit` as one undo
+step and `ui.dialog.cancel` rolls the preview back. Gradient swatches open the Gradient panel and pattern swatches
+pattern editing instead.
+
+Confirmations: deleting swatches from the Swatches panel opens a `confirm` dialog (fields `message`, `detail`);
+`ui.dialog.confirm` runs the command it asks about (here `swatch.delete`) and `ui.dialog.cancel` drops it.
+
+New swatches and colour groups: `ui.newSwatch {spot?, group?}` opens the `newSwatch` dialog prefilled from the active
+fill or stroke (fields as in `swatchOptions` plus `group`; a gradient or pattern only takes `name`) and
+`ui.newColorGroup {swatches?}` opens `newColorGroup` (fields `name`, `fromArtwork`, `toGlobal`, `includeTints`,
+`swatches`); `ui.dialog.confirm` runs `swatch.new` / `swatch.newGroup`.