Transform: Show on Shape Creation counts shapes drawn in perspective

With the perspective grid shown and a plane active, a Rectangle,
Ellipse, Polygon, Star or Line Segment drag is journaled as
perspective.draw naming the shape command. note_shape_drawn now counts
that entry, alone or as a batch step, so the Transform panel opens for
a shape drawn on the plane too. perspective.draw naming another shape
(a flare, for example) still does not count.

The Transform tests now move a selected rectangle and check that the
move succeeded before checking that the panel stays closed, and check
that the frames after a shape draw the panel's controls, with a control
run where the option is off.
This commit is contained in:
dotCooCoo
2026-11-18 14:27:27 -08:00
parent 80cc17da48
commit 70c0f533f6
6 changed files with 85 additions and 23 deletions
+2 -2
View File
@@ -402,8 +402,8 @@ pub struct Prefs {
pub use_registration_point_for_symbol: bool,
/// The Transform panel menu's Show on Shape Creation: drawing a shape with the Rectangle,
/// Rounded Rectangle, Ellipse, Polygon, Star or Line Segment tool (a drag or OK in the tool's
/// dialog), a shape the Shaper tool recognizes, or running one of [`crate::DRAWS_SHAPE`], shows
/// the Transform panel.
/// dialog, also on the active perspective plane), a shape the Shaper tool recognizes, or running
/// one of [`crate::DRAWS_SHAPE`], shows the Transform panel.
pub show_on_shape_creation: bool,
/// The tools' persistent options by store (a tool id, or a store a family shares: `liquify`
/// holds the Liquify tools' Global Brush Dimensions), see [`vectorcraft_tools::settings`]:
+12 -9
View File
@@ -314,17 +314,20 @@ impl Session {
self.replaying
}
/// Note that journal entry `id` with `params` drew a shape ([`DRAWS_SHAPE`], also as a step of
/// `command.batch`), unless saved steps are playing or a script runs.
/// Note that journal entry `id` with `params` drew a shape ([`DRAWS_SHAPE`], also on the active
/// perspective plane as `perspective.draw` naming one, and as a step of `command.batch`), unless
/// saved steps are playing or a script runs.
pub(crate) fn note_shape_drawn(&mut self, id: &str, params: &Value) {
let draws = |id: &str| DRAWS_SHAPE.contains(&id);
let in_batch = || {
params
.get("commands")
.and_then(Value::as_array)
.is_some_and(|steps| steps.iter().any(|step| step.get("command").and_then(Value::as_str).is_some_and(draws)))
let shape = |id: &str| DRAWS_SHAPE.contains(&id);
let draws = |id: &str, params: Option<&Value>| {
shape(id) || (id == "perspective.draw" && params.and_then(|p| p.get("command")).and_then(Value::as_str).is_some_and(shape))
};
if !self.replaying && !self.script_in_run && (draws(id) || (id == "command.batch" && in_batch())) {
let in_batch = || {
params.get("commands").and_then(Value::as_array).is_some_and(|steps| {
steps.iter().any(|step| step.get("command").and_then(Value::as_str).is_some_and(|c| draws(c, step.get("params"))))
})
};
if !self.replaying && !self.script_in_run && (draws(id, Some(params)) || (id == "command.batch" && in_batch())) {
self.shape_drawn = true;
}
}
+29
View File
@@ -1372,6 +1372,35 @@ fn take_shape_drawn_follows_the_shapes_that_were_drawn() {
assert!(!s.take_shape_drawn(), "a script");
}
/// With the perspective grid shown and a plane active, a shape tool's drag journals
/// `perspective.draw` naming the shape command: `take_shape_drawn` is true for a Rectangle drawn on
/// the plane and for `perspective.draw` naming a shape command (alone or as a batch step), and false
/// for one naming a shape outside [`crate::DRAWS_SHAPE`].
#[test]
fn take_shape_drawn_counts_shapes_drawn_in_perspective() {
use vectorcraft_tools::{PointerEvent, PointerKind};
let (mut s, _) = super::persp_select::persp_session();
s.execute("perspective.grid.show", &json!({"visible": true})).unwrap();
s.execute("perspective.plane.set", &json!({"plane": "left"})).unwrap();
s.execute("select.none", &json!({})).unwrap();
s.take_shape_drawn();
let v = crate::tooling::ViewInfo { smart_guides: false, ..Default::default() };
s.select_tool("rectangle", v).unwrap();
s.pointer(&PointerEvent::new(PointerKind::Down, 250.0, 350.0), v).unwrap();
s.pointer(&PointerEvent::new(PointerKind::Drag, 280.0, 380.0), v).unwrap();
s.pointer(&PointerEvent::new(PointerKind::Up, 300.0, 410.0), v).unwrap();
assert_eq!(s.journal.last().unwrap().0, "perspective.draw");
assert!(s.take_shape_drawn(), "a Rectangle drawn on the plane");
let rect = json!({"x": 260, "y": 360, "width": 30, "height": 30});
s.execute("perspective.draw", &json!({"command": "shape.rectangle", "params": rect})).unwrap();
assert!(s.take_shape_drawn(), "perspective.draw naming shape.rectangle");
s.execute("command.batch", &json!({"commands": [{"command": "perspective.draw", "params": {"command": "shape.ellipse", "params": rect}}]}))
.unwrap();
assert!(s.take_shape_drawn(), "a batch step drawing in perspective");
s.execute("perspective.draw", &json!({"command": "shape.flare", "params": {"cx": 300, "cy": 380, "diameter": 40}})).unwrap();
assert!(!s.take_shape_drawn(), "perspective.draw naming a flare");
}
/// Show on Shape Creation (`showOnShapeCreation`) is off until set, is set and read through
/// `prefs.set` and `prefs.get`, refuses a value that is not a boolean, and is kept with the saved
/// preferences.
+39 -9
View File
@@ -1069,8 +1069,14 @@ fn show_on_shape_creation_shows_the_transform_panel_after_a_shape() {
assert!(!visible(&app), "off: the panel stays closed");
let mut app = app_without_transform_panel();
// A selected rectangle to move, drawn while the preference is off.
let id = app.run("shape.rectangle", rect.clone()).unwrap()["id"].as_u64().unwrap();
app.session.take_shape_drawn();
set_pref(&mut app, "showOnShapeCreation", true);
app.run("object.move", json!({"dx": 5, "dy": 0})).ok();
let x0 = |app: &VectorcraftApp| app.session.active().unwrap().doc.node(vectorcraft_doc::NodeId(id)).unwrap().geometric_bounds().unwrap().x0;
let before = x0(&app);
app.run("object.move", json!({"dx": 5, "dy": 0})).unwrap();
assert_eq!(x0(&app), before + 5.0, "the move moved the rectangle");
show_on_shape_creation(&mut app, &ctx);
assert!(!visible(&app), "an edit that draws no shape");
app.replay("shape.rectangle", rect.clone()).unwrap();
@@ -1111,22 +1117,46 @@ fn show_on_shape_creation_shows_the_transform_panel_after_a_shape() {
assert!(visible(&app), "a floating panel");
}
/// The app's frame shows the Transform panel after a shape is drawn, with Show on Shape Creation on.
/// The app's frame shows the Transform panel after a shape is drawn, with Show on Shape Creation on,
/// and the next frame draws the panel's controls; with it off, no frame draws them.
#[test]
fn a_frame_after_a_shape_shows_the_transform_panel() {
let mut app = app_without_transform_panel();
set_pref(&mut app, "showOnShapeCreation", true);
fn walk(s: &egui::Shape, out: &mut Vec<String>) {
match s {
egui::Shape::Text(t) => out.push(t.galley.text().to_string()),
egui::Shape::Vec(v) => v.iter().for_each(|s| walk(s, out)),
_ => {}
}
}
let ctx = egui::Context::default();
crate::theme::install_fonts(&ctx);
let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1200.0, 800.0));
// One frame of the app: the texts it drew.
let frame = |app: &mut VectorcraftApp| {
let mut out = ctx.run_ui(egui::RawInput { screen_rect: Some(screen), ..Default::default() }, |ui| app.ui(ui));
out.textures_delta.clear();
let mut texts = vec![];
out.shapes.iter().for_each(|c| walk(&c.shape, &mut texts));
texts
};
for _ in 0..3 {
// The Transform panel's heading for a selected live rectangle.
let heading = "Rectangle Properties:";
let rect = json!({"x": 10, "y": 10, "width": 40, "height": 30});
for on in [false, true] {
let mut app = app_without_transform_panel();
set_pref(&mut app, "showOnShapeCreation", on);
for _ in 0..3 {
frame(&mut app);
}
assert!(!crate::panel_docking::visible(&app.ui, "transform"));
app.run("shape.rectangle", rect.clone()).unwrap();
frame(&mut app);
assert_eq!(crate::panel_docking::visible(&app.ui, "transform"), on, "on: {on}");
// The panel opens in its icon column's flyout: the next pass draws the flyout's tabs and the
// one after it the panel's controls.
let tabs = frame(&mut app);
let texts = frame(&mut app);
assert!(!tabs.iter().any(|t| t == heading) || on, "on: {on}, {tabs:?}");
assert_eq!(texts.iter().any(|t| t == heading), on, "on: {on}, {texts:?}");
}
assert!(!crate::panel_docking::visible(&app.ui, "transform"));
app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 40, "height": 30})).unwrap();
frame(&mut app);
assert!(crate::panel_docking::visible(&app.ui, "transform"));
}
+2 -2
View File
@@ -12119,8 +12119,8 @@ and Y at the symbol's registration point (`symbol.options` `registration`) where
(after a flip the art's top-left corner is the box's top-right one), give `reference` as the box's point nearest it
and turn, shear and flip about it (`origin`). Show on Shape Creation is the `showOnShapeCreation` preference (off
until set): with it on, the app shows the Transform panel, as `window.panel {"panel": "transform"}` does, after a
`shape.rectangle`, `shape.ellipse`, `shape.polygon`, `shape.star` or `shape.line` succeeds, alone or as a
`command.batch` step, whether a shape tool's drag, its dialog, the Shaper tool or an agent ran it. A panel that is showing already
`shape.rectangle`, `shape.ellipse`, `shape.polygon`, `shape.star` or `shape.line` succeeds, alone, as a
`command.batch` step or on the active perspective plane as the `command` of `perspective.draw`, whether a shape tool's drag, its dialog, the Shaper tool or an agent ran it. A panel that is showing already
stays as it is. Failed commands, saved steps an action plays, a script's commands and Presentation Mode leave the
panels as they are.
+1 -1
View File
@@ -1110,7 +1110,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
- The History panel menu's Clear History (`edit.clearHistory`) removes every step to undo and to redo and leaves the document as it is; it is not an undo step itself, and it is disabled when there is no step to clear.
- The New Document from State button at the bottom of the History panel (`edit.newDocumentFromState`) makes a new document, which becomes active, from the state the panel has selected ([public source](https://helpx.adobe.com/illustrator/desktop/get-started/learn-the-basics/undo-edits-and-manage-design-history.html)). VectorCraft's own rules: the new document takes the next Untitled-N name, is marked unsaved, has nothing selected and has no steps to undo or redo, and the source document and its steps stay as they are.
- The Transform panel menu's Transform Object Only, Transform Pattern Only and Transform Both (`transformPanelPatterns`) choose whether the fields, flips and menu flips of the Transform panel and the Properties panel's Transform section, and the Control bar's inline X, Y, W and H, move the object and leave its pattern tiles, move the tiles alone, or both (until a choice they follow General › Transform Pattern Tiles, as before); Use Registration Point for Symbol (`useRegistrationPointForSymbol`) measures and transforms one selected symbol instance from its symbol's registration point, where the instance's flips, rotations and shears put it ([Transform panel overview](https://helpx.adobe.com/illustrator/desktop/manage-objects/reshape-transform-objects/transform-panel-overview.html); `panels::transform::tests::the_menu_chooses_whether_the_object_its_pattern_or_both_transform`, `use_registration_point_for_symbol_measures_an_instance_from_its_registration_point`, `use_registration_point_for_symbol_follows_a_transformed_instance`, `tests_prefs::transform_panel_patterns_defaults_to_following_the_general_preference`).
- The Transform panel menu's Show on Shape Creation (`showOnShapeCreation`) shows the Transform panel after a shape is drawn: with the Rectangle, Rounded Rectangle, Ellipse, Polygon, Star or Line Segment tool (a drag, or OK in the tool's dialog), as a rectangle, ellipse, polygon or line that the Shaper tool recognizes, or by a `shape.rectangle`, `shape.ellipse`, `shape.polygon`, `shape.star` or `shape.line` command, alone or as a batch step ([the help page](https://helpx.adobe.com/illustrator/desktop/manage-objects/reshape-transform-objects/transform-panel-overview.html)). VectorCraft's own rules: the option is off until chosen and is kept with the preferences; the panel shows where Window › Transform shows it, and a panel that is showing already stays as it is; a canceled drag or dialog, saved steps an action plays, a script's commands and Presentation Mode leave the panels as they are (`panels::transform::tests::show_on_shape_creation_shows_the_transform_panel_after_a_shape`, `a_frame_after_a_shape_shows_the_transform_panel`, `tests::journal::take_shape_drawn_follows_the_shapes_that_were_drawn`).
- The Transform panel menu's Show on Shape Creation (`showOnShapeCreation`) shows the Transform panel after a shape is drawn: with the Rectangle, Rounded Rectangle, Ellipse, Polygon, Star or Line Segment tool (a drag, or OK in the tool's dialog), as a rectangle, ellipse, polygon or line that the Shaper tool recognizes, or by a `shape.rectangle`, `shape.ellipse`, `shape.polygon`, `shape.star` or `shape.line` command, alone, as a batch step or on the active perspective plane ([the help page](https://helpx.adobe.com/illustrator/desktop/manage-objects/reshape-transform-objects/transform-panel-overview.html)). VectorCraft's own rules: the option is off until chosen and is kept with the preferences; the panel shows where Window › Transform shows it, and a panel that is showing already stays as it is; a canceled drag or dialog, saved steps an action plays, a script's commands and Presentation Mode leave the panels as they are (`panels::transform::tests::show_on_shape_creation_shows_the_transform_panel_after_a_shape`, `a_frame_after_a_shape_shows_the_transform_panel`, `tests::journal::take_shape_drawn_follows_the_shapes_that_were_drawn`, `take_shape_drawn_counts_shapes_drawn_in_perspective`).
- The Transform panel's Align to Pixel Grid checkbox (`object.setPixelAligned`) gives paths and compound paths a pixel-aligned property, saved in the native file: their horizontal and vertical straight segments sit on whole points (half points under an odd centered stroke) with whole stroke weights, and every move, scale, rotation, reflection, Transform Each, Align move, Transform panel change, move of direct-selected anchors or of one anchor, move of a compound path's path on its own, artboard move, resize or copy that carries the art, Duplicate or paste that moves a copy, stroke edit and appearance edit that adds, removes, hides, repaints or reweighs a stroke snaps them again, while diagonal segments and curves keep their shape; a compound path made from an aligned path or compound path is aligned and snaps its paths with its own stroke; the box shows a dash for a mixed selection and is unavailable for type, images and groups ([Pixel-aligned property](https://helpx.adobe.com/illustrator/desktop/get-started/learn-the-basics/pixel-preview-mode-for-web-graphics.html); `tests::pixelalign::turning_it_on_snaps_the_path_in_one_undo_step`, `it_stays_aligned_through_transforms`, `it_stays_aligned_when_its_artboard_moves`, `diagonal_segments_and_curves_keep_their_shape`, `type_and_images_cannot_be_aligned`, `the_property_is_saved_and_read_back`, `stroke_edits_keep_it_aligned`, `a_compound_path_of_aligned_paths_is_aligned`, `a_compound_path_of_an_aligned_compound_path_is_aligned`, `a_stroke_without_paint_snaps_to_whole_points`, `moving_direct_selected_anchors_keeps_it_aligned`, `moving_one_anchor_keeps_it_aligned`, `moving_a_path_of_an_aligned_compound_path_keeps_it_aligned`, `artboard_options_and_artboard_copies_keep_it_aligned`, `appearance_edits_keep_it_aligned`, `placed_gradients_follow_the_snapped_path`, `duplicates_and_pastes_keep_it_aligned`, `paths_added_to_or_moved_in_an_aligned_compound_path_keep_it_aligned`, `the_art_of_a_linked_opacity_mask_keeps_it_aligned`, `a_linked_opacity_mask_follows_a_snap`, `aligning_direct_selected_anchors_keeps_it_aligned`, `global_edit_keeps_its_members_aligned`, `a_path_with_live_corners_snaps_its_inner_edges`, `geometry_edits_keep_it_aligned`, `other_path_edits_keep_it_aligned`, `panels::transform::tests::align_to_pixel_grid_shows_and_sets_the_property`).
- Align New Objects to Pixel Grid (`document.setup {alignNewObjectsToPixelGrid}`, a checkbox in New Document's Advanced Options and a checked item in the Transform panel menu) gives every path and compound path drawn in the document, the paths of a new grid or flare included, the pixel-aligned property, snapped in the step that draws it; it is on in the Mobile and Web presets and off in the others, saved presets and Recent keep it, and the document saves it. Type, images and groups do not take it, and art already in the document, pasted, duplicated or placed keeps its own property (VectorCraft's own rules) ([Pixel-aligned property](https://helpx.adobe.com/illustrator/desktop/get-started/learn-the-basics/pixel-preview-mode-for-web-graphics.html); `tests::pixelalign::align_new_objects_makes_new_paths_pixel_aligned`, `align_new_objects_reaches_grids_flares_and_add_on_shapes`, `align_new_objects_is_saved_and_read_back`, `tests::newdoc::align_new_objects_to_pixel_grid_follows_the_preset`, `panels::transform::tests::align_new_objects_menu_item_toggles_the_active_document`, `dialogs::new_document::tests::align_new_objects_checkbox_follows_the_preset_and_reaches_the_document`).
- The Transform panel works out its Align to Pixel Grid checkbox once for each document revision and reuses it on later frames, and lists the selected objects' ids only when the box is clicked. The box shows the same state. With Select All of 99,500 objects (100,000 paths, 1,000 of them in 500 compound paths), working the state out on every frame took a median 33.5 ms of thread CPU time per frame in a release build on a loaded machine; the first frame after a change now takes 31.5 ms and later frames take about 1 ns (`panels::transform::tests::align_to_pixel_grid_kept_state_equals_a_full_measure`, `align_to_pixel_grid_state_is_measured_once_per_revision`, `pixel_aligned_state_timing`).