From 15b8a33cb44394e8b0277c6f57cd722348b5b9da Mon Sep 17 00:00:00 2001 From: David Mann Date: Sun, 18 Oct 2026 02:50:36 +0200 Subject: [PATCH 1/3] Rotated view: Type box and Move marquee previews follow the document axes (#7063) The Type tools' drag box and the Move tool's layer marquee were drawn as an upright screen rectangle through two mapped corners, while the release creates a document-axis box (the text box, layer.selectInRect). In a rotated view the preview and the result disagreed; at 45 degrees a dragged square previewed as a sliver. Map the four document corners to the screen instead, as the selection marquee does since #2512. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/canvas.rs | 13 +++++++++++-- crates/ui-egui/src/marquee_tests.rs | 25 +++++++++++++++++++++++++ crates/ui-egui/src/move_box.rs | 3 +-- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index 914d395acc..6f42f616d1 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -373,6 +373,15 @@ pub(crate) fn marquee_drag_ants(d: &Drag, xf: &ViewXform, marquee: Option<[f64; marquee_ants(xf, d.tool, a, b) } +/// The corners on screen of the document-axis box dragged from `a` to `b`, clockwise from its +/// top-left: a turned parallelogram in a rotated view, as the box the release creates (the Type +/// tools' text box, the Move tool's layer marquee). +pub(crate) fn doc_box_corners(xf: &ViewXform, a: [f64; 2], b: [f64; 2]) -> [Pos2; 4] { + let (x0, x1) = (a[0].min(b[0]) as f32, a[0].max(b[0]) as f32); + let (y0, y1) = (a[1].min(b[1]) as f32, a[1].max(b[1]) as f32); + [xf.to_screen(x0, y0), xf.to_screen(x1, y0), xf.to_screen(x1, y1), xf.to_screen(x0, y1)] +} + /// The size readout shown beside the cursor while dragging a marquee: the width and height values. pub fn marquee_readout(r: [f64; 4]) -> [String; 2] { [format!("{} px", r[2] - r[0]), format!("{} px", r[3] - r[1])] @@ -4976,8 +4985,8 @@ fn draw_drag_preview(app: &mut PhotocraftApp, painter: &egui::Painter, xf: &View painter.circle_filled(b, 3.0, Color32::WHITE); } Tool::Type | Tool::VerticalType | Tool::HorizontalTypeMask | Tool::VerticalTypeMask => { - let r = Rect::from_two_pos(xf.to_screen(d.start[0] as f32, d.start[1] as f32), xf.to_screen(last[0] as f32, last[1] as f32)); - let pts = [r.left_top(), r.right_top(), r.right_bottom(), r.left_bottom(), r.left_top()]; + let [p0, p1, p2, p3] = doc_box_corners(xf, d.start, last); + let pts = [p0, p1, p2, p3, p0]; painter.add(egui::Shape::line(pts.to_vec(), Stroke::new(1.0, Color32::WHITE))); painter.add(egui::Shape::dashed_line(&pts, Stroke::new(1.0, Color32::BLACK), 3.0, 3.0)); } diff --git a/crates/ui-egui/src/marquee_tests.rs b/crates/ui-egui/src/marquee_tests.rs index 169d4588b9..107de7c7d5 100644 --- a/crates/ui-egui/src/marquee_tests.rs +++ b/crates/ui-egui/src/marquee_tests.rs @@ -299,6 +299,31 @@ fn the_live_outline_matches_the_committed_selection_in_a_rotated_view() { } } +/// #7063: the Type tools' text box and the Move tool's layer marquee preview the document-axis box +/// the release creates, not an upright screen box through two of its corners (at 45° that box +/// flattens a dragged square into a sliver). +#[test] +fn the_type_box_and_layer_marquee_previews_follow_a_rotated_view() { + for rotation in [30.0, 45.0] { + let xf = ViewXform { + rect: egui::Rect::from_min_size(Pos2::ZERO, vec2(800.0, 600.0)), + zoom: 1.5, + center: [200.0, 150.0], + flip: false, + rotation, + aspect: 1.0, + }; + for (a, b) in [([100.0, 100.0], [300.0, 200.0]), ([300.0, 300.0], [100.0, 100.0])] { + let pts = crate::canvas::doc_box_corners(&xf, a, b); + let (x0, x1, y0, y1) = (a[0].min(b[0]), a[0].max(b[0]), a[1].min(b[1]), a[1].max(b[1])); + let want = [[x0, y0], [x1, y0], [x1, y1], [x0, y1]].map(|[x, y]| xf.to_screen(x as f32, y as f32)); + for (i, (p, w)) in pts.iter().zip(want).enumerate() { + assert!((p.x - w.x).abs() < 0.01 && (p.y - w.y).abs() < 0.01, "{rotation}°: corner {i} at {p:?}, the document box's corner is at {w:?}"); + } + } + } +} + /// 800 %, snapping off, the view centred on (30, 30): the pointer lands between pixel edges. fn zoomed(tool: Tool) -> Harness<'static, PhotocraftApp> { let mut h = harness(tool); diff --git a/crates/ui-egui/src/move_box.rs b/crates/ui-egui/src/move_box.rs index ccbfd9cb4f..5ae202b913 100644 --- a/crates/ui-egui/src/move_box.rs +++ b/crates/ui-egui/src/move_box.rs @@ -68,8 +68,7 @@ pub(crate) fn pointer(app: &mut PhotocraftApp, ev: ToolEvent) -> bool { /// The marquee as marching ants. pub(crate) fn draw(app: &PhotocraftApp, painter: &egui::Painter, xf: &ViewXform) { let Some(b) = app.layer_box else { return }; - let r = egui::Rect::from_two_pos(xf.to_screen(b.start[0] as f32, b.start[1] as f32), xf.to_screen(b.end[0] as f32, b.end[1] as f32)); - crate::tool_feedback::draw_ants(painter, &[r.left_top(), r.right_top(), r.right_bottom(), r.left_bottom()], true); + crate::tool_feedback::draw_ants(painter, &crate::canvas::doc_box_corners(xf, b.start, b.end), true); } #[cfg(test)] From e9c04fa545c0f0fa1037dafd47dc4de2fcde5dbc Mon Sep 17 00:00:00 2001 From: David Mann Date: Wed, 21 Oct 2026 10:20:33 +0200 Subject: [PATCH 2/3] Address review: the rotated-view tests check the drawn Type box and Move marquee MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace the test that recomputed `doc_box_corners` with its own formula by two harness tests that drag in a 30° and 45° view and read the outline the canvas actually painted: the Type tools' preview must map back onto the text box the release creates, the Move tool's layer marquee onto the dragged document box. Both fail if `draw_drag_preview` or `move_box::draw` go back to the upright screen box. Co-Authored-By: Claude Opus 5.5 (1M context) --- crates/ui-egui/src/marquee_tests.rs | 102 ++++++++++++++++++++++------ 1 file changed, 81 insertions(+), 21 deletions(-) diff --git a/crates/ui-egui/src/marquee_tests.rs b/crates/ui-egui/src/marquee_tests.rs index a0f0fae560..c813a877c5 100644 --- a/crates/ui-egui/src/marquee_tests.rs +++ b/crates/ui-egui/src/marquee_tests.rs @@ -299,28 +299,88 @@ fn the_live_outline_matches_the_committed_selection_in_a_rotated_view() { } } -/// #7063: the Type tools' text box and the Move tool's layer marquee preview the document-axis box -/// the release creates, not an upright screen box through two of its corners (at 45° that box -/// flattens a dragged square into a sliver). -#[test] -fn the_type_box_and_layer_marquee_previews_follow_a_rotated_view() { - for rotation in [30.0, 45.0] { - let xf = ViewXform { - rect: egui::Rect::from_min_size(Pos2::ZERO, vec2(800.0, 600.0)), - zoom: 1.5, - center: [200.0, 150.0], - flip: false, - rotation, - aspect: 1.0, - }; - for (a, b) in [([100.0, 100.0], [300.0, 200.0]), ([300.0, 300.0], [100.0, 100.0])] { - let pts = crate::canvas::doc_box_corners(&xf, a, b); - let (x0, x1, y0, y1) = (a[0].min(b[0]), a[0].max(b[0]), a[1].min(b[1]), a[1].max(b[1])); - let want = [[x0, y0], [x1, y0], [x1, y1], [x0, y1]].map(|[x, y]| xf.to_screen(x as f32, y as f32)); - for (i, (p, w)) in pts.iter().zip(want).enumerate() { - assert!((p.x - w.x).abs() < 0.01 && (p.y - w.y).abs() < 0.01, "{rotation}°: corner {i} at {p:?}, the document box's corner is at {w:?}"); +/// The closed outlines the last frame drew as a solid white line under black dashes: the Type +/// tools' drag box and the Move tool's layer marquee (four corners, the first repeated). +fn white_box_outlines(h: &Harness<'static, PhotocraftApp>) -> Vec> { + h.output() + .shapes + .iter() + .filter_map(|c| match &c.shape { + egui::Shape::Path(p) + if matches!(p.stroke.color, egui::epaint::ColorMode::Solid(col) if col == egui::Color32::WHITE) + && p.points.len() == 5 + && p.points.first() == p.points.last() => + { + Some(p.points.clone()) } - } + _ => None, + }) + .collect() +} + +/// Every drawn corner of `outline` maps back, through the view, to the document corner of `want` +/// ([x0, y0, x1, y1]) with the same index, clockwise from the top-left. +fn assert_doc_box(xf: &ViewXform, outline: &[Pos2], want: [f64; 4], what: &str) { + let corners = [[want[0], want[1]], [want[2], want[1]], [want[2], want[3]], [want[0], want[3]]]; + for (i, (p, w)) in outline.iter().zip(corners).enumerate() { + let [x, y] = xf.to_doc(*p); + assert!( + (x - w[0]).abs() <= 1.0 && (y - w[1]).abs() <= 1.0, + "{what}: corner {i} drawn at {p:?} is document ({x:.1}, {y:.1}), the box's corner is {w:?}" + ); + } +} + +/// #7063: in a rotated view the Type tools' drag box previews the document-axis text box the +/// release creates. An upright screen box through two of its corners is another shape (at 45° a +/// dragged square previews as a sliver). +#[test] +fn the_type_drag_box_matches_the_committed_text_box_in_a_rotated_view() { + for rotation in [30.0, 45.0] { + let mut h = harness(Tool::Type); + h.state_mut().ui.extras.snap = false; + h.state_mut().ui.views[0].rotation = rotation; + h.run_steps(2); + press_at(&mut h, 50.0, 50.0, Modifiers::NONE); + move_to(&mut h, 150.0, 90.0); + let xf = view_xform(&h); + let drawn = white_box_outlines(&h); + assert_eq!(drawn.len(), 1, "{rotation}°: one text box is previewed: {drawn:?}"); + release_at(&mut h, 150.0, 90.0, Modifiers::NONE); + // The text box the release created, in document pixels. + let committed = { + let st = h.state().session.active().unwrap(); + let layer = st.doc.layer(st.active_layer.unwrap()).unwrap(); + let photocraft_doc::LayerContent::Text(t) = &layer.content else { panic!("{rotation}°: a type layer") }; + let photocraft_doc::text::TextShape::Box { x, y, width, height } = t.shape else { panic!("{rotation}°: paragraph text") }; + let (tx, ty) = (t.transform.m[4], t.transform.m[5]); + [tx + f64::from(x), ty + f64::from(y), tx + f64::from(x + width), ty + f64::from(y + height)] + }; + assert!((committed[0] - 50.0).abs() <= 1.0 && (committed[3] - 90.0).abs() <= 1.0, "{rotation}°: the drag made {committed:?}"); + assert_doc_box(&xf, &drawn[0], committed, &format!("{rotation}°: the Type preview")); + } +} + +/// #7063: in a rotated view the Move tool's layer marquee (#2844) previews the document-axis box +/// `layer.selectInRect` gets on the release, not an upright screen box through two of its corners. +#[test] +fn the_move_layer_marquee_follows_the_document_axes_in_a_rotated_view() { + for rotation in [30.0, 45.0] { + let mut h = harness(Tool::Move); + let app = h.state_mut(); + app.ui.extras.snap = false; + app.ui.tool_options.move_auto_select = true; + app.ui.views[0].rotation = rotation; + h.run_steps(2); + // On the locked Background, so the drag draws the marquee (#4058). + press_at(&mut h, 50.0, 50.0, Modifiers::NONE); + move_to(&mut h, 150.0, 90.0); + assert!(h.state().layer_box.is_some(), "{rotation}°: the drag draws the layer marquee"); + let xf = view_xform(&h); + let drawn = white_box_outlines(&h); + assert_eq!(drawn.len(), 1, "{rotation}°: one marquee is drawn: {drawn:?}"); + assert_doc_box(&xf, &drawn[0], [50.0, 50.0, 150.0, 90.0], &format!("{rotation}°: the layer marquee")); + release_at(&mut h, 150.0, 90.0, Modifiers::NONE); } } From 75bc29f6c5cedd265ca996cdbe7e2bfc7ddab8c2 Mon Sep 17 00:00:00 2001 From: David Mann Date: Thu, 29 Oct 2026 17:02:09 +0100 Subject: [PATCH 3/3] Tests: the Move marquee test reads the slanted ant edges main's device-pixel ants draw Main's #7530 draws marching ants as a pixel mesh plus white base segments for slanted edges, so the rotated Move-tool marquee is no longer one white closed path. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/marquee_tests.rs | 32 +++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/crates/ui-egui/src/marquee_tests.rs b/crates/ui-egui/src/marquee_tests.rs index af590ea9f2..6cf286b52b 100644 --- a/crates/ui-egui/src/marquee_tests.rs +++ b/crates/ui-egui/src/marquee_tests.rs @@ -455,7 +455,7 @@ fn the_live_outline_matches_the_committed_selection_in_a_rotated_view() { } /// The closed outlines the last frame drew as a solid white line under black dashes: the Type -/// tools' drag box and the Move tool's layer marquee (four corners, the first repeated). +/// tools' drag box (four corners, the first repeated). fn white_box_outlines(h: &Harness<'static, PhotocraftApp>) -> Vec> { h.output() .shapes @@ -473,6 +473,20 @@ fn white_box_outlines(h: &Harness<'static, PhotocraftApp>) -> Vec> { .collect() } +/// The slanted edges the last frame drew as marching ants (#7530): each is a white base segment +/// under black dashes (`ants::shapes`); upright edges go into a pixel mesh instead. The Move tool's +/// layer marquee in a rotated view. +fn white_ant_edges(h: &Harness<'static, PhotocraftApp>) -> Vec<[Pos2; 2]> { + h.output() + .shapes + .iter() + .filter_map(|c| match &c.shape { + egui::Shape::LineSegment { points, stroke } if stroke.color == egui::Color32::WHITE => Some(*points), + _ => None, + }) + .collect() +} + /// Every drawn corner of `outline` maps back, through the view, to the document corner of `want` /// ([x0, y0, x1, y1]) with the same index, clockwise from the top-left. fn assert_doc_box(xf: &ViewXform, outline: &[Pos2], want: [f64; 4], what: &str) { @@ -532,9 +546,19 @@ fn the_move_layer_marquee_follows_the_document_axes_in_a_rotated_view() { move_to(&mut h, 150.0, 90.0); assert!(h.state().layer_box.is_some(), "{rotation}°: the drag draws the layer marquee"); let xf = view_xform(&h); - let drawn = white_box_outlines(&h); - assert_eq!(drawn.len(), 1, "{rotation}°: one marquee is drawn: {drawn:?}"); - assert_doc_box(&xf, &drawn[0], [50.0, 50.0, 150.0, 90.0], &format!("{rotation}°: the layer marquee")); + // Four slanted ant edges, each from one corner of the document box to the next. An upright + // screen box would have none (its edges go into the ants' pixel mesh). + let edges = white_ant_edges(&h); + assert_eq!(edges.len(), 4, "{rotation}°: the marquee's four edges are drawn slanted: {edges:?}"); + let ends: Vec = edges.iter().map(|e| e[0]).collect(); + assert_doc_box(&xf, &ends, [50.0, 50.0, 150.0, 90.0], &format!("{rotation}°: the layer marquee (edge starts)")); + let ends: Vec = edges.iter().map(|e| e[1]).collect(); + assert_doc_box( + &xf, + &ends[3..].iter().chain(&ends[..3]).copied().collect::>(), + [50.0, 50.0, 150.0, 90.0], + &format!("{rotation}°: the layer marquee (edge ends)"), + ); release_at(&mut h, 150.0, 90.0, Modifiers::NONE); } }