Keep opposite edge fixed when resizing with side handles

This commit is contained in:
Dandaedre 2026-11-13 13:35:43 +01:00
parent cbb1681b04
commit 8ea50141e6
4 changed files with 27 additions and 13 deletions

View File

@ -1338,7 +1338,7 @@ impl Editor {
ink.text(
24.0,
r.height() - 57.0,
"Corners resize · Side handles resize symmetrically · Shift-click selects",
"Corners resize · Side handles keep opposite edge fixed · Shift-click selects",
12.0,
MUTED,
);
@ -1606,7 +1606,12 @@ mod tests {
);
frame(&mut app, &ctx, vec![mouse(start + delta, false)]);
let after = app.layout.layers()[1];
assert_eq!(after.center(), before.center());
match side {
0 => assert_eq!(after.y + after.height, before.y + before.height),
1 => assert_eq!(after.y, before.y),
2 => assert_eq!(after.x + after.width, before.x + before.width),
_ => assert_eq!(after.x, before.x),
}
if side < 2 {
assert!(after.height > before.height);
assert_eq!(after.width, before.width);

View File

@ -657,7 +657,7 @@ impl Layout {
let horizontal = matches!(r.handle, ResizeHandle::Left | ResizeHandle::Right);
let (width, height) = if side {
if horizontal {
let width = (original.width + 2.0 * dx).max(if r.keep_ratio {
let width = (original.width + dx).max(if r.keep_ratio {
(original.width / original.height).max(1.0)
} else {
1.0
@ -671,7 +671,7 @@ impl Layout {
},
)
} else {
let height = (original.height + 2.0 * dy).max(if r.keep_ratio {
let height = (original.height + dy).max(if r.keep_ratio {
(original.height / original.width).max(1.0)
} else {
1.0
@ -698,14 +698,14 @@ impl Layout {
)
};
let next = Geometry {
x: if side {
x: if side && !horizontal {
original.center()[0] - width / 2.0
} else if left {
original.x + original.width - width
} else {
original.x
},
y: if side {
y: if side && horizontal {
original.center()[1] - height / 2.0
} else if top {
original.y + original.height - height

View File

@ -643,7 +643,7 @@ fn free_resize_changes_ratio_and_cancels_without_flipping_or_moving_locked_layer
}
#[test]
fn midpoint_handles_resize_symmetrically_and_preserve_undo_and_ratio() {
fn midpoint_handles_fix_opposite_edge_and_preserve_undo_and_ratio() {
use midra_layout::ResizeHandle as H;
for handle in [H::Left, H::Right, H::Top, H::Bottom] {
for keep_ratio in [true, false] {
@ -665,15 +665,23 @@ fn midpoint_handles_resize_symmetrically_and_preserve_undo_and_ratio() {
layout.drag_to(end);
layout.finish_drag();
let after = layout.layers()[1];
assert_eq!(after.center(), center);
match handle {
H::Left => assert_eq!(after.x + after.width, before[1].x + before[1].width),
H::Right => assert_eq!(after.x, before[1].x),
H::Top => assert_eq!(after.y + after.height, before[1].y + before[1].height),
H::Bottom => assert_eq!(after.y, before[1].y),
_ => unreachable!(),
}
assert_eq!(layout.layers()[0], before[0]);
if matches!(handle, H::Left | H::Right) {
assert_eq!(after.width, 680.0);
assert_eq!(after.width, 660.0);
assert_eq!(after.center()[1], center[1]);
if !keep_ratio {
assert_eq!(after.height, 360.0);
}
} else {
assert_eq!(after.height, 400.0);
assert_eq!(after.height, 380.0);
assert_eq!(after.center()[0], center[0]);
if !keep_ratio {
assert_eq!(after.width, 640.0);
}

View File

@ -289,8 +289,9 @@ viewing/copying or applying unchanged rounded fields does not quantize the docum
This presentation rule does not validate the hardware's crop/container mapping.
Each selected box also has a handle at the middle of every side. Dragging top or
bottom resizes height equally about the center; left or right resizes width the
same way. With the aspect lock enabled, the other dimension scales around the
same center. Disable it to change just one axis. Corner handles still keep the
bottom resizes height with the opposite edge fixed; left or right does the same
for width. With the aspect lock enabled, the other dimension scales around its
center, keeping the opposite edge’s midpoint fixed. Disable it to change just
one axis. Corner handles still keep the
opposite corner fixed. Crop preservation, lock protection, Escape and Undo apply
to both kinds of resize handles.