mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-27 03:35:15 +00:00
Crop: an edge or corner drag may take a document crop past its bounds
The Crop tool bounds the overlay by the canvas while Delete Cropped Pixels is on so that an image-mode turn keeps the frame inside the image (photocraft#10869). The drag rules also cut every edge and corner resize to those bounds, so a crop could not grow the canvas. In the reference application it does. A resize of a document crop now goes past the bounds; turns, moves, drawn frames, nudges and a placed picture's crop (bounded by its source) are unchanged. Fixes storytold/photocraft#16043. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
eb8e6c98e9
commit
c49a12a99d
@@ -70,6 +70,9 @@ pub(super) struct Rules {
|
|||||||
pub image: bool,
|
pub image: bool,
|
||||||
pub auto_center: bool,
|
pub auto_center: bool,
|
||||||
pub fills_uncovered: bool,
|
pub fills_uncovered: bool,
|
||||||
|
/// An edge or corner drag 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).
|
||||||
|
pub resize_grows: bool,
|
||||||
/// The canvas's snapping, with this pass's tolerance.
|
/// The canvas's snapping, with this pass's tolerance.
|
||||||
pub snap: Option<Snap>,
|
pub snap: Option<Snap>,
|
||||||
pub os: Platform,
|
pub os: Platform,
|
||||||
@@ -89,6 +92,7 @@ impl Rules {
|
|||||||
/// as it was (a draw not yet sized) or cannot be kept inside.
|
/// as it was (a draw not yet sized) or cannot be kept inside.
|
||||||
pub fn proposal(&self, drag: &mut Drag, to: Point, mods: Mods, space: bool) -> Option<CropBox> {
|
pub fn proposal(&self, drag: &mut Drag, to: Point, mods: Mods, space: bool) -> Option<CropBox> {
|
||||||
let at = drag.at_press;
|
let at = drag.at_press;
|
||||||
|
let mut grows = false;
|
||||||
let (next, resizing, held) = match &mut drag.kind {
|
let (next, resizing, held) = match &mut drag.kind {
|
||||||
Kind::Draw { anchor, cur, last } => {
|
Kind::Draw { anchor, cur, last } => {
|
||||||
if space {
|
if space {
|
||||||
@@ -115,6 +119,7 @@ impl Rules {
|
|||||||
} else {
|
} else {
|
||||||
at.resized(*part, by, hold, mods.alt)
|
at.resized(*part, by, hold, mods.alt)
|
||||||
};
|
};
|
||||||
|
grows = self.resize_grows;
|
||||||
(next, true, self.ratio.is_some() || mods.shift)
|
(next, true, self.ratio.is_some() || mods.shift)
|
||||||
}
|
}
|
||||||
Kind::Turn { grab } => {
|
Kind::Turn { grab } => {
|
||||||
@@ -137,7 +142,7 @@ impl Rules {
|
|||||||
if !next.is_finite() {
|
if !next.is_finite() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
match self.bounds {
|
match self.bounds.filter(|_| !grows) {
|
||||||
Some(bounds) => next.within(bounds, resizing, held).or(Some(drag.last)),
|
Some(bounds) => next.within(bounds, resizing, held).or(Some(drag.last)),
|
||||||
None => Some(next),
|
None => Some(next),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -154,7 +154,8 @@ pub struct CropOverlay<'a> {
|
|||||||
#[prop(flag)]
|
#[prop(flag)]
|
||||||
straighten: bool,
|
straighten: bool,
|
||||||
/// The area the frame may not leave, in document units. An image-mode turn moves or shrinks the frame to keep it
|
/// The area the frame may not leave, in document units. An image-mode turn moves or shrinks the frame to keep it
|
||||||
/// inside (Command keeps it as it was at the press).
|
/// inside (Command keeps it as it was at the press). An edge or corner drag of a document crop may still take it
|
||||||
|
/// past them: the crop grows the canvas.
|
||||||
#[prop]
|
#[prop]
|
||||||
bounds: Option<DocRect>,
|
bounds: Option<DocRect>,
|
||||||
/// Image mode: the frame stays upright on screen and a move or turn moves or turns the view instead.
|
/// Image mode: the frame stays upright on screen and a move or turn moves or turns the view instead.
|
||||||
@@ -232,6 +233,7 @@ impl<'a> CropOverlay<'a> {
|
|||||||
image: self.image_mode,
|
image: self.image_mode,
|
||||||
auto_center: self.auto_center,
|
auto_center: self.auto_center,
|
||||||
fills_uncovered: self.fills_uncovered,
|
fills_uncovered: self.fills_uncovered,
|
||||||
|
resize_grows: matches!(self.scope, CropScope::Document),
|
||||||
snap: canvas_snap(env),
|
snap: canvas_snap(env),
|
||||||
os: env.shell().os,
|
os: env.shell().os,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -803,6 +803,33 @@ fn a_shift_corner_follows_the_diagonal_and_snaps_along_it() {
|
|||||||
assert!(rig.seen.borrow().snapped.is_empty(), "no snap line reported");
|
assert!(rig.seen.borrow().snapped.is_empty(), "no snap line reported");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[trial]
|
||||||
|
fn a_document_crop_grows_past_its_bounds_on_an_edge_or_corner_drag_only() {
|
||||||
|
// The canvas as the bounds, as the Crop tool sets them with Delete Cropped Pixels on.
|
||||||
|
let canvas = Rect::new(50.0, 50.0, 350.0, 250.0);
|
||||||
|
for (what, base) in [("classic", Setup::new()), ("image mode", Setup::image(0.0, false))] {
|
||||||
|
let mut setup = base;
|
||||||
|
setup.bounds = Some(canvas);
|
||||||
|
// An edge dragged past the canvas takes the frame with it: the crop grows the canvas there.
|
||||||
|
let mut rig = Rig::new(CropBox::upright(RECT), setup.clone());
|
||||||
|
rig.drag(rig.at(RECT.x1, 150.0), rig.at(380.0, 150.0), Modifiers::NONE);
|
||||||
|
let r = rig.rect();
|
||||||
|
assert!((r.x1 - 380.0).abs() < 1e-6 && r.x0 == RECT.x0, "{what}: the right edge follows past the canvas: {r:?}");
|
||||||
|
// So does a corner.
|
||||||
|
let mut rig = Rig::new(CropBox::upright(RECT), setup.clone());
|
||||||
|
rig.drag(rig.at(RECT.x1, RECT.y1), rig.at(380.0, 280.0), Modifiers::NONE);
|
||||||
|
let r = rig.rect();
|
||||||
|
assert!(r.x1 > canvas.x1 + 1.0 && r.y1 > canvas.y1 + 1.0, "{what}: the corner follows past the canvas: {r:?}");
|
||||||
|
}
|
||||||
|
// A classic move still stops at the canvas.
|
||||||
|
let mut setup = Setup::new();
|
||||||
|
setup.bounds = Some(canvas);
|
||||||
|
let mut rig = Rig::new(CropBox::upright(RECT), setup);
|
||||||
|
rig.drag(rig.at(200.0, 150.0), rig.at(300.0, 150.0), Modifiers::NONE);
|
||||||
|
let r = rig.rect();
|
||||||
|
assert!(r.x1 <= canvas.x1 + 1e-6 && (r.width() - RECT.width()).abs() < 1e-6, "a move stays inside: {r:?}");
|
||||||
|
}
|
||||||
|
|
||||||
#[trial]
|
#[trial]
|
||||||
fn an_object_crop_is_bounded_by_its_source_and_a_press_outside_it_reaches_what_lies_beneath() {
|
fn an_object_crop_is_bounded_by_its_source_and_a_press_outside_it_reaches_what_lies_beneath() {
|
||||||
let source = Rect::new(50.0, 50.0, 350.0, 250.0);
|
let source = Rect::new(50.0, 50.0, 350.0, 250.0);
|
||||||
|
|||||||
Reference in New Issue
Block a user