Flare: a click on a selected flare's handle opens the dialog again

A click without a drag on the selected flare's center or end handle is a
click with the Flare tool again: it opens Flare Tool Options at the
click, and with Alt (Option on macOS) held it draws a flare there with
the tool's options. Before this, the click did nothing.

shape.editFlare also refuses an explicit center or end point that is
not finite where the flare was drawn (`x2 must be a finite coordinate`,
or `y2`, `cx`, `cy`), instead of storing it as null and drawing the
flare with the default path.
This commit is contained in:
dotCooCoo
2026-11-17 05:37:12 -08:00
parent 4a0e66ebd4
commit 74ae933b53
3 changed files with 41 additions and 11 deletions
+6 -1
View File
@@ -164,7 +164,12 @@ fn edited(old: &Value, p: &Value, xf: Affine) -> Result<Value> {
if p.get(kx).is_none_or(Value::is_null) && p.get(ky).is_none_or(Value::is_null) {
return Ok(None);
}
Ok(Some(inv * Point::new(f64_req(p, kx, C)?, f64_req(p, ky, C)?)))
// A point that leaves the finite range where the flare was drawn is refused, not stored.
let q = inv * Point::new(f64_req(p, kx, C)?, f64_req(p, ky, C)?);
match [(kx, q.x), (ky, q.y)].into_iter().find(|(_, v)| !v.is_finite()) {
None => Ok(Some(q)),
Some((key, _)) => Err(bad(C, format!("{key} must be a finite coordinate"))),
}
};
let c = point("cx", "cy")?;
let end = point("x2", "y2")?;
+13 -5
View File
@@ -3363,17 +3363,25 @@ fn flare_counts_are_whole_numbers() {
assert!(s.execute("shape.flare", &json!({"cx": 100, "cy": 100, "rays": 2.5})).is_err());
}
/// `shape.editFlare` on a flare scaled far down: a `pathLength` whose end point, taken back to
/// where the flare was drawn, is not a finite number is an error, and the flare keeps its settings.
/// `shape.editFlare` on a flare scaled far down: a `pathLength`, an end point or a center that,
/// taken back to where the flare was drawn, is not a finite number is an error, and the flare keeps
/// its settings.
#[test]
fn edit_flare_end_points_that_are_not_finite_are_errors() {
let mut s = session();
let id = NodeId(s.execute("shape.flare", &json!({"cx": 100, "cy": 100, "rings": 2})).unwrap()["id"].as_u64().unwrap());
s.execute("object.scale", &json!({"sx": 1e-4, "sy": 1e-4})).unwrap();
let before = flare_settings(&s.doc().unwrap().doc, id).expect("a flare");
let err = s.execute("shape.editFlare", &json!({"pathLength": 1e305})).unwrap_err().to_string();
assert!(err.ends_with("x2 must be a finite coordinate"), "{err}");
assert_eq!(flare_settings(&s.doc().unwrap().doc, id).expect("still a flare"), before);
for (p, key) in [
(json!({"pathLength": 1e305}), "x2"),
(json!({"x2": 1e305, "y2": 0}), "x2"),
(json!({"x2": 0, "y2": -1e305}), "y2"),
(json!({"cx": 1e305, "cy": 0}), "cx"),
] {
let err = s.execute("shape.editFlare", &p).unwrap_err().to_string();
assert!(err.ends_with(&format!("{key} must be a finite coordinate")), "{p}: {err}");
assert_eq!(flare_settings(&s.doc().unwrap().doc, id).expect("still a flare"), before, "{p}");
}
}
/// A flare drawn again keeps its parts' pixel-aligned property, whatever the document's Align New
+22 -5
View File
@@ -90,13 +90,15 @@ pub struct FlareTool {
}
/// A drag of a selected flare's handle: the flare, whether it is the end handle (else the center),
/// where the handle was, where it was pressed and whether the drag has begun its undo step.
/// where the handle was, where it was pressed, whether Alt (Option on macOS) was held at the press
/// and whether the drag has begun its undo step.
#[derive(Clone, Copy, Debug)]
struct HandleDrag {
id: vectorcraft_doc::NodeId,
end: bool,
from: Point,
at: Point,
alt: bool,
began: bool,
}
@@ -307,7 +309,14 @@ impl Tool for FlareTool {
}
PointerKind::Up => {
self.handle = None;
if h.began { vec![Action::Preview("shape.editFlare".into(), handle_params(h, ev.pos)), Action::Commit] } else { vec![] }
if h.began {
vec![Action::Preview("shape.editFlare".into(), handle_params(h, ev.pos)), Action::Commit]
} else if h.alt {
// A click on a handle without a drag is a click with the tool.
self.click_flare(cx, h.at)
} else {
vec![Action::Dialog("flare".into(), json!({ "x": h.at.x, "y": h.at.y }))]
}
}
_ => vec![],
};
@@ -322,7 +331,7 @@ impl Tool for FlareTool {
let (dc, de) = (ev.pos.distance(c), ev.pos.distance(e));
if dc.min(de) <= tol {
let end = de < dc;
self.handle = Some(HandleDrag { id, end, from: if end { e } else { c }, at: ev.pos, began: false });
self.handle = Some(HandleDrag { id, end, from: if end { e } else { c }, at: ev.pos, alt: ev.mods.alt, began: false });
return vec![];
}
}
@@ -1128,9 +1137,17 @@ mod tests {
assert_eq!(a.last(), Some(&Action::Preview("shape.editFlare".into(), json!({ "ids": [gid.0], "cx": 150.0, "cy": 120.0 }))));
assert_eq!(t.key(&cx, ToolKey::Escape, Mods::default()), vec![Action::Cancel]);
assert!(!t.busy());
// A click on a handle without a drag changes nothing.
// A click on a handle without a drag is a click with the tool: it opens the dialog, and
// with Alt held it draws a flare there with the tool's options.
t.pointer(&cx, &PointerEvent::new(PointerKind::Down, 110.0, 120.0));
assert!(t.pointer(&cx, &PointerEvent::new(PointerKind::Up, 110.0, 120.0)).is_empty());
let a = t.pointer(&cx, &PointerEvent::new(PointerKind::Up, 110.0, 120.0));
assert_eq!(a, vec![Action::Dialog("flare".into(), json!({ "x": 110.0, "y": 120.0 }))]);
assert!(!t.busy());
let alt = Mods { alt: true, ..Default::default() };
t.pointer(&cx, &PointerEvent::new(PointerKind::Down, 310.0, 121.0).with_mods(alt));
let a = t.pointer(&cx, &PointerEvent::new(PointerKind::Up, 310.0, 121.0).with_mods(alt));
assert_eq!(a, vec![Action::Exec("shape.flare".into(), flare_params(&t.options(), Point::new(310.0, 121.0)))]);
assert!(!t.busy());
// Away from the handles a drag draws a new flare.
t.pointer(&cx, &PointerEvent::new(PointerKind::Down, 200.0, 300.0));
let a = t.pointer(&cx, &PointerEvent::new(PointerKind::Drag, 240.0, 300.0));