From 269c33ea556be935b056477525de4601c7e7d686 Mon Sep 17 00:00:00 2001 From: David Mann Date: Sun, 22 Nov 2026 22:25:17 +0100 Subject: [PATCH] Crop: a move of a turned document crop may take the frame past its bounds A turned frame stopped at the image's edge on a move (photocraft#16460); the reference application lets it go past and fills the area there, as for an upright frame (photocraft#16404). Only the turn itself still keeps the frame inside the turned image (photocraft#10869). Co-Authored-By: Claude Opus 5.5 --- crates/ui-canvas/src/canvas/crop/gesture.rs | 10 +++++----- crates/ui-canvas/tests/it/canvas/crop.rs | 19 +++++++++++++++++-- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/crates/ui-canvas/src/canvas/crop/gesture.rs b/crates/ui-canvas/src/canvas/crop/gesture.rs index 6f4cda17e..18e106e5b 100644 --- a/crates/ui-canvas/src/canvas/crop/gesture.rs +++ b/crates/ui-canvas/src/canvas/crop/gesture.rs @@ -70,8 +70,8 @@ pub(super) struct Rules { pub image: bool, pub auto_center: bool, pub fills_uncovered: bool, - /// An edge or corner drag, and a move of an upright frame, may take the frame past `bounds`: the crop grows the - /// canvas there, as in the reference application (a document crop, not one bounded by a placed picture's source). + /// An edge or corner drag, and a move, may take the frame past `bounds`, turned or not: the crop grows the canvas + /// there, as in the reference application (a document crop, not one bounded by a placed picture's source). pub resize_grows: bool, /// The canvas's snapping, with this pass's tolerance. pub snap: Option, @@ -110,9 +110,9 @@ impl Rules { (CropBox::upright(drawn(*anchor, *cur, self.ratio, mods)), true, self.ratio.is_some() || mods.shift) } Kind::Move => { - // A moved document crop may take in the area past the canvas, as an edge drag does (photocraft#16404); - // a turned frame stays inside the image it turns over (#10869). - grows = self.resize_grows && at.angle == 0.0; + // A moved document crop may take in the area past the canvas, as an edge drag does (photocraft#16404), + // also once turned (photocraft#16460): only the turn itself keeps the frame inside the image (#10869). + grows = self.resize_grows; let by = if self.image { drag.from - to } else { to - drag.from }; (at.moved(by), false, false) } diff --git a/crates/ui-canvas/tests/it/canvas/crop.rs b/crates/ui-canvas/tests/it/canvas/crop.rs index 9a74fb579..a090560ab 100644 --- a/crates/ui-canvas/tests/it/canvas/crop.rs +++ b/crates/ui-canvas/tests/it/canvas/crop.rs @@ -862,13 +862,28 @@ fn a_document_crop_moved_past_its_bounds_takes_in_the_area_there() { "image mode, auto centre {auto_center}: the frame moves past the canvas: {r:?}" ); } - // A turned frame keeps inside the canvas. + // A turned frame moves past the canvas too (photocraft#16460): in Classic Mode past the right edge, in image mode + // (the image turned under an upright frame on screen) past the left edge. let mut setup = Setup::new(); setup.bounds = Some(canvas); let mut rig = Rig::new(CropBox::new(RECT, 10.0), setup); rig.drag(rig.at(200.0, 150.0), rig.at(300.0, 150.0), Modifiers::NONE); let b = rig.crop().turned_bounds(); - assert!(b.x1 <= canvas.x1 + 1e-6, "a turned frame's move stays inside: {b:?}"); + assert!(b.x1 > canvas.x1 + 1.0, "classic: a turned frame moves past the canvas: {b:?}"); + assert!((rig.rect().width() - RECT.width()).abs() < 1e-6, "classic: a turned frame keeps its size: {:?}", rig.rect()); + for auto_center in [false, true] { + let mut setup = Setup::image(10.0, auto_center); + setup.bounds = Some(canvas); + let mut rig = Rig::new(CropBox::new(RECT, 10.0), setup); + rig.drag(rig.at(200.0, 150.0), rig.at(300.0, 150.0), Modifiers::NONE); + let b = rig.crop().turned_bounds(); + assert!(b.x0 < canvas.x0 - 1.0, "image mode, auto centre {auto_center}: a turned frame moves past the canvas: {b:?}"); + assert!( + (rig.rect().width() - RECT.width()).abs() < 1e-6, + "image mode, auto centre {auto_center}: a turned frame keeps its size: {:?}", + rig.rect() + ); + } } #[trial]