diff --git a/crates/midra-layout/src/gui.rs b/crates/midra-layout/src/gui.rs index d9ef463..d6507b7 100644 --- a/crates/midra-layout/src/gui.rs +++ b/crates/midra-layout/src/gui.rs @@ -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); diff --git a/crates/midra-layout/src/lib.rs b/crates/midra-layout/src/lib.rs index 7a7a2c2..dc0f456 100644 --- a/crates/midra-layout/src/lib.rs +++ b/crates/midra-layout/src/lib.rs @@ -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 diff --git a/crates/midra-layout/tests/positioning.rs b/crates/midra-layout/tests/positioning.rs index f5a80be..59b4575 100644 --- a/crates/midra-layout/tests/positioning.rs +++ b/crates/midra-layout/tests/positioning.rs @@ -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); } diff --git a/docs/midra-layout.md b/docs/midra-layout.md index 3fb2244..09014c9 100644 --- a/docs/midra-layout.md +++ b/docs/midra-layout.md @@ -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.