Transform: a line length too small to move its ends records no undo step, and both Line fields send together

object.setLiveShape reports no change when the rounded ends stay where they
are. The Line Length and Line Angle fields send every edited value in one
call, so a length committed in the same frame as an angle step is applied.
This commit is contained in:
dotCooCoo
2026-11-17 11:18:57 -08:00
parent cd4e9e9506
commit a533aec0fe
3 changed files with 13 additions and 7 deletions
+1 -1
View File
@@ -120,7 +120,7 @@ fn line_edit(l: &LiveShape, len: Option<f64>, angle: Option<f64>) -> Option<Live
new.set_line_angle(a);
changed = true;
}
changed.then_some(new)
(changed && new != *l).then_some(new)
}
pub(super) fn set_live_shape(s: &mut Session, p: &Value) -> Result<Value> {
+6
View File
@@ -612,6 +612,12 @@ fn a_line_takes_its_length_and_angle() {
run(&mut s, json!({"ids": [speck.0], "lineLength": 1e-12}));
assert_eq!(steps(&s), n + 1, "a length of 1e-12 pt is a change");
assert!(ends(&s, speck).2 > 20.0, "{:?}", ends(&s, speck));
// A length so short that the rounded ends do not move records no undo step.
let dust = line(&mut s, (20.0, 20.0), (20.0, 20.0));
let n = steps(&s);
run(&mut s, json!({"ids": [dust.0], "lineLength": 1e-20}));
assert_eq!(steps(&s), n, "a length of 1e-20 pt changes nothing");
near(ends(&s, dust), (20.0, 20.0, 20.0, 20.0));
// Other live shapes ignore the line params.
let rect = NodeId(s.execute("shape.rectangle", &json!({"x": 0, "y": 0, "width": 10, "height": 10})).unwrap()["id"].as_u64().unwrap());
let n = steps(&s);
+6 -6
View File
@@ -462,22 +462,22 @@ pub(crate) fn line_rows(app: &mut VectorcraftApp, ui: &mut Ui, live: &LiveShape,
}
let (units, fw) = (app.session.general_unit(), super::field_width(ui));
widgets::subheader(ui, tl!("Line Properties:"));
// The `object.setLiveShape` param an edited field sets.
let mut set = None;
// The `object.setLiveShape` params the edited fields set, all sent in one call.
let mut set = serde_json::Map::new();
egui::Grid::new((id, "grid")).num_columns(2).spacing([6.0, 6.0]).show(ui, |ui| {
widgets::dim_label(ui, tl!("Line Length:"));
if let Some(l) = widgets::num_field_named(ui, (id, "length"), Some(tl!("Line Length:")), live.line_length(), units, fw) {
set = Some(("lineLength", json!(l)));
set.insert("lineLength".into(), json!(l));
}
ui.end_row();
widgets::dim_label(ui, tl!("Line Angle:"));
if let Some(a) = widgets::plain_field_named(ui, (id, "angle"), Some(tl!("Line Angle:")), live.line_angle().unwrap_or(0.0), "°", 1, fw) {
set = Some(("lineAngle", json!(a)));
set.insert("lineAngle".into(), json!(a));
}
ui.end_row();
});
if let Some((key, v)) = set
&& let Err(e) = app.run("object.setLiveShape", json!({ key: v }))
if !set.is_empty()
&& let Err(e) = app.run("object.setLiveShape", serde_json::Value::Object(set))
{
app.status(e);
}