Object › Path › Offset Path (and `ui.menuDialog` for it) opens on the offset, joins and miter limit of the last time OK was pressed, as in Illustrator, instead of 10 pt and Miter every time. The values are kept with the rest of the remembered dialog options. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
52 lines
2.0 KiB
Rust
52 lines
2.0 KiB
Rust
//! Path dialogs: Average, Offset Path (with Preview), Simplify and Split Into Grid.
|
|
|
|
use serde_json::{Value, json};
|
|
|
|
use super::{DialogSpec, form, run_and_close};
|
|
use crate::VectorcraftApp;
|
|
use crate::state::Dialog;
|
|
|
|
pub(super) const SPEC: DialogSpec = DialogSpec { heading: |d| title(&d.kind).into(), body, confirm, preview: true, ..DialogSpec::FORM };
|
|
|
|
fn title(kind: &str) -> &'static str {
|
|
match kind {
|
|
"average" => tl!("Average"),
|
|
"offsetPath" => tl!("Offset Path"),
|
|
"simplify" => tl!("Simplify"),
|
|
_ => tl!("Split Into Grid"),
|
|
}
|
|
}
|
|
|
|
/// The command the dialog runs and its parameters.
|
|
fn command(d: &Dialog) -> (&'static str, Value) {
|
|
match d.kind.as_str() {
|
|
"average" => ("path.average", json!({"axis": d.str("axis")})),
|
|
"offsetPath" => {
|
|
("object.path.offsetPath", json!({"offset": d.f64("offset", 10.0), "joins": d.str("joins"), "miterLimit": d.f64("miterLimit", 4.0)}))
|
|
}
|
|
"simplify" => ("object.path.simplify", json!({"tolerance": d.f64("tolerance", 1.0)})),
|
|
_ => ("object.path.splitIntoGrid", json!({"rows": d.f64("rows", 2.0), "columns": d.f64("columns", 2.0), "gutter": d.f64("gutter", 12.0)})),
|
|
}
|
|
}
|
|
|
|
fn body(app: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) -> bool {
|
|
form::grid(ui, d, app.session.general_unit());
|
|
if d.kind == "offsetPath" {
|
|
let (id, params) = command(d);
|
|
form::preview(app, ui, d, "Offset Path", id, params);
|
|
}
|
|
false
|
|
}
|
|
|
|
fn confirm(app: &mut VectorcraftApp, d: &Dialog) -> Result<Value, String> {
|
|
let (id, params) = command(d);
|
|
if d.kind != "offsetPath" {
|
|
return run_and_close(app, id, params);
|
|
}
|
|
let r = form::commit_preview(app, id, params)?;
|
|
// The fields as the dialog held them, so they show as typed when it opens again.
|
|
let kept = ["offset", "joins", "miterLimit"].into_iter().filter_map(|k| Some((k.to_string(), d.fields.get(k)?.clone())));
|
|
app.ui.offset_path = Value::Object(kept.collect());
|
|
Ok(r)
|
|
}
|