diff --git a/crates/engine/src/tests/smartguides.rs b/crates/engine/src/tests/smartguides.rs index 8bb6a0dfb..7e2741c64 100644 --- a/crates/engine/src/tests/smartguides.rs +++ b/crates/engine/src/tests/smartguides.rs @@ -89,6 +89,37 @@ fn a_pen_anchor_lines_up_with_another_objects_centre() { assert!((pts[2] - Point::new(100.0, 381.0)).hypot() < 1e-9, "{pts:?}"); } +/// View › Pixel Preview turns Smart Guides off in the tools: a moved square no longer lines up with +/// the other square's top and shows no guide, and a Rectangle tool corner no longer lands on its +/// anchor. +#[test] +fn pixel_preview_turns_smart_guides_off() { + for pixel in [false, true] { + let view = ViewInfo { pixel_preview: pixel, ..ViewInfo::default() }; + let mut s = session(); + let b = s.execute("shape.rectangle", &json!({"x": 400, "y": 300, "width": 50, "height": 50})).unwrap()["id"].as_u64().unwrap(); + s.select_tool("selection", view).unwrap(); + s.execute("select.set", &json!({"ids": [b]})).unwrap(); + s.pointer(&PointerEvent::new(PointerKind::Down, 425.0, 325.0), view).unwrap(); + for y in [300.0, 250.0, 200.0, 150.0, 128.0] { + s.pointer(&PointerEvent::new(PointerKind::Drag, 425.0, y), view).unwrap(); + } + let guides = s.overlays(view).into_iter().filter(|o| matches!(o, Overlay::Line { .. } | Overlay::Label { .. })).count(); + s.pointer(&PointerEvent::new(PointerKind::Up, 425.0, 128.0), view).unwrap(); + let top = s.doc().unwrap().doc.node(NodeId(b)).unwrap().geometric_bounds().unwrap().y0; + assert_eq!((top, guides > 0), if pixel { (103.0, false) } else { (100.0, true) }, "Pixel Preview {pixel}"); + + s.select_tool("rectangle", view).unwrap(); + for (kind, x, y) in + [(PointerKind::Down, 302.0, 297.0), (PointerKind::Drag, 250.0, 250.0), (PointerKind::Drag, 202.0, 203.0), (PointerKind::Up, 202.0, 203.0)] + { + s.pointer(&PointerEvent::new(kind, x, y), view).unwrap(); + } + let r = made(&s); + assert_eq!((r.x0, r.y0), if pixel { (202.0, 203.0) } else { (200.0, 200.0) }, "Pixel Preview {pixel}"); + } +} + /// Preferences › Smart Guides › Construction Guides: on (the default), a Pen anchor near the /// 45° guide through the last one lands on it; off, it stays where it was clicked. #[test] diff --git a/crates/engine/src/tooling.rs b/crates/engine/src/tooling.rs index 3f364c2ce..e1b212d3a 100644 --- a/crates/engine/src/tooling.rs +++ b/crates/engine/src/tooling.rs @@ -22,6 +22,8 @@ pub struct ViewInfo { /// View → Show Guides: the ruler guides show (and, unlocked, can be picked). pub guides: bool, pub snap_to_grid: bool, + /// View → Pixel Preview: while it is on, the tools use no Smart Guides. + pub pixel_preview: bool, pub show_bbox: bool, /// View → Snap to Pixel: drawing and moving land on whole pixels (points at 72 ppi). pub snap_to_pixel: bool, @@ -46,6 +48,7 @@ impl Default for ViewInfo { smart_guides: true, guides: true, snap_to_grid: false, + pixel_preview: false, show_bbox: true, snap_to_pixel: false, snap_to_point: true, @@ -335,6 +338,7 @@ impl Session { { let Some(st) = self.active.and_then(|i| self.docs.get(i)) else { return R::default() }; let (unit, stroke_unit) = (self.general_unit(), self.stroke_unit()); + let smart_guides = view.smart_guides && !view.pixel_preview; let cx = ToolContext { doc: &st.doc, ruler_origin: st.doc.ruler_origin_for(view.artboard), @@ -344,7 +348,7 @@ impl Session { isolation: st.isolation, paint: &self.paint, outline: view.outline, - smart_guides: view.smart_guides, + smart_guides, guides: view.guides && !self.menu.guides_locked, snap_to_grid: view.snap_to_grid, show_bbox: view.show_bbox, @@ -354,7 +358,7 @@ impl Session { snap_to_point: view.snap_to_point, snap_tangent: self.prefs.snap_tangent, snap_perpendicular: self.prefs.snap_perpendicular, - snap_to_glyph: view.snap_to_glyph && view.smart_guides && !view.snap_to_grid, + snap_to_glyph: view.snap_to_glyph && smart_guides && !view.snap_to_grid, glyph_snap: self.prefs.glyph_snap, corner_widgets: view.corner_widgets, fill_active: self.fill_active, diff --git a/crates/ui-egui/src/app/view.rs b/crates/ui-egui/src/app/view.rs index 6aa3eab76..f88367cb6 100644 --- a/crates/ui-egui/src/app/view.rs +++ b/crates/ui-egui/src/app/view.rs @@ -117,6 +117,7 @@ impl VectorcraftApp { smart_guides: self.ui.view.smart_guides, guides: self.ui.view.guides, snap_to_grid: self.ui.view.snap_to_grid, + pixel_preview: self.ui.view.pixel_preview, snap_to_pixel: self.ui.view.snap_to_pixel, // View › Hide Edges: the canvas draws neither the bounding box (with the type widget) // nor the Live Corners widgets, and the tools do not answer the pointer on them. diff --git a/crates/ui-egui/src/canvas/tests.rs b/crates/ui-egui/src/canvas/tests.rs index a891179a6..418c7ad1a 100644 --- a/crates/ui-egui/src/canvas/tests.rs +++ b/crates/ui-egui/src/canvas/tests.rs @@ -3723,6 +3723,34 @@ fn snap_to_grid_and_pixel_preview_hide_the_hover_outline() { assert!(outlines(&mut app) > 0, "Pixel Preview off again"); } +/// View › Pixel Preview turns Smart Guides off in the tools: a square moved to 3 pt below another +/// square's top lines up with it only while Pixel Preview is off. +#[test] +fn pixel_preview_stops_smart_guides_snapping_a_move() { + for pixel in [false, true] { + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + app.session.execute("file.new", &json!({"width": 800, "height": 600})).unwrap(); + app.session.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 100, "height": 100})).unwrap(); + let id = app.session.execute("shape.rectangle", &json!({"x": 400, "y": 300, "width": 50, "height": 50})).unwrap()["id"].as_u64().unwrap(); + if pixel { + app.run("view.pixelPreview", json!({})).unwrap(); + } + assert!(app.ui.view.smart_guides); + assert_eq!(app.ui.view.pixel_preview, pixel); + app.run("select.set", json!({"ids": [id]})).unwrap(); + app.select_tool("selection"); + let view = app.view_info(); + let mut at = |kind: PointerKind, y: f64| crate::canvas::dispatch(&mut app, &PointerEvent::new(kind, 425.0, y), view); + at(PointerKind::Down, 325.0); + for y in [300.0, 250.0, 200.0, 150.0, 128.0] { + at(PointerKind::Drag, y); + } + at(PointerKind::Up, 128.0); + let top = app.session.active().unwrap().doc.node(vectorcraft_doc::NodeId(id)).unwrap().geometric_bounds().unwrap().y0; + assert_eq!(top, if pixel { 103.0 } else { 100.0 }, "Pixel Preview {pixel}"); + } +} + /// #2452: while the view scrolls under a resting pointer, the art under it isn't hit-tested: /// no hover outline, and the tool's last cursor stays. Once the view has been still for /// [`HOVER_STILL_SECS`], the outline comes back without the pointer moving. diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index c8d10fc0b..014921ea3 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1010,6 +1010,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - **Drawing aids:** Smart Guides and snapping (moving, with the Selection, Group Selection or Direct Selection tool, and resizing by the bounding-box handles with the Selection or Free Transform tool, Shift and Alt too: the dragged corner or side lands on the other objects' anchors and centres ("anchor", "center") or lines up with their edges and centres (a line and "align"); with Smart Guides › Spacing Guides, a moved selection that lines up with nothing along an axis lands as far from its neighbour as two other objects of its row or column are apart, or halfway between its two neighbours, the equal gaps marked; with View › Snap to Grid on, a moved selection lands on the grid instead, by whichever of its edges is nearest a gridline on each axis (the center does not snap), #740, #1816; the Rotate, Scale, Shear and Reflect tools drag from the anchor they grab and snap the pointer the same way, so a corner dragged onto another object's anchor scales exactly onto it, #482; anchors dragged with Direct Selection: the one pressed on lands on other anchors, its own path's that stay put among them, on path segments or in line with them, the others following, Shift keeps 45° steps, and with Smart Guides off Snap to Point pulls it onto anchors; the Artboard tool snaps artboards, and their bleed, to other artboards, bleeds and art, the grid or whole pixels while moving, copying and resizing them, and the Transform panel shows and edits the active artboard's X/Y/W/H; drawn points, #506: hovering shows where the press goes, the point lands on the other objects' anchors, centres and paths ("anchor", "center", "path") or lines up with their anchors, edges and centres ("align"), the Pen's on the path being drawn too, near a construction guide through the anchor before it on that guide (Preferences › Smart Guides › Construction Guides and Angles), and with Shift kept to its 45° step or a square's diagonal it slides along that way into line; the targets are gathered once per document state, from the art in the window, and the anchors, centres and lines near the pointer are found by bisection, so hovering never rescans the document), guides dragged out of the rulers (#451: they snap as moved guides do, Shift to the ruler's ticks; with the Artboard tool they are artboard guides, which run across their artboard only and move, copy and delete with it, `guide.add {artboard}`) that the Selection, Direct Selection and Group Selection tools then pick and drag (#414: the selected guides highlight and move together, Alt copies them, Shift snaps the dragged one to the ticks, otherwise it snaps to pixels, the grid or the edges, centres (so the sides' midpoints) and anchors of the art and the artboards, or with Smart Guides off Snap to Point pulls it onto anchors; Shift-clicked they join the selected art, and Shift-added art keeps them, so guides and art are selected together in either order, Delete then deleting both in one step; the arrow keys nudge them, Delete deletes them, dragging one back onto its ruler deletes it, Lock Guides and Hide Guides leave them alone; `guide.list`, `guide.select`, `guide.move` and `guide.remove` reach agents), a right-click on either ruler or the origin box to pick the document's units (the current one checked; `document.setUnits`, one undo step, #528), and Draw Normal / Behind / Inside modes. Smart Guides: a point drawn with the Pen or a shape tool, and an anchor dragged with Direct Selection, snaps to where paths and ruler guides cross, labelled "intersect" (#1658, part of #1602; a moved selection's own anchors don't). A move that Shift keeps level, upright or diagonal stays on that line when it snaps, with the Selection, Group Selection or Direct Selection tool. It slides along the line until the selection lands on the grid or on whole pixels, lines up with the other objects or is spaced evenly with them, or until the line passes an anchor or crosses a ruler guide near the point the selection was grabbed by. A level or upright move snaps along its own axis only. Snap to Last Location: with Smart Guides on and Preferences › Smart Guides › Snap to Last Location on (off by default, VectorCraft's own choice), a selection moved by dragging with the Selection, Group Selection or Direct Selection tool, Shift too, goes back to where the move began while it is within Snapping Tolerance of it, labeled "last location"; an Alt copy is not pulled back onto its original, and with View › Snap to Grid or Snap to Pixel on the move snaps to the grid or to whole pixels instead (`prefs.set` key `snapToLastLocation`). The public [Smart Guides options](https://helpx.adobe.com/illustrator/desktop/measure-and-align/grids-and-guides/smart-guides-options.html) page lists the option as snapping objects back to their previous position; the distance, the label, the copy rule and the grid and pixel rule are VectorCraft's own. Tests: `select::tests::snap_to_last_location_puts_a_move_back_where_it_began`, `select::tests::snap_to_pixel_wins_over_snap_to_last_location`, `direct::tests::snap_to_last_location_puts_a_path_moved_by_its_anchor_back`, `direct::tests::snap_to_pixel_wins_over_snap_to_last_location_for_a_path_moved_by_its_anchor`, `tests_prefs::snap_to_last_location_puts_a_dragged_square_back`. + Pixel Preview: with View › Pixel Preview on, the tools use no Smart Guides. Nothing snaps to Smart Guides or shows their guides, and Snap to Point acts as it does with Smart Guides off. View › Smart Guides keeps its setting and applies again when Pixel Preview is turned off. [Work with Smart Guides](https://helpx.adobe.com/illustrator/desktop/measure-and-align/grids-and-guides/work-with-smart-guides.html) says Smart Guides cannot be used while Pixel Preview is on. Tests: `tests::smartguides::pixel_preview_turns_smart_guides_off`, `canvas::tests::pixel_preview_stops_smart_guides_snapping_a_move`. Distance Guides: with Smart Guides on (View › Smart Guides and Preferences › Smart Guides › Invoke Distance Guides, on by default), something selected and the Selection tool, holding Alt/Option over another object shows the distances between the selection's bounds and that object's: on an axis on which they lie apart, one line across the gap between their facing edges; on one on which they overlap, the offsets of their left and right (top and bottom) edges, each line running across the middle of where they overlap, with a dashed line out to the other object's edge when it passes beside it. Over an empty part of an artboard it shows the selection's distances from the artboard's left, right, top and bottom edges. Each line has ticks at its ends and its length in a pill of the smart guide colour, in the General unit; letting Alt go, pressing (a pan or zoom press too), moving off them, leaving the canvas or a floating panel, menu or dialog over the pointer takes them away, and with the pointer still they follow what lies under it as the view scrolls, zooms or turns, as the document, the tab or the selection changes, and when the Selection tool is switched to. Behaviour from the public [Use Distance Guides for accurate placement](https://helpx.adobe.com/illustrator/desktop/measure-and-align/grids-and-guides/use-distance-guides-for-accurate-placement.html) and [Smart Guides options](https://helpx.adobe.com/illustrator/desktop/measure-and-align/grids-and-guides/smart-guides-options.html) pages, which describe hovering only: nothing shows while moving or nudging. Tests: `select::tests::alt_over_*`, `select::tests::distance_guides_need_alt_a_selection_and_smart_guides`, `tests_prefs::invoke_distance_guides_measures_the_selection_to_the_object_under_alt`, `canvas::tests::alt_over_another_object_draws_the_distance_guide_label`, `canvas::tests::distance_guides_go_when_the_hover_ends`, `canvas::tests::distance_guides_follow_what_lies_under_a_still_pointer`. A move pressed on a path's stroke, or within 6 px of its outline away from its anchors and center, is held by the nearest point of that path, with the Selection, Group Selection or Direct Selection tool, and a straight segment Direct Selection drags is held by its own nearest point. That point is what snaps, so the path lands exactly on a ruler guide (with "align") instead of the pressed spot landing there and the path a few pixels beside it, an offset that showed only zoomed far in (#3701). A press in the middle of a fill still snaps the pressed spot: the public [Align objects with guides](https://helpx.adobe.com/illustrator/desktop/measure-and-align/grids-and-guides/align-graphic-objects-with-guides.html) page has Snap to Point align the point under the pointer, which is placed exactly where the object should meet the guide. A bounding-box handle dragged with the Selection or Free Transform tool snaps what it moves as a dragged point snaps (#2054). With View › Snap to Grid on, it snaps to the nearest gridline, and with Snap to Pixel on, it snaps to whole pixels. With Smart Guides off and Snap to Point on, it snaps to the other objects' anchors and the ruler guides within the Snap to Point distance. With Smart Guides and Snap to Point both on, it lines up with the ruler guides as well as the other objects. Shift still keeps the proportions, and Alt still scales about the center.