From db27e2c1c71fd588fde290a6201317ec589fb5d4 Mon Sep 17 00:00:00 2001 From: aiongg Date: Mon, 16 Nov 2026 21:12:00 +0000 Subject: [PATCH] Crop overlay: a crop that fills what a turn uncovers keeps the press frame; Content-Aware Fill sets it --- crates/draw/src/ui/crop/tool.rs | 3 +++ crates/ui-canvas/src/canvas/crop/gesture.rs | 5 +++-- crates/ui-canvas/src/canvas/crop/mod.rs | 6 ++++++ crates/ui-canvas/tests/it/canvas/crop.rs | 17 +++++++++++++++++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/crates/draw/src/ui/crop/tool.rs b/crates/draw/src/ui/crop/tool.rs index ae858e0f4..323dc281e 100644 --- a/crates/draw/src/ui/crop/tool.rs +++ b/crates/draw/src/ui/crop/tool.rs @@ -265,6 +265,9 @@ impl CropTool { if settings.delete_pixels { overlay = overlay.bounds(document.canvas()); } + if settings.fill == CropFill::ContentAware { + overlay = overlay.fills_uncovered(); + } if settings.image_mode() { overlay = overlay.image_mode(); } diff --git a/crates/ui-canvas/src/canvas/crop/gesture.rs b/crates/ui-canvas/src/canvas/crop/gesture.rs index c3412d21e..17fc6511e 100644 --- a/crates/ui-canvas/src/canvas/crop/gesture.rs +++ b/crates/ui-canvas/src/canvas/crop/gesture.rs @@ -69,6 +69,7 @@ pub(super) struct Rules { pub turn_step: f64, pub image: bool, pub auto_center: bool, + pub fills_uncovered: bool, /// The canvas's snapping, with this pass's tolerance. pub snap: Option, pub os: Platform, @@ -122,9 +123,9 @@ impl Rules { match self.bounds.filter(|_| self.image) { // An image-mode turn keeps the frame inside the turned image (#10869), each step from the press // frame so turning back gives it back. ⌘ keeps the press frame, and so does a press frame that - // was already past the bounds. + // was already past the bounds, and a crop that fills what the turn uncovers. Some(bounds) => { - let keeps_press = mods.cmd || at.kept_inside(bounds) != Some(at); + let keeps_press = mods.cmd || self.fills_uncovered || at.kept_inside(bounds) != Some(at); let kept = if keeps_press { Some(turned) } else { turned.kept_inside(bounds) }; return kept.filter(CropBox::is_finite).or(Some(drag.last)); } diff --git a/crates/ui-canvas/src/canvas/crop/mod.rs b/crates/ui-canvas/src/canvas/crop/mod.rs index 6127b5d77..8e29a03fc 100644 --- a/crates/ui-canvas/src/canvas/crop/mod.rs +++ b/crates/ui-canvas/src/canvas/crop/mod.rs @@ -163,6 +163,10 @@ pub struct CropOverlay<'a> { /// middle of the canvas. #[prop(flag)] auto_center: bool, + /// The crop fills what the turned image leaves uncovered (Content-Aware Fill), so an image-mode turn leaves the + /// frame as it was at the press instead of moving or shrinking it inside the bounds. + #[prop(flag)] + fills_uncovered: bool, /// Nothing is painted and a press anywhere on the canvas draws a new frame. #[prop(flag)] hidden: bool, @@ -185,6 +189,7 @@ impl<'a> CropOverlay<'a> { bounds: None, image_mode: false, auto_center: false, + fills_uncovered: false, hidden: false, report: Report::default(), } @@ -199,6 +204,7 @@ impl<'a> CropOverlay<'a> { turn_step: self.turn_step, image: self.image_mode, auto_center: self.auto_center, + fills_uncovered: self.fills_uncovered, snap: canvas_snap(env), os: env.shell().os, } diff --git a/crates/ui-canvas/tests/it/canvas/crop.rs b/crates/ui-canvas/tests/it/canvas/crop.rs index 021b46f07..60ac8cabc 100644 --- a/crates/ui-canvas/tests/it/canvas/crop.rs +++ b/crates/ui-canvas/tests/it/canvas/crop.rs @@ -32,6 +32,7 @@ struct Setup { default_frame: bool, image_mode: bool, auto_center: bool, + fills_uncovered: bool, hidden: bool, bounds: Option, snap_x: Option, @@ -49,6 +50,7 @@ impl Setup { default_frame: false, image_mode: false, auto_center: false, + fills_uncovered: false, hidden: false, bounds: None, snap_x: None, @@ -148,6 +150,9 @@ impl Rig { if s.straighten { overlay = overlay.straighten(); } + if s.fills_uncovered { + overlay = overlay.fills_uncovered(); + } if s.hidden { overlay = overlay.hidden(); } @@ -688,6 +693,18 @@ fn a_default_turn_keeps_the_frame_inside_the_turned_image() { assert_eq!(rig.rect(), past.rect, "the frame was past the image at the press"); rig.release(end); + // A crop that fills what the turn uncovers keeps the press frame. + let mut s = Setup::new(); + s.image_mode = true; + s.bounds = Some(image); + s.fills_uncovered = true; + s.view = crop_view(&edge, &s.view); + let mut rig = Rig::new(edge, s); + let (_, end) = turn_by(&mut rig, &[10.0, 20.0], 120.0, Modifiers::NONE); + assert!(rig.crop().angle.abs() > 1.0, "it turned: {:?}", rig.crop()); + assert_eq!(rig.rect(), edge.rect, "the fill covers what the turn uncovers"); + rig.release(end); + // A Classic Mode turn that would leave the image is refused: both steps leave it. let mut rig = rig_for(fits, false); let (_, end) = turn_by(&mut rig, &[30.0, 40.0], 140.0, Modifiers::NONE);