Fix proportional resize snapping and add Shift inversion
This commit is contained in:
parent
ad7c48f49b
commit
65299e1d6f
|
|
@ -1892,7 +1892,7 @@ impl Editor {
|
|||
} else if let Some(i) = content {
|
||||
self.layout.start_content_drag(i, point);
|
||||
}
|
||||
} else if let Some((i, corner)) = handle.filter(|_| !shift) {
|
||||
} else if let Some((i, corner)) = handle {
|
||||
if let Err(e) = self.layout.start_selected_resize(
|
||||
i,
|
||||
corner,
|
||||
|
|
@ -1924,6 +1924,9 @@ impl Editor {
|
|||
}
|
||||
self.snap_guides = [None; 2];
|
||||
let mut snapping = self.snapping;
|
||||
if self.layout.resizing() && ui.input(|i| i.modifiers.shift) {
|
||||
snapping.enabled = !snapping.enabled;
|
||||
}
|
||||
if ui.input(|i| i.modifiers.alt) {
|
||||
snapping.enabled = false;
|
||||
}
|
||||
|
|
@ -3853,6 +3856,61 @@ mod tests {
|
|||
assert_eq!(*app.layout.layers(), before);
|
||||
}
|
||||
#[test]
|
||||
fn shift_inverts_resize_snapping_from_press_through_release() {
|
||||
for enabled in [false, true] {
|
||||
let ctx = egui::Context::default();
|
||||
let mut app = Editor::default();
|
||||
app.snapping.enabled = enabled;
|
||||
app.snapping.pixels = false;
|
||||
app.snapping.layer_edges = false;
|
||||
let output = frame(&mut app, &ctx, vec![]);
|
||||
let rect = layer_rects(&output)[1];
|
||||
let g = app.layout.layers()[1];
|
||||
let scale = rect.width() / g.width as f32;
|
||||
let start = rect.right_center();
|
||||
let end = start + Vec2::new((1920.0 - g.x - g.width) as f32 * scale - 3.0, 0.0);
|
||||
let shift = egui::Modifiers {
|
||||
shift: true,
|
||||
..Default::default()
|
||||
};
|
||||
for events in [
|
||||
vec![egui::Event::PointerMoved(start), mouse(start, true)],
|
||||
vec![egui::Event::PointerMoved(end)],
|
||||
vec![mouse(end, false)],
|
||||
] {
|
||||
let events = events
|
||||
.into_iter()
|
||||
.map(|mut e| {
|
||||
if let egui::Event::PointerButton { modifiers, .. } = &mut e {
|
||||
*modifiers = shift;
|
||||
}
|
||||
e
|
||||
})
|
||||
.collect();
|
||||
let _ = ctx.run(
|
||||
egui::RawInput {
|
||||
screen_rect: Some(Rect::from_min_size(
|
||||
Pos2::ZERO,
|
||||
Vec2::new(1440.0, 940.0),
|
||||
)),
|
||||
modifiers: shift,
|
||||
events,
|
||||
..Default::default()
|
||||
},
|
||||
|ctx| app.ui(ctx),
|
||||
);
|
||||
}
|
||||
let next = app.layout.layers()[1];
|
||||
assert!(
|
||||
next.width > g.width,
|
||||
"Shift must resize instead of selecting a region"
|
||||
);
|
||||
let expected = if enabled { 1914.0 } else { 1920.0 };
|
||||
assert!((next.x + next.width - expected).abs() < 0.01);
|
||||
assert_eq!(app.snapping.enabled, enabled);
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn snapped_move_and_resize_stay_snapped_on_release_and_undo_as_one_edit() {
|
||||
for resize in [false, true] {
|
||||
for zoom in [0.75, 1.0] {
|
||||
|
|
|
|||
|
|
@ -86,6 +86,14 @@ fn resized_geometry(
|
|||
handle: ResizeHandle,
|
||||
delta: [f64; 2],
|
||||
keep_ratio: bool,
|
||||
) -> Geometry {
|
||||
resized_geometry_exact(original, handle, delta.map(f64::round), keep_ratio)
|
||||
}
|
||||
fn resized_geometry_exact(
|
||||
original: Geometry,
|
||||
handle: ResizeHandle,
|
||||
delta: [f64; 2],
|
||||
keep_ratio: bool,
|
||||
) -> Geometry {
|
||||
let left = matches!(
|
||||
handle,
|
||||
|
|
@ -95,8 +103,8 @@ fn resized_geometry(
|
|||
handle,
|
||||
ResizeHandle::Corner(Corner::TopLeft | Corner::TopRight) | ResizeHandle::Top
|
||||
);
|
||||
let dx = delta[0].round() * if left { -1.0 } else { 1.0 };
|
||||
let dy = delta[1].round() * if top { -1.0 } else { 1.0 };
|
||||
let dx = delta[0] * if left { -1.0 } else { 1.0 };
|
||||
let dy = delta[1] * if top { -1.0 } else { 1.0 };
|
||||
let side = !matches!(handle, ResizeHandle::Corner(_));
|
||||
let horizontal = matches!(handle, ResizeHandle::Left | ResizeHandle::Right);
|
||||
let (width, height) = if side {
|
||||
|
|
@ -1129,6 +1137,9 @@ impl Layout {
|
|||
Ok(())
|
||||
}
|
||||
pub fn drag_to(&mut self, point: [f64; 2]) {
|
||||
self.drag_to_with_precision(point, false);
|
||||
}
|
||||
fn drag_to_with_precision(&mut self, point: [f64; 2], exact: bool) {
|
||||
if point.iter().any(|v| !v.is_finite()) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -1191,7 +1202,12 @@ impl Layout {
|
|||
}
|
||||
if let Some(r) = &self.resize {
|
||||
let original = r.before.layers[r.index];
|
||||
let next = resized_geometry(
|
||||
let resize = if exact {
|
||||
resized_geometry_exact
|
||||
} else {
|
||||
resized_geometry
|
||||
};
|
||||
let next = resize(
|
||||
original,
|
||||
r.handle,
|
||||
[point[0] - r.start[0], point[1] - r.start[1]],
|
||||
|
|
@ -1261,6 +1277,9 @@ impl Layout {
|
|||
}
|
||||
}
|
||||
}
|
||||
pub fn resizing(&self) -> bool {
|
||||
self.resize.is_some()
|
||||
}
|
||||
pub fn dragging(&self) -> bool {
|
||||
self.drag.is_some()
|
||||
|| self.resize.is_some()
|
||||
|
|
|
|||
|
|
@ -166,7 +166,19 @@ impl Layout {
|
|||
for (priority, _, axis, target) in candidates {
|
||||
let mut adjusted = point;
|
||||
adjusted[axis] += target - current[axis];
|
||||
self.drag_to(adjusted);
|
||||
if r.keep_ratio && matches!(r.handle, ResizeHandle::Corner(_)) {
|
||||
let original = r.before.layers[r.index];
|
||||
let original_handle = handle_point(original);
|
||||
let anchor = [
|
||||
2.0 * original.center()[0] - original_handle[0],
|
||||
2.0 * original.center()[1] - original_handle[1],
|
||||
];
|
||||
let factor = (target - anchor[axis]) / (original_handle[axis] - anchor[axis]);
|
||||
for j in 0..2 {
|
||||
adjusted[j] = r.start[j] + (original_handle[j] - anchor[j]) * (factor - 1.0);
|
||||
}
|
||||
}
|
||||
self.drag_to_with_precision(adjusted, true);
|
||||
// Ratio/minimum-size constraints can prevent the requested snap. Never show a false guide.
|
||||
if self.gesture_error.is_none()
|
||||
&& (handle_point(self.layers[r.index])[axis] - target).abs() < 1e-6
|
||||
|
|
|
|||
|
|
@ -162,3 +162,52 @@ fn resize_can_bypass_snapping_and_cancel() {
|
|||
layout.cancel_drag();
|
||||
assert_eq!(layout.layers()[0], g);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ratio_locked_corners_reach_fractional_layer_edges() {
|
||||
use midra_layout::{Corner, ResizeHandle};
|
||||
for corner in [
|
||||
Corner::TopLeft,
|
||||
Corner::TopRight,
|
||||
Corner::BottomLeft,
|
||||
Corner::BottomRight,
|
||||
] {
|
||||
let mut layout = Layout::default();
|
||||
let mut target = layout.layers()[1];
|
||||
target.x = 900.25;
|
||||
layout.apply(1, target).unwrap();
|
||||
layout.select(Some(0));
|
||||
let g = layout.layers()[0];
|
||||
let handle = ResizeHandle::Corner(corner);
|
||||
let start = ResizeHandle::positions(g)
|
||||
.into_iter()
|
||||
.find(|(h, _)| *h == handle)
|
||||
.unwrap()
|
||||
.1;
|
||||
let left = matches!(corner, Corner::TopLeft | Corner::BottomLeft);
|
||||
let target_x = if left { 0.0 } else { target.x };
|
||||
layout.start_handle_resize(0, handle, start, true);
|
||||
// Move along the aspect-ratio diagonal to just inside the snap radius.
|
||||
let dx = target_x - start[0] + if left { 2.0 } else { -2.0 };
|
||||
let same_sign = matches!(corner, Corner::TopLeft | Corner::BottomRight);
|
||||
let point = [
|
||||
start[0] + dx,
|
||||
start[1] + dx * g.height / g.width * if same_sign { 1.0 } else { -1.0 },
|
||||
];
|
||||
let guides = layout.drag_to_snapped(
|
||||
point,
|
||||
Snapping {
|
||||
enabled: true,
|
||||
pixels: false,
|
||||
screen_edges: true,
|
||||
layer_edges: true,
|
||||
},
|
||||
6.0,
|
||||
);
|
||||
let next = layout.layers()[0];
|
||||
let edge = if left { next.x } else { next.x + next.width };
|
||||
assert!((edge - target_x).abs() < 1e-6, "{corner:?}: {edge}");
|
||||
assert_eq!(guides[0], Some(target_x));
|
||||
assert!((next.width / next.height - g.width / g.height).abs() < 1e-9);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -103,4 +103,4 @@ fixed six-logical-pixel proximity radius converted by viewport scale. It affects
|
|||
layer movement and resize handles; numeric entry, nudges and crop-content gestures
|
||||
bypass it. Resize snapping preserves anchors and proportions and shows guides only
|
||||
when the resulting edge actually reaches its target.
|
||||
Alt temporarily disables it without changing the saved option.
|
||||
Shift temporarily inverts snapping during layer resizing, including release, without changing the saved option. Alt temporarily disables it and takes precedence over Shift.
|
||||
|
|
|
|||
|
|
@ -621,3 +621,5 @@ no layer mapping.
|
|||
**Apply to Midra**, beside ONLINE/OFFLINE and in **Export**, sends the selected layers using the current destination mappings, screen, Preview/Program target and sizing strategy. If mapping is incomplete, it opens the send window first. Configure these choices in **Export → Configure Midra export…**. The action is disabled offline, during transfers, or when values already match the last snapshot. Sending writes directly and verifies readback; results appear in the send window. Only applied editor values are sent.
|
||||
|
||||
Layer rows use padlock and eye icon buttons for locking and visibility, with tooltips and highlighted locked/hidden states. Double-click a layer name in the right-hand list to rename it. Enter saves, Escape or Cancel discards the edit; names must contain 1–128 characters. Renaming preserves the layer ID and folder and supports Undo.
|
||||
|
||||
Snapping also applies to side and corner resizing, including with aspect ratio locked. Hold **Shift** during a resize to temporarily invert snapping (on when disabled, off when enabled); release uses the current modifier state. **Alt** still disables snapping. Shift-drag on a resize handle resizes; Shift-click and Shift-drag elsewhere retain selection behavior.
|
||||
|
|
|
|||
Loading…
Reference in New Issue