Merge pull request #8527 from dotCooCoo/feat/transform-rectangle-corner-type

Transform: Rectangle Properties has a Corner menu, one per corner when Corner Radius is unlinked
This commit is contained in:
BFlat authored and GitHub committed 2026-11-20 03:46:22 +07:00
commit e133d546e2
9 files changed
+444 -18

No files matched your search

+1 -1
View File
@@ -305,7 +305,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Live Shape Properties",
[],
None,
"{id?, ids?, radius?: pt (or % of each corner's maximum when `relativeRadii` is true), kind?: \"round\"|\"invertedRound\"|\"chamfer\", relativeRadii?: bool (Relative rounding, as in the reference app: store radii as fractions of each corner's maximum so they scale with the shape), corners?: [i…], items?: [{id, corners?: [i…]}] (several objects, each with its own corners, in place of ids and corners: the canvas's corner widgets across a selection), sides?: n, polygonAngle?: degrees (counter-clockwise from its first vertex straight up), polygonRadius?: pt (centre to vertex), sideLength?: pt (sets the radius), makeSidesEqual?: true (a polygon scaled unevenly: drops the uneven scale and shear, keeping its centre, angle and mean radius), pieStart?, pieEnd?: degrees (an ellipse's pie, counter-clockwise from 3 o'clock; 0 to 360 is the whole ellipse), invertPie?: true (swaps them: the other part of the ellipse), constrainPie?: bool (Constrain Pie Angle: with one of pieStart and pieEnd, not both and not with invertPie, the other angle moves by as much, so each ellipse keeps its span), lineLength?: pt (a live line's length, above 0; its first end stays), lineAngle?: degrees (a live line's angle, counter-clockwise from 3 o'clock, from its first end to its second; it turns about its midpoint), rectangleAngle?: degrees (a live rectangle's, counterclockwise from level), ellipseAngle?: degrees (a live ellipse's, counterclockwise from level; its pie turns with it)} (rectangleAngle, ellipseAngle and polygonAngle turn each shape of that kind about its own center and leave other objects as they are; a pixel-aligned shape then goes back on the pixel grid, as after other edits, which can move its center or change its size; an angle that is not a number is an error, and `null` counts as an omitted key; a shape that a turn would take past the coordinate limit (±4,000,000 pt) is an error that changes nothing; Live Corners on any path: radius and kind set its corners (anchors that aren't smooth, where two sides, straight or curved (#1144), meet at an angle): `corners` (anchor indices of the path with its corners uncut, counting every subpath's anchors in order: a rectangle's 0 top-left, 1 top-right, 2 bottom-right, 3 bottom-left; a polygon's from the first vertex clockwise), else the corners with a Direct-Selected anchor, else every corner; each radius is drawn no larger than half the corner's shorter side allows; a path that isn't a live shape keeps its uncut outline so its corners stay editable, and is plain again once none is cut; sides: a polygon's, which keep the radius they shared; the polygon params apply in that order: sides, makeSidesEqual, polygonAngle, then sideLength or else polygonRadius; a line's lineLength applies before its lineAngle)",
"{id?, ids?, radius?: pt (or % of each corner's maximum when `relativeRadii` is true), kind?: \"round\"|\"invertedRound\"|\"chamfer\", relativeRadii?: bool (Relative rounding, as in the reference app: store radii as fractions of each corner's maximum so they scale with the shape), corners?: [i…], rectanglesOnly?: bool (only the live rectangles among the targets; the other objects stay as they are), items?: [{id, corners?: [i…]}] (several objects, each with its own corners, in place of ids and corners: the canvas's corner widgets across a selection), sides?: n, polygonAngle?: degrees (counter-clockwise from its first vertex straight up), polygonRadius?: pt (centre to vertex), sideLength?: pt (sets the radius), makeSidesEqual?: true (a polygon scaled unevenly: drops the uneven scale and shear, keeping its centre, angle and mean radius), pieStart?, pieEnd?: degrees (an ellipse's pie, counter-clockwise from 3 o'clock; 0 to 360 is the whole ellipse), invertPie?: true (swaps them: the other part of the ellipse), constrainPie?: bool (Constrain Pie Angle: with one of pieStart and pieEnd, not both and not with invertPie, the other angle moves by as much, so each ellipse keeps its span), lineLength?: pt (a live line's length, above 0; its first end stays), lineAngle?: degrees (a live line's angle, counter-clockwise from 3 o'clock, from its first end to its second; it turns about its midpoint), rectangleAngle?: degrees (a live rectangle's, counterclockwise from level), ellipseAngle?: degrees (a live ellipse's, counterclockwise from level; its pie turns with it)} (rectangleAngle, ellipseAngle and polygonAngle turn each shape of that kind about its own center and leave other objects as they are; a pixel-aligned shape then goes back on the pixel grid, as after other edits, which can move its center or change its size; an angle that is not a number is an error, and `null` counts as an omitted key; a shape that a turn would take past the coordinate limit (±4,000,000 pt) is an error that changes nothing; Live Corners on any path: radius and kind set its corners (anchors that aren't smooth, where two sides, straight or curved (#1144), meet at an angle): `corners` (anchor indices of the path with its corners uncut, counting every subpath's anchors in order: a rectangle's 0 top-left, 1 top-right, 2 bottom-right, 3 bottom-left; a polygon's from the first vertex clockwise), else the corners with a Direct-Selected anchor, else every corner; each radius is drawn no larger than half the corner's shorter side allows; a path that isn't a live shape keeps its uncut outline so its corners stay editable, and is plain again once none is cut; sides: a polygon's, which keep the radius they shared; the polygon params apply in that order: sides, makeSidesEqual, polygonAngle, then sideLength or else polygonRadius; a line's lineLength applies before its lineAngle)",
has_selection,
set_live_shape
),
+20 -6
View File
@@ -124,7 +124,7 @@ fn line_edit(l: &LiveShape, len: Option<f64>, angle: Option<f64>) -> Option<Live
}
pub(super) fn set_live_shape(s: &mut Session, p: &Value) -> Result<Value> {
check_switches(p, &["constrainPie", "invertPie", "makeSidesEqual", "relativeRadii"], "object.setLiveShape")?;
check_switches(p, &["constrainPie", "invertPie", "makeSidesEqual", "rectanglesOnly", "relativeRadii"], "object.setLiveShape")?;
check_numbers(p, &["radius", "sides"], "object.setLiveShape")?;
// `items`: objects each with its own `corners`; else `ids` (or the selection) sharing them.
let items = match p.get("items").filter(|v| !v.is_null()) {
@@ -235,6 +235,13 @@ pub(super) fn set_live_shape(s: &mut Session, p: &Value) -> Result<Value> {
// When every value given is the current one, the document and its undo history stay as they
// are.
let st = s.doc()?;
// `rectanglesOnly`: the live rectangles among the targets; the other objects stay as they are.
let ids: Vec<NodeId> = if p.get("rectanglesOnly").and_then(Value::as_bool) == Some(true) {
let rectangle = |id: &NodeId| matches!(st.doc.node(*id).map(|n| &n.kind), Some(NodeKind::Path { live: Some(l), .. }) if matches!(**l, LiveShape::Rectangle { .. }));
ids.into_iter().filter(rectangle).collect()
} else {
ids
};
// The lines that Line Length or Line Angle changes, as they become. A line that would reach
// past the document's coordinate limit is an error before anything changes.
let mut lines = std::collections::BTreeMap::new();
@@ -278,16 +285,23 @@ pub(super) fn set_live_shape(s: &mut Session, p: &Value) -> Result<Value> {
}
let Some(c) = LiveCorners::new(path, live.as_deref()) else { return true };
let picked = corners_of(*id).unwrap_or_else(|| c.picked(st.selection.anchors.get(id)));
// Setting corners folds a scale left in a rectangle's transform into its size, which
// changes it.
live.as_deref().is_none_or(|l| l.folded() == *l)
// Setting a radius folds a scale left in a rectangle's transform into its size, which
// changes it. A kind the corners already have leaves the rectangle as it is.
(radius.is_none() || live.as_deref().is_none_or(|l| l.folded() == *l))
&& picked.iter().all(|k| {
*k < c.base.anchor_count()
&& radius.is_none_or(|r| (c.drawn_radius(*k) - r.max(0.0)).abs() < 1e-9)
// A radius stored in document units can be larger than it draws; a relative
// one is a fraction, so it is compared as drawn.
&& radius.is_none_or(|r| {
let now = if c.radii_relative() { c.drawn_radius(*k) } else { c.radius(*k) };
(now - r.max(0.0)).abs() < 1e-9
})
&& kind.is_none_or(|kd| c.kind(*k) == kd)
})
};
if ids.iter().all(has_values) {
// The objects every value given already matches stay as they are, beside others that change.
let ids: Vec<NodeId> = ids.into_iter().filter(|id| !has_values(id)).collect();
if ids.is_empty() {
return ok();
}
s.edit("Live Shape", |d, sel| {
+101
View File
@@ -59,6 +59,107 @@ fn a_whole_rectangle_rounds_all_corners_and_given_corners_alone() {
assert_eq!(corners(&s, id).1[3], CornerKind::Chamfer);
}
/// The Corner menus of Rectangle Properties: a kind for all four corners or one, set on corners
/// with no radius too and leaving the radii as they are, in one undo step; the kind the corners
/// already have adds no step.
#[test]
fn rectangle_kind_menu_targets_all_or_one_corner_and_skips_noop_undo() {
let (mut s, id) = session();
run(&mut s, json!({"corners": [1], "radius": 12}));
let steps = |s: &Session| s.doc().unwrap().history.undo.len();
let undo = steps(&s);
run(&mut s, json!({"corners": [0, 1, 2, 3], "kind": "invertedRound"}));
assert_eq!(corners(&s, id).0, [0.0, 12.0, 0.0, 0.0]);
assert_eq!(corners(&s, id).1, [CornerKind::InvertedRound; 4]);
assert_eq!(steps(&s), undo + 1);
run(&mut s, json!({"corners": [0, 1, 2, 3], "kind": "invertedRound"}));
run(&mut s, json!({"corners": [2], "kind": "invertedRound"}));
assert_eq!(steps(&s), undo + 1, "no step when nothing changes");
run(&mut s, json!({"corners": [2], "kind": "chamfer"}));
assert_eq!(corners(&s, id).1, [CornerKind::InvertedRound, CornerKind::InvertedRound, CornerKind::Chamfer, CornerKind::InvertedRound]);
assert_eq!(corners(&s, id).0, [0.0, 12.0, 0.0, 0.0]);
assert_eq!(steps(&s), undo + 2);
}
/// A kind the corners already have leaves a rectangle saved stretched by an older version as it
/// is, alone or beside a rectangle the kind changes: its scale stays in its transform.
#[test]
fn a_kind_the_corners_have_leaves_a_stretched_rectangle() {
let (mut s, id) = session();
let other = NodeId(s.execute("shape.rectangle", &json!({"x": 200, "y": 10, "width": 40, "height": 40})).unwrap()["id"].as_u64().unwrap());
let stretched = LiveShape::Rectangle {
w: 50.0,
h: 60.0,
radii: [10.0; 4],
kinds: [CornerKind::Chamfer; 4],
radii_relative: false,
xf: Affine::translate((10.0, 10.0)) * Affine::scale_non_uniform(2.0, 1.0),
};
{
let d = std::sync::Arc::make_mut(&mut s.doc_mut().unwrap().doc);
let NodeKind::Path { path, live: Some(live), .. } = &mut d.node_mut(id).unwrap().kind else { panic!("not live") };
**live = stretched.clone();
*path = live.to_path();
}
let live = |s: &Session| node_path(s, id).1;
let steps = |s: &Session| s.doc().unwrap().history.undo.len();
let undo = steps(&s);
run(&mut s, json!({"ids": [id.0], "kind": "chamfer"}));
assert_eq!(live(&s), Some(stretched.clone()));
assert_eq!(steps(&s), undo, "no step when nothing changes");
run(&mut s, json!({"ids": [id.0, other.0], "kind": "chamfer"}));
assert_eq!(live(&s), Some(stretched));
assert_eq!(corners(&s, other).1, [CornerKind::Chamfer; 4]);
assert_eq!(steps(&s), undo + 1);
}
/// A radius is stored on a corner that stores a larger radius drawn at the new value, alone or
/// beside another rectangle; the radius every target already stores adds no undo step.
#[test]
fn a_radius_reaches_a_rectangle_that_already_draws_it() {
let (mut s, id) = session();
let other = NodeId(s.execute("shape.rectangle", &json!({"x": 200, "y": 10, "width": 100, "height": 60})).unwrap()["id"].as_u64().unwrap());
// 80 pt on every corner draws at 30 pt, half the 60 pt side.
run(&mut s, json!({"ids": [id.0], "radius": 80}));
assert_eq!(corners(&s, id).0, [80.0; 4]);
let (path, live) = node_path(&s, id);
let drawn = LiveCorners::new(&path, live.as_ref()).unwrap().drawn_radius(0);
assert!((drawn - 30.0).abs() < 1e-9, "draws at {drawn}");
let steps = |s: &Session| s.doc().unwrap().history.undo.len();
let undo = steps(&s);
run(&mut s, json!({"ids": [id.0], "corners": [1], "radius": 30}));
assert_eq!(corners(&s, id).0, [80.0, 30.0, 80.0, 80.0]);
assert_eq!(steps(&s), undo + 1);
run(&mut s, json!({"ids": [id.0, other.0], "corners": [0], "radius": 30}));
assert_eq!(corners(&s, id).0[0], 30.0);
assert_eq!(corners(&s, other).0[0], 30.0);
// The radius both already store adds no step.
run(&mut s, json!({"ids": [id.0, other.0], "corners": [0], "radius": 30}));
assert_eq!(steps(&s), undo + 2);
}
/// `rectanglesOnly` sets the live rectangles among the selection and leaves a polygon as it is; an
/// action that records it holds no ids, so playing it sets the rectangles selected then.
#[test]
fn rectangles_only_sets_the_selected_rectangles_when_an_action_plays() {
let (mut s, id) = session();
let polygon = NodeId(s.execute("shape.polygon", &json!({"cx": 300, "cy": 300, "radius": 40, "sides": 6})).unwrap()["id"].as_u64().unwrap());
s.execute("select.set", &json!({"ids": [id.0, polygon.0]})).unwrap();
let start = s.journal.len();
run(&mut s, json!({"rectanglesOnly": true, "corners": [0], "kind": "chamfer"}));
assert_eq!(corners(&s, id).1[0], CornerKind::Chamfer);
let NodeKind::Path { live: Some(l), .. } = &s.doc().unwrap().doc.node(polygon).unwrap().kind else { panic!("not live") };
let LiveShape::Polygon { kinds, .. } = &**l else { panic!("not a polygon") };
assert!(kinds.iter().all(|k| *k == CornerKind::Round), "the polygon keeps its corners: {kinds:?}");
let action = s.journal_for_action(start);
assert_eq!(action.len(), 1);
assert_eq!(action[0].1.get("ids"), None);
let other = NodeId(s.execute("shape.rectangle", &json!({"x": 200, "y": 10, "width": 40, "height": 40})).unwrap()["id"].as_u64().unwrap());
s.execute("select.set", &json!({"ids": [other.0, polygon.0]})).unwrap();
s.replay(&action[0].0, &action[0].1).unwrap();
assert_eq!(corners(&s, other).1[0], CornerKind::Chamfer);
}
/// #938: `items` rounds several objects in one step, each its own corners (or all of them).
#[test]
fn items_round_several_objects_each_its_own_corners() {
+78 -7
View File
@@ -96,8 +96,9 @@ pub(crate) fn field_width(ui: &Ui) -> f32 {
}
/// The Corner Radius field of a live rectangle's properties: [`corner_radius`], which a new value
/// sets on those corners. The link behind it is the `singleCornerRadius` preference: off, a field
/// for each of the four corners follows, each setting its own corner.
/// sets on those corners. The link behind it is the `singleCornerRadius` preference: on, a Corner
/// menu follows that sets the kind of all four corners; off, a row for each of the four corners
/// follows, each with a radius field and a Corner menu that set its own corner.
pub(crate) fn corner_radius_row(app: &mut VectorcraftApp, ui: &mut Ui, n: &Node, id: &str) {
let fw = field_width(ui);
let single = app.session.prefs.single_corner_radius;
@@ -111,27 +112,97 @@ pub(crate) fn corner_radius_row(app: &mut VectorcraftApp, ui: &mut Ui, n: &Node,
transform::set_pref(app, "singleCornerRadius", !single);
}
});
if !single {
if single {
corner_kind_row(app, ui, n, id, fw);
} else {
corner_fields(app, ui, n, id, fw);
}
}
/// The Corner menu of a live rectangle whose corners share one radius field: the kind of all four
/// corners, also while some of them are Direct-Selected, blank when they differ. A pick sets it on
/// every corner of each selected live rectangle ([`set_rectangle_kinds`]).
fn corner_kind_row(app: &mut VectorcraftApp, ui: &mut Ui, n: &Node, id: &str, width: f32) {
let Some(lc) = LiveCorners::of(n) else { return };
let current = lc.style(&lc.all()).1;
ui.horizontal(|ui| {
dim_label(ui, tl!("Corner:"));
if let Some(kind) = corner_kind_menu(ui, (id, "kind"), tl!("Corner:"), current, width) {
set_rectangle_kinds(app, kind, None);
}
});
}
/// Set `kind` on corner `corner` (every corner for None) of each selected live rectangle
/// ([`set_rectangle_corners`]).
fn set_rectangle_kinds(app: &mut VectorcraftApp, kind: CornerKind, corner: Option<usize>) {
set_rectangle_corners(app, json!({"kind": kind}), corner);
}
/// Run `object.setLiveShape` with `p` (a `kind` or `radius`) on corner `corner` (every corner for
/// None) of each selected live rectangle, leaving other selected objects as they are: one undo
/// step, or none when nothing changes.
fn set_rectangle_corners(app: &mut VectorcraftApp, mut p: Value, corner: Option<usize>) {
p["corners"] = corner.map_or(json!([0, 1, 2, 3]), |k| json!([k]));
// The edit the tool computes on another thread comes first: the rectangles are the ones
// selected after it.
match app.session.finish_tool_edit() {
Ok(reqs) => crate::canvas::apply_requests(app, Ok(reqs)),
Err(e) => {
app.status(e.to_string());
return;
}
}
if app.session.active().is_none() {
return;
}
// The live rectangles of the selection when it runs, so an action that records it acts on the
// rectangles selected when it plays.
p["rectanglesOnly"] = json!(true);
if let Err(e) = app.run("object.setLiveShape", p) {
app.status(e);
}
}
/// A menu of the corner kinds, `width` wide, showing `current` (blank for None) and named `name`
/// for screen readers. Returns the kind picked.
fn corner_kind_menu(ui: &mut Ui, id: impl std::hash::Hash, name: &str, current: Option<CornerKind>, width: f32) -> Option<CornerKind> {
let names: Vec<&str> = CornerKind::ALL.iter().map(|k| crate::dialogs::corners::kind_label(*k)).collect();
let shown = current.map_or("", crate::dialogs::corners::kind_label);
crate::widgets::dropdown_names_named(ui, id, Some(name), shown, &names, width).and_then(|i| CornerKind::ALL.get(i).copied())
}
/// The corners of a live rectangle in the order their fields show, with their labels.
fn rectangle_corners() -> [(usize, &'static str); 4] {
[(0, tl!("Top Left:")), (1, tl!("Top Right:")), (2, tl!("Bottom Right:")), (3, tl!("Bottom Left:"))]
}
/// One Corner Radius field per corner of a live rectangle, each on its own row with its label,
/// the fields in line.
/// One Corner Radius field and one Corner menu per corner of a live rectangle, each pair on its own
/// row with the corner's label, the fields and menus in line; in a panel too narrow for that, each
/// menu goes on the row under its field. A value typed or a kind picked is set on that corner
/// alone, of each selected live rectangle ([`set_rectangle_corners`]).
fn corner_fields(app: &mut VectorcraftApp, ui: &mut Ui, n: &Node, id: &str, width: f32) {
let Some(lc) = LiveCorners::of(n) else { return };
let unit = app.session.general_unit();
egui::Grid::new((id, "corners")).num_columns(2).spacing(vec2(6.0, 4.0)).show(ui, |ui| {
let widest = |names: &mut dyn Iterator<Item = &str>| names.map(|t| crate::widgets::dim_label_width(ui, t)).fold(0.0, f32::max);
let labels = widest(&mut rectangle_corners().into_iter().map(|(_, label)| label));
// The longest kind name, with the room the menu's button gives around it and its arrow.
let menu_width = width.max(widest(&mut CornerKind::ALL.into_iter().map(crate::dialogs::corners::kind_label)) + 26.0);
// The two gaps between the grid's three columns are 6 points each.
let in_line = labels + width + menu_width + 12.0 <= ui.available_width();
egui::Grid::new((id, "corners")).num_columns(if in_line { 3 } else { 2 }).spacing(vec2(6.0, 4.0)).show(ui, |ui| {
for (k, label) in rectangle_corners() {
dim_label(ui, label);
if let Some(v) = crate::widgets::num_field_named(ui, (id, "corner", k), Some(label), Some(lc.radius(k)), unit, width) {
// A negative radius typed in rounds nothing: the command takes 0 or more.
app.run("object.setLiveShape", json!({"radius": v.max(0.0), "corners": [k]})).ok();
set_rectangle_corners(app, json!({"radius": v.max(0.0)}), Some(k));
}
if !in_line {
ui.end_row();
ui.label("");
}
if let Some(kind) = corner_kind_menu(ui, (id, "kind", k), label, Some(lc.kind(k)), menu_width) {
set_rectangle_kinds(app, kind, Some(k));
}
ui.end_row();
}
@@ -1575,11 +1575,11 @@ fn direct_selected_corners_show_their_kind_and_radius() {
// The whole path selected.
app.run("select.set", json!({"ids": [star]})).unwrap();
assert!(!shows(&tall(&mut app, &ctx, vec![]), "Corner:"), "no corner selected");
// A live rectangle's corner: its own Corner Radius row, once.
// A live rectangle's corner: its own Corner Radius row and Corner menu, once each.
let r = rect(&mut app, 20.0, 20.0, 60.0, 40.0).as_u64().unwrap();
app.run("select.anchors", json!({"id": r, "anchors": [[0, 1]], "mode": "set"})).unwrap();
let texts = tall(&mut app, &ctx, vec![]);
assert!(!shows(&texts, "Corner:"), "{texts:?}");
assert_eq!(texts.iter().filter(|(t, _)| t == "Corner:").count(), 1, "{texts:?}");
assert_eq!(texts.iter().filter(|(t, _)| t == "Corner Radius:").count(), 1, "{texts:?}");
}
@@ -136,6 +136,101 @@ fn a_polygon_shows_its_polygon_properties() {
assert!(live(&app).polygon_sides_equal());
}
/// A live rectangle's Rectangle Properties show one Corner menu for all four corners while Corner
/// Radius is linked, blank when the corners' kinds differ, and one per corner when it is unlinked,
/// in the Transform panel and the Properties panel's Transform section.
#[test]
fn a_rectangle_shows_linked_and_unlinked_corner_types() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
app.run("file.new", json!({"width": 300, "height": 300})).unwrap();
app.run("shape.rectangle", json!({"x": 50, "y": 50, "width": 120, "height": 80, "radius": 10})).unwrap();
let count = |shown: &[String], t: &str| shown.iter().filter(|s| *s == t).count();
let draws = [show as fn(&mut VectorcraftApp, &mut Ui), crate::panels::properties::transform_section];
set_pref(&mut app, "singleCornerRadius", true);
for draw in draws {
let shown = texts(&mut app, draw);
assert_eq!((count(&shown, "Corner:"), count(&shown, "Round")), (1, 1), "{shown:?}");
}
// Kinds that differ leave the linked menu blank.
app.run("object.setLiveShape", json!({"kind": "chamfer", "corners": [2]})).unwrap();
for draw in draws {
let shown = texts(&mut app, draw);
assert_eq!((count(&shown, "Corner:"), count(&shown, "Round"), count(&shown, "Chamfer")), (1, 0, 0), "{shown:?}");
}
set_pref(&mut app, "singleCornerRadius", false);
for draw in draws {
let shown = texts(&mut app, draw);
for t in ["Top Left:", "Top Right:", "Bottom Right:", "Bottom Left:"] {
assert_eq!(count(&shown, t), 1, "{t} in {shown:?}");
}
assert_eq!((count(&shown, "Round"), count(&shown, "Chamfer")), (3, 1), "{shown:?}");
}
}
/// A corner kind set with no live rectangle selected leaves the selected polygon, the document and
/// its undo history as they are.
#[test]
fn a_rectangle_corner_kind_without_a_selected_rectangle_changes_nothing() {
use vectorcraft_geom::shapes::CornerKind::Chamfer;
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
app.run("file.new", json!({"width": 300, "height": 300})).unwrap();
app.run("shape.polygon", json!({"cx": 150, "cy": 150, "radius": 40, "sides": 6})).unwrap();
let st = app.session.active().unwrap();
let (before, steps) = (st.doc.clone(), st.history.undo.len());
crate::panels::set_rectangle_kinds(&mut app, Chamfer, None);
crate::panels::set_rectangle_kinds(&mut app, Chamfer, Some(2));
let st = app.session.active().unwrap();
assert!(st.doc == before, "the document changed");
assert_eq!(st.history.undo.len(), steps);
}
/// A corner kind picked while a Shape Builder merge is computed on another thread applies the
/// merge first, and sets the kind on the live rectangles selected after it.
#[test]
fn a_rectangle_corner_kind_applies_a_merge_on_another_thread_first() {
use vectorcraft_geom::shapes::CornerKind::Chamfer;
use vectorcraft_tools::{Mods, PointerEvent, PointerKind};
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
app.run("file.new", json!({"width": 800, "height": 200})).unwrap();
for k in 0..40 {
app.run("shape.rectangle", json!({"x": k * 10, "y": 0, "width": 20, "height": 20})).unwrap();
}
app.run("select.all", json!({})).unwrap();
app.run("tool.select", json!({"tool": "shapeBuilder"})).unwrap();
let view = app.view_info();
let at = |kind| PointerEvent {
kind,
pos: vectorcraft_geom::Point::new(15.0, 10.0),
mods: Mods::default(),
pressure: 1.0,
backquote: false,
pen: None,
};
crate::canvas::dispatch(&mut app, &at(PointerKind::Move), view);
app.session.tool_poll(view, true).unwrap();
crate::canvas::dispatch(&mut app, &at(PointerKind::Down), view);
crate::canvas::dispatch(&mut app, &at(PointerKind::Up), view);
assert!(app.session.tool_editing());
crate::panels::set_rectangle_kinds(&mut app, Chamfer, None);
assert!(!app.session.tool_editing());
let st = app.session.active().unwrap();
let labels: Vec<_> = st.history.undo.iter().rev().take(2).map(|e| e.label.as_str()).collect();
assert_eq!(labels, ["Live Shape", "Shape Builder"]);
let kinds: Vec<_> = st
.selection
.objects
.iter()
.filter_map(|id| match &st.doc.node(*id)?.kind {
NodeKind::Path { live: Some(l), .. } => match &**l {
LiveShape::Rectangle { kinds, .. } => Some(*kinds),
_ => None,
},
_ => None,
})
.collect();
assert!(!kinds.is_empty() && kinds.iter().all(|k| *k == [Chamfer; 4]), "{kinds:?}");
}
/// #3451: a live ellipse shows pie start/end angles and Invert Pie in the Transform panel and
/// the Properties panel's Transform section; typed angles update the shape.
#[test]
+142
View File
@@ -744,6 +744,148 @@ fn the_shape_properties_popup_keeps_its_corner_dropdown() {
assert!(!kinds.is_empty() && kinds.iter().all(|k| *k == vectorcraft_geom::shapes::CornerKind::Chamfer), "{kinds:?}");
}
/// A rectangle's Corner menu in the popup sets the kind of all four corners in one undo step while
/// Corner Radius is linked; picking the kind they already have adds no step. Unlinked, each
/// corner's menu sets that corner alone.
#[test]
fn the_shape_properties_popup_changes_a_rectangle_corner_type() {
use vectorcraft_geom::shapes::CornerKind::{Chamfer, Round};
let mut app = app();
app.run("tool.select", json!({"tool": "selection"})).unwrap();
app.run("prefs.set", json!({"key": "singleCornerRadius", "value": true})).unwrap();
let rect = id(app.run("shape.rectangle", json!({"x": 40, "y": 40, "width": 80, "height": 60, "radius": 10})).unwrap());
select(&mut app, &[rect]);
let kinds = |app: &VectorcraftApp| match live(app, rect) {
vectorcraft_doc::LiveShape::Rectangle { kinds, radii, .. } => (kinds, radii),
l => panic!("{l:?}"),
};
let steps = |app: &VectorcraftApp| app.session.active().unwrap().history.undo.len();
let (ctx, texts) = click_lock_slot(&mut app);
let click = |app: &mut VectorcraftApp, p: Pos2| {
let press = |pressed| Event::PointerButton { pos: p, button: PointerButton::Primary, pressed, modifiers: Default::default() };
frame(app, &ctx, vec![Event::PointerMoved(p), press(true), press(false)]);
frame(app, &ctx, vec![])
};
// The open list's entry for `name`, drawn after the closed menu that may show the same name.
let entry = |texts: &[(String, Rect)], name: &str| texts.iter().rev().find(|(t, _)| t == name).map(|(_, r)| r.center()).unwrap();
let before = steps(&app);
let texts = click(&mut app, at(&texts, "Round"));
let texts = click(&mut app, entry(&texts, "Chamfer"));
assert_eq!(kinds(&app), ([Chamfer; 4], [10.0; 4]), "all four corners, radii kept");
assert_eq!(steps(&app), before + 1, "one undo step");
let texts = click(&mut app, at(&texts, "Chamfer"));
// The list is open: its Chamfer row shows as well as the closed menu's, and the pick closes it.
assert_eq!(texts.iter().filter(|(t, _)| t == "Chamfer").count(), 2, "{texts:?}");
assert!(texts.iter().any(|(t, _)| t == "Inverted Round"), "{texts:?}");
let texts = click(&mut app, entry(&texts, "Chamfer"));
assert!(!texts.iter().any(|(t, _)| t == "Inverted Round"), "the pick closes the list: {texts:?}");
assert_eq!(steps(&app), before + 1, "the same kind adds no undo step");
app.run("prefs.set", json!({"key": "singleCornerRadius", "value": false})).unwrap();
let texts = frame(&mut app, &ctx, vec![]);
assert_eq!(texts.iter().filter(|(t, _)| t == "Chamfer").count(), 4, "{texts:?}");
// The first menu is the top left corner's.
let texts = click(&mut app, at(&texts, "Chamfer"));
click(&mut app, entry(&texts, "Round"));
assert_eq!(kinds(&app), ([Round, Chamfer, Chamfer, Chamfer], [10.0; 4]));
assert_eq!(steps(&app), before + 2);
app.run("edit.undo", json!({})).unwrap();
assert_eq!(kinds(&app).0, [Chamfer; 4]);
}
/// One Transform panel frame `width` points wide: the texts drawn, with their rectangles.
fn panel_frame(app: &mut VectorcraftApp, ctx: &egui::Context, width: f32, events: Vec<Event>) -> Vec<(String, Rect)> {
let screen = Rect::from_min_size(Pos2::ZERO, vec2(width, 700.0));
let input = egui::RawInput { screen_rect: Some(screen), events, ..Default::default() };
let mut out = ctx.run_ui(input, |ui| crate::panels::transform::show(app, ui));
out.textures_delta.clear();
shapes_text(&out.shapes.iter().map(|c| c.shape.clone()).collect::<Vec<_>>())
}
/// With several rectangles selected, the linked Corner menu sets the kind on every corner of each
/// of them, also when the rectangle the panel shows already has it, and leaves a selected polygon
/// as it is.
#[test]
fn the_linked_corner_menu_sets_every_selected_rectangle() {
use vectorcraft_geom::shapes::CornerKind::{Chamfer, Round};
let mut app = app();
app.run("prefs.set", json!({"key": "singleCornerRadius", "value": true})).unwrap();
let a = id(app.run("shape.rectangle", json!({"x": 20, "y": 20, "width": 80, "height": 60, "radius": 8})).unwrap());
let b = id(app.run("shape.rectangle", json!({"x": 200, "y": 20, "width": 80, "height": 60, "radius": 8})).unwrap());
let polygon = id(app.run("shape.polygon", json!({"cx": 200, "cy": 200, "radius": 40, "sides": 6})).unwrap());
app.run("object.setLiveShape", json!({"ids": [a], "kind": "chamfer"})).unwrap();
select(&mut app, &[a, b, polygon]);
let kinds = |app: &VectorcraftApp, id: u64| match live(app, id) {
vectorcraft_doc::LiveShape::Rectangle { kinds, .. } => kinds,
l => panic!("{l:?}"),
};
let ctx = egui::Context::default();
crate::theme::install_fonts(&ctx);
let click = |app: &mut VectorcraftApp, p: Pos2| {
let press = |pressed| Event::PointerButton { pos: p, button: PointerButton::Primary, pressed, modifiers: Default::default() };
panel_frame(app, &ctx, 300.0, vec![Event::PointerMoved(p), press(true), press(false)]);
panel_frame(app, &ctx, 300.0, vec![])
};
panel_frame(&mut app, &ctx, 300.0, vec![]);
let texts = panel_frame(&mut app, &ctx, 300.0, vec![]);
let steps = app.session.active().unwrap().history.undo.len();
let texts = click(&mut app, at(&texts, "Chamfer"));
let entry = texts.iter().rev().find(|(t, _)| t == "Chamfer").map(|(_, r)| r.center()).unwrap();
click(&mut app, entry);
assert_eq!((kinds(&app, a), kinds(&app, b)), ([Chamfer; 4], [Chamfer; 4]));
let vectorcraft_doc::LiveShape::Polygon { kinds: sides, .. } = live(&app, polygon) else { panic!("not a polygon") };
assert!(sides.iter().all(|k| *k == Round), "the polygon keeps its corners: {sides:?}");
assert_eq!(app.session.active().unwrap().history.undo.len(), steps + 1, "one undo step");
app.run("edit.undo", json!({})).unwrap();
assert_eq!(kinds(&app, b), [Round; 4]);
}
/// Unlinked, a corner's radius field rounds that corner of each selected rectangle and leaves a
/// selected polygon as it is.
#[test]
fn an_unlinked_corner_radius_leaves_other_selected_shapes() {
let mut app = app();
app.run("prefs.set", json!({"key": "singleCornerRadius", "value": false})).unwrap();
let rect = id(app.run("shape.rectangle", json!({"x": 20, "y": 20, "width": 80, "height": 60, "radius": 7})).unwrap());
let polygon = id(app.run("shape.polygon", json!({"cx": 200, "cy": 200, "radius": 40, "sides": 6})).unwrap());
select(&mut app, &[rect, polygon]);
let ctx = egui::Context::default();
crate::theme::install_fonts(&ctx);
panel_frame(&mut app, &ctx, 300.0, vec![]);
let texts = panel_frame(&mut app, &ctx, 300.0, vec![]);
// The top left corner's field is the first that shows the radius.
let p = at(&texts, "7 pt");
let press = |pressed| Event::PointerButton { pos: p, button: PointerButton::Primary, pressed, modifiers: Default::default() };
panel_frame(&mut app, &ctx, 300.0, vec![Event::PointerMoved(p), press(true), press(false)]);
panel_frame(&mut app, &ctx, 300.0, vec![]);
panel_frame(&mut app, &ctx, 300.0, vec![Event::Text("15".into())]);
let enter = Event::Key { key: egui::Key::Enter, physical_key: None, pressed: true, repeat: false, modifiers: Default::default() };
panel_frame(&mut app, &ctx, 300.0, vec![enter]);
panel_frame(&mut app, &ctx, 300.0, vec![]);
let vectorcraft_doc::LiveShape::Rectangle { radii, .. } = live(&app, rect) else { panic!("not a rectangle") };
assert_eq!(radii, [15.0, 7.0, 7.0, 7.0]);
let vectorcraft_doc::LiveShape::Polygon { radii, .. } = live(&app, polygon) else { panic!("not a polygon") };
assert!(radii.iter().all(|r| *r == 0.0), "the polygon keeps its corners: {radii:?}");
}
/// Unlinked, the four corner rows keep their Corner menus inside a panel at its narrowest.
#[test]
fn the_unlinked_corner_menus_fit_a_narrow_panel() {
let mut app = app();
app.run("prefs.set", json!({"key": "singleCornerRadius", "value": false})).unwrap();
let rect = id(app.run("shape.rectangle", json!({"x": 20, "y": 20, "width": 80, "height": 60, "radius": 8})).unwrap());
app.run("object.setLiveShape", json!({"ids": [rect], "kind": "invertedRound"})).unwrap();
select(&mut app, &[rect]);
let ctx = egui::Context::default();
crate::theme::install_fonts(&ctx);
let width = 220.0;
panel_frame(&mut app, &ctx, width, vec![]);
let texts = panel_frame(&mut app, &ctx, width, vec![]);
let menus: Vec<_> = texts.iter().filter(|(t, _)| t.starts_with("Inverted")).collect();
assert_eq!(menus.len(), 4, "{texts:?}");
assert!(menus.iter().all(|(_, r)| r.right() <= width), "{menus:?}");
}
/// Every other selection keeps Lock: a plain closed path, a star (a plain path), a path with live
/// corners, a group and several objects. The Direct Selection tool keeps it for a basic shape.
#[test]
+4 -2
View File
@@ -7530,7 +7530,7 @@ and files saved without it open with it off.
## Live Corners
`object.setLiveShape {id?, ids?, radius?, kind?, corners?, items?}` sets the corners of any path (one undo step): a live
`object.setLiveShape {id?, ids?, radius?, kind?, corners?, rectanglesOnly?, items?}` sets the corners of any path (one undo step): a live
rectangle's or polygon's, a star's, a pen path's. A corner is an anchor where two sides, straight or curved, meet at an angle
(not an open path's ends, not a smooth anchor, not one the sides run straight on through); a curved side is trimmed to
what the cut leaves of it. `radius` (pt) and `kind`
@@ -7549,7 +7549,9 @@ or keeps its size with Scale Corners off), and a rectangle from a file that kept
(elliptical corners) gets circular ones in document units when its corners are next set. Dragging a corner widget
rounds the corners whose widgets show (every corner, or the Direct-Selected ones) on every selected path at once,
outlining in red those that reach their limit; the Selection tool shows the widgets of live rectangles and polygons,
the Direct Selection tool those of any path. Several objects each with their own corners are one call:
the Direct Selection tool those of any path. `rectanglesOnly: true` sets them on the live rectangles among the targets
alone and leaves the other objects as they are (the Rectangle Properties corner fields and menus send it with the
selection, so an action that records them acts on the rectangles selected when it plays). Several objects each with their own corners are one call:
`items: [{id, corners?}]` in place of `ids` and `corners`. Alt-clicking one cycles their kind and double-clicking one opens Corners (`ui.corners {id?, corners?}`,
dialog `corners`: `kind`, `radius`; OK runs `object.setLiveShape`).
`view.shapeWidgets {on?}` (desktop app, the Hide Shape Widgets and Show Shape Widgets button in the Control bar of the
+1
View File
@@ -1473,6 +1473,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
With Direct Selection, Shift pressed during the drag of a curved segment keeps both of its handles at right angles to the line between its anchors, on the same side and at the same length (`path.reshapeSegment {perpendicular}`). Shift held while any segment is dragged with the Anchor Point tool or the Pen with Alt does the same. With the Anchor Point tool, Shift held at the press on an anchor (or a selected blend's spine point) moves it, handles and all, instead of pulling out handles; Shift kept down keeps the move at 45° steps, and a Shift-click that doesn't move leaves the anchor as it was (`path.moveAnchor`). A selected blend spine's segment dragged with the Anchor Point tool, or a curved one dragged with Direct Selection, bends the same way (`object.blend.spine.reshapeSegment`).
- **Live Corners:** drag a live rectangle's corner widgets (Selection or Direct Selection) to round all corners, with a radius readout; with Direct Selection, select corner anchors to show and round just those corners (#381). Each corner keeps its own radius and kind (Round, Inverted Round, Chamfer): Alt-click a widget to cycle the kind, double-click it for the Corners dialog, and the Properties and Transform radius fields set the selected corners (`object.setLiveShape {corners, radius, kind}`). A link toggle behind Corner Radius (the `singleCornerRadius` preference) switches the panels to a field for each corner of a live rectangle: Top Left, Top Right, Bottom Right and Bottom Left. Corners stay circular when the rectangle is scaled unevenly or along its own sides when rotated (the radius keeps its size, or scales by the mean scale with Scale Corners on); only a shear distorts them. On a rectangle that isn't square every corner is the same circle: a radius past half the shorter side stops there for all of them, the widgets sit on the corners as drawn and turn the edited corners red at that limit, CSS export writes the drawn radii, and rectangles saved stretched by older versions get circular corners when their corners are next set (#442). Live Corners work on any path's corners too, as on a rectangle's (#511): a star's, a live polygon's (which also shows them to the Selection tool, has a Corner Radius field in the Properties and Transform panels and keeps its radius as its sides change) and a pen path's, wherever two sides meet at an angle at an anchor that isn't smooth: curved sides too, trimmed to what the cut leaves of them (#1144). Direct Selection shows the widgets of every corner, or of the corners holding selected anchors; each corner is a circle tangent to both sides, drawn no larger than takes its cut halfway along its shorter side; a path keeps its uncut outline so its corners stay editable, and the same command, dialog, angle preference and View › Hide Corner Widget apply. With Direct Selection a click on a widget (no drag) selects its corner, as a click on the corner's anchor does, so the next drag on it rounds that corner alone; Shift-click toggles it (#1239). While a corner widget is dragged with the Selection tool the bounding box hides, so the rounding shows against the path alone (#1229). A round corner next to a curved side curves smoothly instead of sticking out of the shape (#1547, fixes #1512).
View › Hide Edges hides the Live Corners widgets, the bounding box and the type widget, and the selection tools then do not answer a press on them or change the cursor over them.
- **Rectangle Properties corner type:** a live rectangle's Rectangle Properties (Transform panel, the Properties panel's Transform section and the Contextual Task Bar's Shape Properties) have a Corner menu with Round, Inverted Round and Chamfer. With Corner Radius linked, one menu sets the kind of every corner of each selected rectangle, also corners with no radius, and shows blank when the shown rectangle's kinds differ; unlinked, each corner's row has its own menu beside its radius field, or under it in a panel too narrow for both; the unlinked radius fields and menus leave other selected paths and polygons as they are. A pick is one undo step, and picking the kind the corners already have adds none (`object.setLiveShape {kind, rectanglesOnly, corners}`); an action that records them acts on the rectangles selected when it plays. The help page says a rectangle's corner type can be set for each corner or for all of them at once ([the help page](https://helpx.adobe.com/illustrator/desktop/draw-shapes-and-paths/modify-live-shapes/live-shape-properties.html)); tying the number of menus to the Corner Radius link, the blank value and the undo steps are VectorCraft's own rules (`a_rectangle_shows_linked_and_unlinked_corner_types`, `the_shape_properties_popup_changes_a_rectangle_corner_type`, `the_linked_corner_menu_sets_every_selected_rectangle`, `the_unlinked_corner_menus_fit_a_narrow_panel`, `an_unlinked_corner_radius_leaves_other_selected_shapes`, `a_rectangle_corner_kind_without_a_selected_rectangle_changes_nothing`, `rectangle_kind_menu_targets_all_or_one_corner_and_skips_noop_undo`, `rectangles_only_sets_the_selected_rectangles_when_an_action_plays`, `a_radius_reaches_a_rectangle_that_already_draws_it`).
- **Polygon side widget:** 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 the edges are shown. Dragging the widget sets the polygon's side count, from 3 to 11, as [the help page](https://helpx.adobe.com/illustrator/desktop/draw-shapes-and-paths/modify-live-shapes/add-or-remove-sides-from-polygons.html) describes; typed counts in the Transform panel and `object.setLiveShape` still go from 3 to 1000. A drag down adds one side and a drag 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}`, so the polygon keeps its center, radius and rotation; the release adds one undo step when the count changed and none when it ends where it began, and Escape puts the count back. The widget's look and place, the drag direction, the step and the rule for more than 11 sides are VectorCraft's own (`crates/tools/src/sidewidget.rs`).
- **Hide/Show Shape Widgets:** with the Rectangle, Rounded Rectangle, Ellipse, Polygon or Star tool, the Control bar shows a Hide Shape Widgets button, which reads Show Shape Widgets while the widgets are hidden (`view.shapeWidgets {on?}`). [The help page](https://helpx.adobe.com/illustrator/using/live-shapes.html) describes this Control panel button, offered with any live shape drawing tool, as switching the on-canvas widgets of selected shapes off and on. While they are hidden, a selected live rectangle's or polygon's corner widgets, a live ellipse's pie widgets and a live polygon's side widget are not drawn, and the Selection tool and those shape tools do not answer a press, a double-click or the cursor on their place (a shape tool draws from there). The bounding box and its handles, the center point and Direct Selection's corner widgets (View › Hide Corner Widget) stay as they are. The setting is on by default, kept with the interface state across sessions and tool switches, and adds no undo step. Its scope beyond the shape tools, its default and what it leaves shown are VectorCraft's own rules (tests `hidden_shape_widgets_leave_the_bounding_box`, `the_shape_tools_control_bar_hides_and_shows_the_shape_widgets`, `shape_widgets_command_toggles_and_takes_on`, `hidden_shape_widgets_do_not_answer_a_shape_tool` and `hidden_shape_widgets_leave_direct_selections_corners`).
- **Blend spine Anchor Point tool (#2544):** on a selected blend, dragging a spine corner makes symmetric Smooth handles; the tool displays and picks existing spine handles when switched to, drags one independently or retracts it on click, and clicking a point with handles retracts both. The spine is edited live without moving its key objects. Windows native canvas checks and screenshots reviewed: symmetric and independent handles, corner/retraction, Shift constraints and perpendicular reshaping, tool switching, key preservation, Undo/Redo, save/reopen, hidden handles and overlapping Path/Blend priority (PR #2643). Behaviour reference: [public path-editing documentation](https://helpx.adobe.com/illustrator/using/adjust-path-segments.html).