mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-21 09:54:09 +01:00
Pathfinder: Pathfinder Options opens a scaled precision at its bound
A Pathfinder effect whose precision Scale Strokes & Effects took past its range opened Pathfinder Options with the stored value, and OK sent it to `effect.setParams`, which refuses it. The dialog now opens at the bound the effect evaluates at. OK keeps the stored precision unless Precision is set, in the field or with `ui.dialog.set`, so OK with nothing changed records no undo step. `docs/mcp.md` describes the scaled precision.
This commit is contained in:
1 parent
ad3c0f0127
commit
c3d0254901
4 files changed
+75
-5
No files matched your search
@@ -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 Pathfinder
|
||||
/// effect's precision set this way replaces a stored precision out of range, the bound included.
|
||||
pub fn set_field(d: &mut Dialog, field: String, value: Value) {
|
||||
if d.kind == brush_options::KIND {
|
||||
brush_art_options::note_set(d, &field);
|
||||
@@ -614,6 +615,11 @@ pub fn set_field(d: &mut Dialog, field: String, value: Value) {
|
||||
if d.kind == new_document::KIND || new_document::popup_open(d) {
|
||||
new_document::note_set(d, &field);
|
||||
}
|
||||
// A Pathfinder effect's precision set this way replaces a stored one out of range, as one
|
||||
// entered in its field does.
|
||||
if d.kind == "effect" && field == "precision" {
|
||||
d.fields.remove(effect::OPENED_PRECISION);
|
||||
}
|
||||
let dxf = (d.kind == dxf_options::KIND).then(|| field.clone());
|
||||
let graph = (d.kind == graph_data::KIND).then(|| field.clone());
|
||||
d.fields.insert(field, value);
|
||||
|
||||
@@ -175,7 +175,10 @@ fn has_only_pathfinder_options(id: &str) -> bool {
|
||||
|
||||
/// A Pathfinder effect's Pathfinder Options in `fields`, where they are missing: for a new effect
|
||||
/// (`fresh`) the Pathfinder panel's current options, as `effect.apply` takes them; for an applied
|
||||
/// one saved without them, the values it evaluates with.
|
||||
/// one saved without them, the values it evaluates with. A precision out of range (one that Scale
|
||||
/// Strokes & Effects took past it) or not a number opens at the value it evaluates with, kept in
|
||||
/// `__openedPrecision`: OK leaves that value out unless the user enters a precision, so the stored
|
||||
/// one stays until the user changes it.
|
||||
fn fill_pathfinder_options(app: &VectorcraftApp, id: &str, fields: &mut Map<String, Value>, fresh: bool) {
|
||||
if !vectorcraft_effects::takes_pathfinder_options(id) {
|
||||
return;
|
||||
@@ -185,8 +188,17 @@ fn fill_pathfinder_options(app: &VectorcraftApp, id: &str, fields: &mut Map<Stri
|
||||
for (key, v) in options.as_object().into_iter().flatten() {
|
||||
fields.entry(key.clone()).or_insert_with(|| v.clone());
|
||||
}
|
||||
if fields.get("precision").is_some_and(|v| !v.as_f64().is_some_and(|p| vectorcraft_effects::PATHFINDER_EFFECT_PRECISION.contains(&p))) {
|
||||
let evaluated = vectorcraft_effects::PathfinderEffectOptions::from_params(&json!({"precision": fields["precision"]})).precision;
|
||||
fields.insert("precision".into(), json!(evaluated));
|
||||
fields.insert(OPENED_PRECISION.into(), json!(evaluated));
|
||||
}
|
||||
}
|
||||
|
||||
/// The precision a Pathfinder effect's dialog opened at in place of a stored one out of range,
|
||||
/// until the user enters a precision.
|
||||
pub(super) const OPENED_PRECISION: &str = "__openedPrecision";
|
||||
|
||||
/// A Pathfinder effect's fields: Soft Mix's Mixing Rate as the other effects show their
|
||||
/// parameters, then the Pathfinder Options. Returns whether the values changed.
|
||||
fn pathfinder_fields(ui: &mut egui::Ui, d: &mut Dialog, id: &str, unit: vectorcraft_doc::Unit) -> bool {
|
||||
@@ -1075,6 +1087,12 @@ fn command(d: &Dialog) -> (&'static str, Value) {
|
||||
p["index"] = index.clone();
|
||||
p["item"] = item.unwrap_or(Value::Null);
|
||||
p["params"] = params;
|
||||
// A precision the dialog opened at in place of a stored one out of range keeps the stored one.
|
||||
if let (Some(opened), Some(Value::Object(m))) = (d.fields.get(OPENED_PRECISION).and_then(Value::as_f64), p.get_mut("params"))
|
||||
&& m.get("precision").and_then(Value::as_f64) == Some(opened)
|
||||
{
|
||||
m.remove("precision");
|
||||
}
|
||||
let id = d.str("__effect");
|
||||
// Each target keeps the map its own Warp draws with: the dialog's `version` is the first
|
||||
// target's.
|
||||
@@ -1611,6 +1629,47 @@ mod tests {
|
||||
assert_eq!(app.ui.dialog.as_ref().unwrap().fields["removeUnpainted"], json!(true));
|
||||
}
|
||||
|
||||
/// A Pathfinder effect whose precision Scale Strokes & Effects took past the range opens at the
|
||||
/// bound it evaluates at. OK with nothing changed records no step, OK with another option
|
||||
/// changed keeps the stored precision, and a precision the user sets replaces it.
|
||||
#[test]
|
||||
fn a_pathfinder_precision_scaled_past_its_range_opens_at_the_bound_and_ok_keeps_it() {
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
|
||||
app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 50, "height": 50})).unwrap();
|
||||
app.run("shape.rectangle", json!({"x": 40, "y": 40, "width": 50, "height": 50})).unwrap();
|
||||
app.run("select.all", json!({})).unwrap();
|
||||
app.run("effect.apply", json!({"effect": "pathfinder.add", "params": {"precision": 8}})).unwrap();
|
||||
let g = app.session.doc().unwrap().selection.objects[0];
|
||||
app.run("object.scale", json!({"sx": 200, "strokes": true})).unwrap();
|
||||
let params = |app: &VectorcraftApp| app.session.doc().unwrap().doc.node(g).unwrap().appearance.effects[0].params.clone();
|
||||
assert_eq!(params(&app)["precision"].as_f64(), Some(16.0));
|
||||
let steps = |app: &VectorcraftApp| app.session.doc().unwrap().history.undo.len();
|
||||
let open = |app: &mut VectorcraftApp| {
|
||||
app.run("effect.dialog", json!({"effect": "pathfinder.add", "index": 0, "item": null})).unwrap();
|
||||
assert_eq!(app.ui.dialog.as_ref().unwrap().fields["precision"].as_f64(), Some(10.0));
|
||||
};
|
||||
open(&mut app);
|
||||
let before = steps(&app);
|
||||
super::super::confirm(&mut app).unwrap();
|
||||
assert_eq!((steps(&app), params(&app)["precision"].as_f64()), (before, Some(16.0)), "OK with nothing changed");
|
||||
open(&mut app);
|
||||
app.ui.dialog.as_mut().unwrap().fields.insert("removeRedundantPoints".into(), json!(true));
|
||||
super::super::confirm(&mut app).unwrap();
|
||||
assert_eq!((params(&app)["precision"].as_f64(), ¶ms(&app)["removeRedundantPoints"]), (Some(16.0), &json!(true)));
|
||||
open(&mut app);
|
||||
app.ui.dialog.as_mut().unwrap().fields.insert("precision".into(), json!(2.5));
|
||||
super::super::confirm(&mut app).unwrap();
|
||||
assert_eq!(params(&app)["precision"].as_f64(), Some(2.5));
|
||||
// Setting the bound itself (`ui.dialog.set`, or the Precision field) replaces a stored value past it.
|
||||
app.run("object.scale", json!({"sx": 800, "strokes": true})).unwrap();
|
||||
assert_eq!(params(&app)["precision"].as_f64(), Some(20.0));
|
||||
open(&mut app);
|
||||
super::super::set_field(app.ui.dialog.as_mut().unwrap(), "precision".into(), json!(10.0));
|
||||
super::super::confirm(&mut app).unwrap();
|
||||
assert_eq!(params(&app)["precision"].as_f64(), Some(10.0));
|
||||
}
|
||||
|
||||
/// A Radial Blur whose saved Blur Center lies outside the object's bounds (a document written
|
||||
/// by hand or by another build) opens with the center at the nearest edge, and OK stores that
|
||||
/// edge instead of sending the saved value, which `effect.setParams` refuses.
|
||||
|
||||
@@ -68,6 +68,8 @@ pub(super) fn fields(ui: &mut egui::Ui, d: &mut Dialog) {
|
||||
let v = d.f64("precision", vectorcraft_engine::PathfinderOptions::default().precision);
|
||||
if let Some(v) = widgets::range_field(ui, "pathfinder-precision", v, range, " pt", 3, 80.0) {
|
||||
d.fields.insert("precision".into(), json!(v));
|
||||
// An entered precision replaces a stored one out of range, the bound included.
|
||||
d.fields.remove(super::effect::OPENED_PRECISION);
|
||||
}
|
||||
ui.end_row();
|
||||
});
|
||||
|
||||
+6
-3
@@ -5338,9 +5338,12 @@ fills the ones `params` leave out from the current Pathfinder Options, and the v
|
||||
saved without them evaluates with precision 0.01 and both switches off, as before effects kept them. `effect.setParams
|
||||
{index, params: {precision?, removeRedundantPoints?, removeUnpainted?}}` edits them as one undo step; values the
|
||||
effect already evaluates with record no undo step and return `{ids: []}`. A precision out of range, or a switch that
|
||||
isn't true or false, is refused with an error and nothing changes. In the app, a Pathfinder effect's name or a
|
||||
double-click on its row in the Appearance panel opens Pathfinder Options for it (Soft Mix's dialog also has Mixing
|
||||
Rate).
|
||||
isn't true or false, is refused with an error and nothing changes. Scale Strokes & Effects scales `precision` with the
|
||||
object (0.01 when it is missing), and the stored value may then pass 10 or fall below 0.001; the effect evaluates at
|
||||
the nearest bound, and setting a precision that differs from the stored one is an edit, the bound included. In the app,
|
||||
a Pathfinder effect's name or a double-click on its row in the Appearance panel opens Pathfinder Options for it (Soft
|
||||
Mix's dialog also has Mixing Rate). A stored precision out of range opens at the bound, and OK keeps the stored value
|
||||
unless Precision is set.
|
||||
|
||||
```json
|
||||
{"name":"run_command","arguments":{"command":"effect.setParams","params":{"index":0,"params":{"precision":1,"removeRedundantPoints":true}}}}
|
||||
|
||||
Reference in new issue
Block a user