PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Merge PR #7530: Marching ants in device pixels, like the reference app (#7489)
aiongg42efb8d77736
diff --cc crates/ui-egui/src/canvas.rsindex dbbab1368,bdc24142f..874e45f5e--- a/crates/ui-egui/src/canvas.rs+++ b/crates/ui-egui/src/canvas.rs@@@ -5647,16 -5104,7 +5560,16 @@@ fn draw_drag_preview(app: &mut Photocraif let Some(lasso) = &d.lasso {pts.push(xf.to_screen(lasso.cursor[0] as f32, lasso.cursor[1] as f32));}- // On pixel centres like the marquee's ants, so a 1 pt line stays crisp wherever the- // canvas sits (a pixel edge would blur it to grey).- let pts: Vec<Pos2> = pts.into_iter().map(|p| p.round() + vec2(0.5, 0.5)).collect();- crate::tool_feedback::draw_ants(painter, &pts, false);+ // The Lasso's outline is solid until the release makes the selection (#7495); a Patch+ // or Content-Aware Move area keeps its ants.+ if d.tool == Tool::Lasso {++ // On pixel centres, so a 1 pt line stays crisp wherever the canvas sits (a pixel++ // edge would blur it to grey).++ let pts: Vec<Pos2> = pts.into_iter().map(|p| p.round() + vec2(0.5, 0.5)).collect();+ crate::tool_feedback::draw_solid_path(painter, &pts, false);+ } else {+ crate::tool_feedback::draw_ants(painter, &pts, false);+ }}Tool::Gradient => {let a = xf.to_screen(d.start[0] as f32, d.start[1] as f32);diff --cc crates/ui-egui/src/tool_feedback.rsindex 58bd14cce,e50714405..ce6cbb9e4--- a/crates/ui-egui/src/tool_feedback.rs+++ b/crates/ui-egui/src/tool_feedback.rs@@@ -168,69 -168,12 +168,26 @@@ pub fn draw_badge(painter: &egui::Paint}}- /// Dash length of the marching ants, in screen points.- pub const DASH: f32 = 4.0;-- /// Marching ants along a polyline: a solid white line under black dashes, the dashes shifted by- /// `phase` (animate it with time). Visible on any image, like Photoshop's selection edges.- pub fn ants(points: &[Pos2], closed: bool, phase: f32) -> Vec<Shape> {- let Some(&first) = points.first().filter(|_| points.len() >= 2) else { return Vec::new() };- let mut pts = points.to_vec();- if closed {- pts.push(first);- }- let mut out = vec![Shape::line(pts.clone(), Stroke::new(1.0, Color32::WHITE))];- let black = Stroke::new(1.0, Color32::BLACK);- // Arc length so dashes run continuously across vertices.- let mut along = -phase.rem_euclid(DASH * 2.0);- for w in pts.windows(2) {- let (a, b) = (w[0], w[1]);- let len = a.distance(b);- if len < 1e-3 {- continue;- }- let dir = (b - a) / len;- // Position of this segment's start within the dash period.- let mut t = -(along.rem_euclid(DASH * 2.0));- while t < len {- let (s0, s1) = (t.max(0.0), (t + DASH).min(len));- if s1 > s0 {- out.push(Shape::line_segment([a + dir * s0, a + dir * s1], black));- }- t += DASH * 2.0;- }- along += len;- }- out- }-- /// Marching-ants phase for the frame time `time` (s), and keep the animation running.- pub fn ants_phase(ctx: &egui::Context) -> f32 {- let time = ctx.input(|i| i.time);- ctx.request_repaint_after(std::time::Duration::from_millis(100));- ((time * 10.0) % (DASH as f64 * 2.0)) as f32- }-- /// Draw animated marching ants along `points`.+ /// Draw animated marching ants along `points`: the same ants as a selection's (`crate::ants`),+ /// visible on any image, like Photoshop's selection edges.pub fn draw_ants(painter: &egui::Painter, points: &[Pos2], closed: bool) {- let phase = ants_phase(painter.ctx());- painter.extend(ants(points, closed, phase));+ crate::ants::draw_polyline(painter, points, closed);}+/// A selection outline still being drawn (Lasso, Polygonal Lasso, Magnetic Lasso): a solid line,+/// as Photoshop draws it until the selection is made (#7495). Marching ants are for selections+/// that exist. A thin dark line on a soft light edge: Photoshop's look on light pixels, and still+/// visible on dark ones.+pub fn solid_path(points: &[Pos2], closed: bool) -> Vec<Shape> {+ let make = |s: Stroke| if closed { Shape::closed_line(points.to_vec(), s) } else { Shape::line(points.to_vec(), s) };+ vec![make(Stroke::new(3.0, Color32::from_white_alpha(140))), make(Stroke::new(1.0, Color32::BLACK))]+}++/// Draw [`solid_path`].+pub fn draw_solid_path(painter: &egui::Painter, points: &[Pos2], closed: bool) {+ painter.extend(solid_path(points, closed));+}+/// Polygon approximating the ellipse inscribed in `r` (enough vertices to look smooth).pub fn ellipse_points(r: egui::Rect) -> Vec<Pos2> {let (c, a, b) = (r.center(), r.width() / 2.0, r.height() / 2.0);@@@ -308,36 -251,9 +265,21 @@@ mod testsassert!(badge_glyph(Badge::Intersect, c, 3.0).iter().all(|[a, b]| a.x != b.x && a.y != b.y));}+ /// #7495: an outline still being drawn is one unbroken line (no dashes, nothing marching),+ /// black over a light edge.+ #[test]+ fn solid_path_is_one_unbroken_dark_line_on_a_light_edge() {+ let pts = [pos2(0.0, 0.0), pos2(40.0, 0.0), pos2(40.0, 30.0)];+ for closed in [false, true] {+ let shapes = solid_path(&pts, closed);+ assert!(shapes.iter().all(|s| matches!(s, Shape::Path(p) if p.closed == closed && p.points.len() == 3)), "{shapes:?}");+ assert_eq!(strokes(&shapes), vec![Color32::from_white_alpha(140), Color32::BLACK], "the dark line on top");+ }+ }+#[test]- fn ants_use_two_contrasting_colours_and_march() {+ fn shape_previews_contrast_and_ellipses_close() {let pts = [pos2(0.0, 0.0), pos2(40.0, 0.0), pos2(40.0, 30.0)];- let a = ants(&pts, true, 0.0);- let cols = strokes(&a);- assert!(cols.contains(&Color32::WHITE) && cols.contains(&Color32::BLACK), "{cols:?}");- // Roughly half the length is black dashes: (40 + 30 + 50) / 8 ≈ 15 dashes.- let dashes = cols.iter().filter(|c| **c == Color32::BLACK).count();- assert!((13..=18).contains(&dashes), "{dashes}");- // The phase moves the dashes (the ants march).- let first = |s: &[Shape]| {- s.iter().find_map(|s| match s {- Shape::LineSegment { points, stroke } if stroke.color == Color32::BLACK => Some(points[0]),- _ => None,- })- };- assert_ne!(first(&a), first(&ants(&pts, true, 2.0)));- assert!(ants(&pts[..1], false, 0.0).is_empty());// Shape previews: the accent path over a dark halo.let s = contrast_path(pts.to_vec(), true, Color32::from_rgb(0, 120, 255));let cols = strokes(&s);diff --cc docs/ui-parity.mdindex b7ace1f65,ea41d6b90..620e30fc4--- a/docs/ui-parity.md+++ b/docs/ui-parity.md@@@ -1,6 -1,6 +1,6 @@@# UI parity: tools, handles, modifiers and feel- > **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-21 · **Change:** minor (Hand tool ⌘ / ⌥ are Zoom In / Zoom Out while held, #6434; the wheel steps value fields, #5473; a dragged guide shows its X or Y beside the pointer, #7680; Type options bar "T" icon scrubs the font size, #6437; Move tool: dragged selected pixels take their own outline as the selection, #7538; artboard backgrounds remain below child Free Transform previews; ⌫/Delete removes the selected smart filter, #4751; Object Finder foreground/background discrimination (#6548); rounded triangle, polygon and star corners; shape Fill/Stroke popovers accept hex RGB values, #6176; a guide let go over either ruler is removed, #6286; Crop rows corrected: saved crop presets and Delete Cropped Pixels off are done, #6562; Animated Zoom: holding the Zoom tool zooms continuously, #6210; shape Density and Feather, TOOL-214-12, #5846; Pen Auto Add/Delete on the path being drawn, #6140; Show Transform Controls frames every selected layer; guide keys and clicks; menu bar from the keyboard, #4988; Crop tool Content-Aware Fill; on-canvas corner radius widgets, TOOL-214-12; Curvature Pen edits the active path; Clip Thumbnails to Layer Bounds; Pen ⇧ 45°; last selected tool restored at launch; Layers panel filter-type dropdown with Kind, Name and Mode, #5048; Free Transform box and marching ants follow the selection, #5297; History: the trash deletes the selected snapshot, rows drag onto the trash, #5324; smart filter reordering by drag; smart object perspective row corrected to done, #426; Free Transform H/V skew fields; toolbar tool shortcuts can be reassigned; ⇧-dragged guides land on ruler ticks; layer and selection keys; tool keys; spring-loaded tool letters; type formatting keys; Pen Auto Add/Delete, #4144; smart filter rows; stale missing-tool rows corrected: Color Replacement, Red Eye and the Add/Delete Anchor Point pair are live toolbar tools, Frame landed; no percentage changed; selection-modifier and ⌥-wheel rows match their tests) · **Target:** Adobe Photoshop 2026-> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-21 · **Change:** minor (marching ants in device pixels, #7489; Animated Zoom: holding the Zoom tool zooms continuously, #6210; shape Density and Feather, TOOL-214-12, #5846; Pen Auto Add/Delete on the path being drawn, #6140; Show Transform Controls frames every selected layer; guide keys and clicks; menu bar from the keyboard, #4988; Crop tool Content-Aware Fill; on-canvas corner radius widgets, TOOL-214-12; Curvature Pen edits the active path; Clip Thumbnails to Layer Bounds; Pen ⇧ 45°; last selected tool restored at launch; Layers panel filter-type dropdown with Kind, Name and Mode, #5048; Free Transform box and marching ants follow the selection, #5297; History: the trash deletes the selected snapshot, rows drag onto the trash, #5324; smart filter reordering by drag; smart object perspective row corrected to done, #426; Free Transform H/V skew fields; toolbar tool shortcuts can be reassigned; ⇧-dragged guides land on ruler ticks; layer and selection keys; tool keys; spring-loaded tool letters; type formatting keys; Pen Auto Add/Delete, #4144; smart filter rows; stale missing-tool rows corrected: Color Replacement, Red Eye and the Add/Delete Anchor Point pair are live toolbar tools, Frame landed; no percentage changed; selection-modifier and ⌥-wheel rows match their tests) · **Target:** Adobe Photoshop 2026++> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-21 · **Change:** minor (Hand tool ⌘ / ⌥ are Zoom In / Zoom Out while held, #6434; the wheel steps value fields, #5473; a dragged guide shows its X or Y beside the pointer, #7680; Type options bar "T" icon scrubs the font size, #6437; Move tool: dragged selected pixels take their own outline as the selection, #7538; artboard backgrounds remain below child Free Transform previews; ⌫/Delete removes the selected smart filter, #4751; Object Finder foreground/background discrimination (#6548); rounded triangle, polygon and star corners; shape Fill/Stroke popovers accept hex RGB values, #6176; a guide let go over either ruler is removed, #6286; Crop rows corrected: saved crop presets and Delete Cropped Pixels off are done, #6562; marching ants in device pixels, #7489; Animated Zoom: holding the Zoom tool zooms continuously, #6210; shape Density and Feather, TOOL-214-12, #5846; Pen Auto Add/Delete on the path being drawn, #6140; Show Transform Controls frames every selected layer; guide keys and clicks; menu bar from the keyboard, #4988; Crop tool Content-Aware Fill; on-canvas corner radius widgets, TOOL-214-12; Curvature Pen edits the active path; Clip Thumbnails to Layer Bounds; Pen ⇧ 45°; last selected tool restored at launch; Layers panel filter-type dropdown with Kind, Name and Mode, #5048; Free Transform box and marching ants follow the selection, #5297; History: the trash deletes the selected snapshot, rows drag onto the trash, #5324; smart filter reordering by drag; smart object perspective row corrected to done, #426; Free Transform H/V skew fields; toolbar tool shortcuts can be reassigned; ⇧-dragged guides land on ruler ticks; layer and selection keys; tool keys; spring-loaded tool letters; type formatting keys; Pen Auto Add/Delete, #4144; smart filter rows; stale missing-tool rows corrected: Color Replacement, Red Eye and the Add/Delete Anchor Point pair are live toolbar tools, Frame landed; no percentage changed; selection-modifier and ⌥-wheel rows match their tests) · **Target:** Adobe Photoshop 2026How PhotoCraft's direct manipulation compares with Photoshop 2026 (27.11.0): the toolbox, thehandles and modifier keys of each gesture, nudging, snapping, numeric precision, navigation,@@@ -282,8 -263,4 +283,9 @@@ Paragraph; the rest open as in-app floa| 2026-10-14 | minor | Last selected tool restored across launches; temporary overrides excluded, explicit Eraser choices retained, and final selection flushed on normal exit || 2026-10-13 | minor | Free Transform with a selection: the box is the selection's rectangle, and the marching ants follow it while it is transformed (#5297) || 2026-10-14 | minor | Move › Show Transform Controls frames every selected layer and outlines the selected shapes |+| 2026-10-21 | minor | Crop rows corrected against the code and the scorecard: saved custom crop presets (TOOL-214-9, #2723) and Delete Cropped Pixels off are done (#6562); no percentage changed |+| 2026-10-20 | minor | Free Transform of an artboard child omits ancestor paper from the covering and isolated composites while retaining board clipping. The base canvas and whole-artboard backgrounds are preserved; synthetic regressions in `transform_tool.rs`. No parity percentage changed. |+| 2026-10-18 | minor | Move tool: dragging selected pixels shrinks the marching ants to the moved pixels as the drag starts, and the dropped selection is theirs, as in Photoshop (#7538) |+ | 2026-10-18 | minor | Marching ants drawn in device pixels like Photoshop's: equally thick on every edge at 125 %/150 % display scale, thicker on HiDPI, slanted dash ends (#7489) |+| 2026-10-15 | minor | ⌫/Delete with a smart filter row selected removes that filter (the Smart Filters row: all of them), as the Delete button does, instead of the smart object (#4751) |+| 2026-10-14 | minor | Rounded corners on live triangles, polygons and stars: Properties field and on-canvas widgets (TOOL-214-12) |