Shapes: dragging a live polygon's side widget changes its number of sides

A selected live polygon shows a small diamond beside the middle of the
right side of its bounding box, with the Selection tool and with the
Rectangle, Rounded Rectangle, Ellipse, Polygon and Star tools, while the
bounding box and edges are shown. Dragging it sets the side count from 3
to 11: down adds a side and up removes one for every 12 screen pixels
along the box's own vertical axis, and the pointer shows the count while
measurement labels are on. A polygon of more than 11 sides keeps its
count until the drag goes up, which gives it 11. The drag sends
object.setLiveShape {sides} in one undo step, none when the count ends
where it began, and Escape puts the count back. Typed counts keep their
3 to 1000 range. The widget is drawn only while the box is drawn, so it
hides during a move, a turn and its own drag.

The help page describes the widget and its 3 to 11 range:
https://helpx.adobe.com/illustrator/desktop/draw-shapes-and-paths/modify-live-shapes/add-or-remove-sides-from-polygons.html
The widget's look and place, the drag direction, the step and the rule
for more than 11 sides are VectorCraft's own.

Docs: docs/target-app-parity.md and docs/ui-parity.md.
This commit is contained in:
dotCooCoo
2026-11-16 14:06:47 -08:00
parent f10c3aeacc
commit 3addb0940f
10 changed files with 533 additions and 11 deletions
+45
View File
@@ -1103,6 +1103,51 @@ fn a_shape_tool_drags_the_selected_shapes_widgets() {
assert_eq!(t.pointer(&c, &PointerEvent::new(PointerKind::Up, 200.0, 20.0)), vec![Action::Commit]);
}
/// With a shape tool, a drag down on a selected live polygon's side widget adds sides instead of
/// drawing, and Escape puts the count back; Line Segment draws from the widget.
#[test]
fn a_shape_tool_drags_a_polygons_side_widget() {
use vectorcraft_doc::{Appearance, LiveShape, Node, NodeKind};
let shape =
LiveShape::Polygon { radius: 80.0, sides: 5, xf: Affine::translate((250.0, 250.0)), radii: vec![], kinds: vec![], radii_relative: false };
let mut d = vectorcraft_doc::Document::new(500.0, 500.0);
let (l, id) = (d.layers[0].id, d.alloc_id());
let mut n = Node::path(id, shape.to_path(), Appearance::default_art());
if let NodeKind::Path { live: slot, .. } = &mut n.kind {
*slot = Some(Box::new(shape));
}
d.insert(Some(l), 0, n).unwrap();
let mut s = Selection::default();
s.add(id);
let p = paint();
let c = cx(&d, &s, &p);
let (w, _) = crate::sidewidget::SideWidget::for_tool(&c).expect("a side widget");
let down = |px: f64| PointerEvent::new(PointerKind::Drag, w.at.x, w.at.y + px);
for tool in ["rectangle", "roundedRectangle", "ellipse", "polygon", "star"] {
let mut t = ShapeTool::new(tool);
assert_eq!(t.cursor(&c, w.at, Mods::default()), Cursor::ArrowHollow, "{tool}");
assert!(t.pointer(&c, &PointerEvent::new(PointerKind::Down, w.at.x, w.at.y)).is_empty(), "{tool}");
let a = t.pointer(&c, &down(25.0));
assert_eq!(
a,
vec![Action::Begin("Live Shape".into()), Action::Preview("object.setLiveShape".into(), json!({ "id": id.0, "sides": 7 }))],
"{tool}"
);
assert!(t.transforming() && !t.drawing_boxed(), "{tool}");
assert_eq!(t.pointer(&c, &PointerEvent::new(PointerKind::Up, w.at.x, w.at.y + 25.0)), vec![Action::Commit], "{tool}");
assert!(!t.busy(), "{tool}");
t.pointer(&c, &PointerEvent::new(PointerKind::Down, w.at.x, w.at.y));
t.pointer(&c, &down(-13.0));
assert_eq!(t.key(&c, ToolKey::Escape, Mods::default()), vec![Action::Cancel], "{tool}");
assert!(!t.busy(), "{tool}");
}
let mut t = ShapeTool::new("lineSegment");
assert_eq!(t.cursor(&c, w.at, Mods::default()), Cursor::Crosshair);
t.pointer(&c, &PointerEvent::new(PointerKind::Down, w.at.x, w.at.y));
let a = t.pointer(&c, &down(25.0));
assert!(matches!(a.last(), Some(Action::Preview(cmd, _)) if cmd == "shape.line"), "{a:?}");
}
/// A double-click on a corner widget of a selected live shape, with a shape tool that shows the
/// widgets, asks for the Transform panel and nothing else: neither click draws, edits or begins an
/// undo step, and the tool stays idle. Line Segment, a plain path, a pie widget, a hidden or