Parametric Shape: W and H keep the center with anchors direct-selected

With anchors direct-selected, the shared reference point locator shows the box around those anchors, not the shape's own box. The panel's W and H now leave out the reference point in that case, so the shape keeps its center as it did before.
This commit is contained in:
dotCooCoo
2026-11-25 05:03:25 -08:00
parent 07907fb70d
commit 9c65a21fce
3 changed files with 27 additions and 3 deletions
+10 -2
View File
@@ -70,6 +70,13 @@ pub(super) fn target(app: &VectorcraftApp) -> (Option<NodeId>, ParametricShape)
(None, apply(fallback, &app.session.tool_options_of(tool::ID)).unwrap_or(fallback))
}
/// Whether anchors are direct-selected, so that the selection's box is the box around them.
fn anchors_selected(app: &VectorcraftApp) -> bool {
app.session
.active()
.is_some_and(|st| vectorcraft_effects::preview::anchor_bounds_with(&st.selection, &st.doc, app.session.bounds_measure()).is_some())
}
/// Whether something is selected and none of it is a parametric shape Convert could take.
pub(super) fn plain_selected(app: &VectorcraftApp) -> bool {
app.session.active().is_some_and(|st| !st.selection.is_empty()) && selected(app).is_none()
@@ -144,8 +151,9 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
(Some(mut p), Some(id)) => {
p["id"] = json!(id.0);
// The Transform panel and the Control bar share one reference point locator. W and H
// keep the point of the shape's bounding box chosen there in place.
if p.get("width").or_else(|| p.get("height")).is_some() {
// keep the point of the shape's bounding box chosen there in place. With anchors
// direct-selected the locator shows their box, so the shape keeps its center instead.
if p.get("width").or_else(|| p.get("height")).is_some() && !anchors_selected(app) {
p["reference"] = json!(app.ui.transform_panel.reference_point);
}
run(app, "addon.pathtools.shape.set", p);
@@ -133,6 +133,21 @@ fn the_parametric_shape_panels_size_fields_keep_the_shared_reference_point() {
let moved = app.selection_box().unwrap().reference_point(refi).distance(was);
assert!(moved < 1e-6, "reference {refi}, rotation {rotation}: the reference point moved {moved} pt");
}
// With an anchor direct-selected the locator shows the anchors' box, so W keeps the shape's center.
let mut app = app();
let params = json!({"kind": "rectangle", "center": [150, 150], "width": 100, "height": 60});
let id = vectorcraft_doc::NodeId(app.run("addon.pathtools.shape.create", params).unwrap()["id"].as_u64().unwrap());
app.session
.select(|_, sel| {
sel.anchors.insert(id, [(0, 1)].into_iter().collect());
})
.unwrap();
app.ui.transform_panel.reference_point = 0;
let mut panel = Panel::new(app, super::shape::show);
panel.type_into("W", "160");
let app = panel.app();
let after = vectorcraft_tools::addons::parametric_shape::read(app.session.active().unwrap().doc.node(id).unwrap()).unwrap();
assert!((after.width - 160.0).abs() < 1e-6 && after.center.distance(vectorcraft_geom::Point::new(150.0, 150.0)) < 1e-6, "{after:?}");
}
/// The Corner Tool and Shared Edge Merge Tool items leave a floating Anchor Inspector showing
+2 -1
View File
@@ -2862,7 +2862,8 @@ The add-on's Parametric Shape Tool (2026-10-30) draws ten kinds of shape that st
ellipse, polygon and star with 3 to 1,000 sides or points, ring, arrow, cross, heart, gear, speech bubble; corner radius
limited to the middle of a side): a drag from the centre sizes and turns one, the arrow keys change its count and values
while dragging, handles edit a selected one, a double-click places one with the last settings, and its panel edits the
numbers (its W and H keep the point chosen in the shared reference point locator in place). A shape is a plain path
numbers (its W and H keep the point chosen in the shared reference point locator in place, and the center when anchors
are direct-selected). A shape is a plain path
whose numbers and outline fingerprint sit in one object-data entry that SVG export
leaves out; moving, rotating or scaling it keeps it editable, editing its anchors makes it a plain path. Convert to
Parametric Shape recognises plain rectangles, ellipses and regular polygons. Geometry in