Snap mirrored layer resizing to exact edge contact
This commit is contained in:
parent
993b0b1b75
commit
0fdaf4cc9c
|
|
@ -3087,6 +3087,64 @@ mod tests {
|
|||
);
|
||||
frame(app, ctx, vec![mouse(pos, false)]);
|
||||
}
|
||||
#[test]
|
||||
fn mirror_resize_snaps_at_contact_through_release_and_alt_bypasses() {
|
||||
for zoom in [0.75, 1.0] {
|
||||
let ctx = egui::Context::default();
|
||||
let mut app = Editor {
|
||||
zoom,
|
||||
resize_mode: ResizeMode::Mirror,
|
||||
..Default::default()
|
||||
};
|
||||
app.layout.set_selection([true; 2]);
|
||||
app.snapping.enabled = true;
|
||||
app.sync();
|
||||
let before = app.layout.layers().clone();
|
||||
let output = frame(&mut app, &ctx, vec![]);
|
||||
let rect = layer_rects(&output)[0];
|
||||
let scale = rect.width() / before[0].width as f32;
|
||||
let start = rect.right_center();
|
||||
let end = start + Vec2::new(198.0 * scale, 0.0);
|
||||
frame(
|
||||
&mut app,
|
||||
&ctx,
|
||||
vec![egui::Event::PointerMoved(start), mouse(start, true)],
|
||||
);
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(end)]);
|
||||
assert!(
|
||||
(app.layout.layers()[0].x + app.layout.layers()[0].width
|
||||
- app.layout.layers()[1].x)
|
||||
.abs()
|
||||
< 1e-6
|
||||
);
|
||||
assert_eq!(app.snap_guides[0], Some(960.0));
|
||||
frame_modifiers(
|
||||
&mut app,
|
||||
&ctx,
|
||||
egui::Modifiers {
|
||||
alt: true,
|
||||
..Default::default()
|
||||
},
|
||||
vec![],
|
||||
);
|
||||
assert!(
|
||||
(app.layout.layers()[0].x + app.layout.layers()[0].width
|
||||
- app.layout.layers()[1].x)
|
||||
.abs()
|
||||
> 1.0
|
||||
);
|
||||
frame(&mut app, &ctx, vec![mouse(end, false)]);
|
||||
assert!(
|
||||
(app.layout.layers()[0].x + app.layout.layers()[0].width
|
||||
- app.layout.layers()[1].x)
|
||||
.abs()
|
||||
< 1e-6
|
||||
);
|
||||
app.layout.undo();
|
||||
assert_eq!(app.layout.layers(), &before);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn viewport_visibility_and_output_overflow_are_independent() {
|
||||
let inside = Geometry {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
//! Proximity snapping for moving one layer or a selection as a rigid group.
|
||||
use crate::{Geometry, Layout, ResizeHandle};
|
||||
//! Proximity snapping for layer movement and anchored single/group resizing.
|
||||
use crate::{Geometry, Layout, ResizeHandle, ResizeMode};
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
|
|
@ -224,16 +224,52 @@ impl Layout {
|
|||
.total_cmp(&(b - current[axis]).abs())
|
||||
})
|
||||
{
|
||||
candidates.push((0, (target - current[axis]).abs(), axis, target));
|
||||
candidates.push((1, (target - current[axis]).abs(), axis, target, None));
|
||||
}
|
||||
if options.layer_edges && matches!(r.mode, ResizeMode::Mirror | ResizeMode::Opposite) {
|
||||
let original = r.before.layers[r.index];
|
||||
let moving = handle_point(original)[axis];
|
||||
let anchor = 2.0 * original.center()[axis] - moving;
|
||||
for (i, other) in r.before.layers.iter().enumerate() {
|
||||
if i == r.index || !r.targets[i] || !self.visible(i) {
|
||||
continue;
|
||||
}
|
||||
let other_handle = if r.mode == ResizeMode::Mirror {
|
||||
r.handle.mirrored_horizontally()
|
||||
} else {
|
||||
r.handle.opposite()
|
||||
};
|
||||
let other_moving = ResizeHandle::positions(*other)
|
||||
.into_iter()
|
||||
.find(|(h, _)| *h == other_handle)
|
||||
.unwrap()
|
||||
.1[axis];
|
||||
let other_anchor = 2.0 * other.center()[axis] - other_moving;
|
||||
let span = moving - anchor;
|
||||
let other_span = other_moving - other_anchor;
|
||||
// Both edges move with the same scale factor, in opposite
|
||||
// directions. Solve their meeting point, not a stale edge.
|
||||
if span * other_span >= 0.0 {
|
||||
continue;
|
||||
}
|
||||
let factor = (other_anchor - anchor) / (span - other_span);
|
||||
let target = anchor + span * factor;
|
||||
if factor > 0.0
|
||||
&& target.is_finite()
|
||||
&& (target - current[axis]).abs() <= tolerance
|
||||
{
|
||||
candidates.push((0, (target - current[axis]).abs(), axis, target, Some(i)));
|
||||
}
|
||||
}
|
||||
}
|
||||
if options.pixels {
|
||||
let spacing = grid.unwrap_or(1.0);
|
||||
let target = (current[axis] / spacing).round() * spacing;
|
||||
candidates.push((1, (target - current[axis]).abs(), axis, target));
|
||||
candidates.push((2, (target - current[axis]).abs(), axis, target, None));
|
||||
}
|
||||
}
|
||||
candidates.sort_by(|a, b| a.0.cmp(&b.0).then(a.1.total_cmp(&b.1)));
|
||||
for (priority, _, axis, target) in candidates {
|
||||
for (priority, _, axis, target, meeting) in candidates {
|
||||
let mut adjusted = point;
|
||||
// The regular preview may be pixel-rounded. Correct from the exact
|
||||
// pointer geometry, or fractional viewport scales can miss the snap.
|
||||
|
|
@ -252,12 +288,32 @@ impl Layout {
|
|||
}
|
||||
}
|
||||
self.drag_to_with_precision(adjusted, true);
|
||||
let touching = meeting.is_none_or(|i| {
|
||||
let a = self.layers[r.index];
|
||||
let b = self.layers[i];
|
||||
let other_axis = 1 - axis;
|
||||
let low = |g: Geometry| if other_axis == 0 { g.x } else { g.y };
|
||||
let size = |g: Geometry| if other_axis == 0 { g.width } else { g.height };
|
||||
let other_handle = if r.mode == ResizeMode::Mirror {
|
||||
r.handle.mirrored_horizontally()
|
||||
} else {
|
||||
r.handle.opposite()
|
||||
};
|
||||
let other_edge = ResizeHandle::positions(b)
|
||||
.into_iter()
|
||||
.find(|(h, _)| *h == other_handle)
|
||||
.unwrap()
|
||||
.1[axis];
|
||||
(other_edge - target).abs() < 1e-6
|
||||
&& low(a).max(low(b)) < (low(a) + size(a)).min(low(b) + size(b))
|
||||
});
|
||||
// Ratio/minimum-size constraints can prevent the requested snap. Never show a false guide.
|
||||
if self.gesture_error.is_none()
|
||||
&& touching
|
||||
&& (handle_point(self.layers[r.index])[axis] - target).abs() < 1e-6
|
||||
{
|
||||
let mut guides = [None; 2];
|
||||
if priority == 0 || grid.is_some() {
|
||||
if priority < 2 || grid.is_some() {
|
||||
guides[axis] = Some(target);
|
||||
}
|
||||
return guides;
|
||||
|
|
|
|||
|
|
@ -350,3 +350,203 @@ fn grid_ignores_crop_content_and_invalid_spacing_does_not_edit() {
|
|||
assert_eq!(*layout.layers(), geometry);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mirrored_layers_snap_to_exact_contact_from_either_handle_and_keep_anchors() {
|
||||
use midra_layout::{Corner, Geometry, ResizeHandle, ResizeMode};
|
||||
for index in [0, 1] {
|
||||
for corner in [false, true] {
|
||||
for ratio in [false, true] {
|
||||
for offset in [-2.0, 2.0] {
|
||||
let mut layout = Layout::default();
|
||||
layout
|
||||
.apply(
|
||||
0,
|
||||
Geometry {
|
||||
x: 100.25,
|
||||
y: 200.0,
|
||||
width: 400.0,
|
||||
height: 200.0,
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
layout
|
||||
.apply(
|
||||
1,
|
||||
Geometry {
|
||||
x: 800.25,
|
||||
y: 200.0,
|
||||
width: 600.0,
|
||||
height: 300.0,
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
layout.set_selection([true; 2]);
|
||||
let before = layout.layers().clone();
|
||||
let formats = layout.formats().clone();
|
||||
let handle = match (index, corner) {
|
||||
(0, false) => ResizeHandle::Right,
|
||||
(0, true) => ResizeHandle::Corner(Corner::BottomRight),
|
||||
(_, false) => ResizeHandle::Left,
|
||||
(_, true) => ResizeHandle::Corner(Corner::BottomLeft),
|
||||
};
|
||||
let start = ResizeHandle::positions(before[index])
|
||||
.into_iter()
|
||||
.find(|(h, _)| *h == handle)
|
||||
.unwrap()
|
||||
.1;
|
||||
let contact = 620.25;
|
||||
let factor = if index == 0 {
|
||||
(contact + offset - 100.25) / 400.0
|
||||
} else {
|
||||
(1400.25 - contact - offset) / 600.0
|
||||
};
|
||||
let point = [
|
||||
contact + offset,
|
||||
if corner && ratio {
|
||||
200.0 + before[index].height * factor
|
||||
} else {
|
||||
start[1]
|
||||
},
|
||||
];
|
||||
layout
|
||||
.start_selected_resize(index, handle, start, ratio, ResizeMode::Mirror)
|
||||
.unwrap();
|
||||
let options = Snapping {
|
||||
enabled: true,
|
||||
pixels: false,
|
||||
screen_edges: false,
|
||||
layer_edges: true,
|
||||
};
|
||||
let guides = layout.drag_to_snapped(point, options, 6.0);
|
||||
assert_eq!(
|
||||
guides,
|
||||
[Some(contact), None],
|
||||
"index={index} corner={corner} ratio={ratio}"
|
||||
);
|
||||
let a = layout.layers()[0];
|
||||
let b = layout.layers()[1];
|
||||
assert!((a.x + a.width - b.x).abs() < 1e-8);
|
||||
assert_eq!(a.x, before[0].x);
|
||||
assert!((b.x + b.width - 1400.25).abs() < 1e-8);
|
||||
assert!((a.width / 400.0 - b.width / 600.0).abs() < 1e-8);
|
||||
if ratio {
|
||||
assert!((a.width / a.height - 2.0).abs() < 1e-8);
|
||||
assert!((b.width / b.height - 2.0).abs() < 1e-8);
|
||||
}
|
||||
let snapped = layout.layers().clone();
|
||||
layout.drag_to_snapped(point, options, 6.0);
|
||||
assert_eq!(layout.layers(), &snapped);
|
||||
layout.drag_to_snapped([point[0] + 40.0, point[1]], options, 6.0);
|
||||
assert!(
|
||||
(layout.layers()[0].x + layout.layers()[0].width - layout.layers()[1].x)
|
||||
.abs()
|
||||
> 1.0
|
||||
);
|
||||
layout.drag_to_snapped(point, options, 6.0);
|
||||
layout.finish_drag();
|
||||
layout.undo();
|
||||
assert_eq!(layout.layers(), &before);
|
||||
assert_eq!(layout.formats(), &formats);
|
||||
layout.redo();
|
||||
assert_eq!(layout.layers(), &snapped);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn meeting_snap_respects_disabled_options_and_requires_actual_edge_contact() {
|
||||
use midra_layout::{ResizeHandle, ResizeMode};
|
||||
for (enabled, layer_edges, separated) in [
|
||||
(false, true, false),
|
||||
(true, false, false),
|
||||
(true, true, true),
|
||||
] {
|
||||
let mut layout = Layout::default();
|
||||
if separated {
|
||||
let mut g = layout.layers()[1];
|
||||
g.y = 2000.0;
|
||||
layout.apply(1, g).unwrap();
|
||||
}
|
||||
layout.set_selection([true; 2]);
|
||||
let before = layout.layers().clone();
|
||||
layout
|
||||
.start_selected_resize(
|
||||
0,
|
||||
ResizeHandle::Right,
|
||||
[760.0, 360.0],
|
||||
false,
|
||||
ResizeMode::Mirror,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
layout.drag_to_snapped(
|
||||
[958.0, 360.0],
|
||||
Snapping {
|
||||
enabled,
|
||||
layer_edges,
|
||||
pixels: false,
|
||||
screen_edges: false
|
||||
},
|
||||
6.0
|
||||
),
|
||||
[None; 2]
|
||||
);
|
||||
assert_eq!(layout.layers()[0].x + layout.layers()[0].width, 958.0);
|
||||
layout.cancel_drag();
|
||||
assert_eq!(layout.layers(), &before);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn opposite_vertical_edges_snap_to_meet() {
|
||||
use midra_layout::{Geometry, ResizeHandle, ResizeMode};
|
||||
let mut layout = Layout::default();
|
||||
layout
|
||||
.apply(
|
||||
0,
|
||||
Geometry {
|
||||
x: 100.0,
|
||||
y: 100.0,
|
||||
width: 300.0,
|
||||
height: 200.0,
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
layout
|
||||
.apply(
|
||||
1,
|
||||
Geometry {
|
||||
x: 100.0,
|
||||
y: 500.0,
|
||||
width: 300.0,
|
||||
height: 400.0,
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
layout.set_selection([true; 2]);
|
||||
layout
|
||||
.start_selected_resize(
|
||||
0,
|
||||
ResizeHandle::Bottom,
|
||||
[250.0, 300.0],
|
||||
false,
|
||||
ResizeMode::Opposite,
|
||||
)
|
||||
.unwrap();
|
||||
let target = 100.0 + 800.0 / 3.0;
|
||||
let guides = layout.drag_to_snapped(
|
||||
[250.0, target - 2.0],
|
||||
Snapping {
|
||||
enabled: true,
|
||||
pixels: false,
|
||||
screen_edges: false,
|
||||
layer_edges: true,
|
||||
},
|
||||
6.0,
|
||||
);
|
||||
assert!((guides[1].unwrap() - target).abs() < 1e-8);
|
||||
assert!((layout.layers()[0].y + layout.layers()[0].height - layout.layers()[1].y).abs() < 1e-8);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -670,6 +670,12 @@ panning are unaffected. Shift-click still toggles selection; Shift-drag on a lay
|
|||
moves it on the grid, and Shift-drag on empty canvas adds a selection box.
|
||||
This replaces the previous Shift-to-invert-resize-snapping shortcut.
|
||||
|
||||
With snapping and layer-edge snapping enabled, resizing in **Mirror** mode snaps
|
||||
the two moving inner edges into exact contact, including unequal-sized layers.
|
||||
**Opposite** mode also supports vertical contact. A guide marks the meeting edge;
|
||||
anchors and aspect-ratio settings are preserved. Move beyond the snap radius to
|
||||
continue resizing, or hold Alt to bypass. Shift/Ctrl+Shift grid overrides remain.
|
||||
|
||||
Midra layer lists omit unassigned source slots (`NONE` or empty). Assigned inputs remain listed even if the layer is off. The exporter defaults to Preview and hides Program until **Settings → Midra integration → Allow sending to Program** is checked. This preference is saved automatically; turning it off returns the exporter and quick Apply action to Preview.
|
||||
|
||||
Destination choices in **Configure Midra export…** now save immediately on the editor layer and support Undo. Save the project JSON to keep links across sessions. Links include screen and layer IDs and survive refreshes and selection changes. Choose the empty destination on the linked screen to unlink. **Send all linked layers** is available beside Apply, in Export and in the send window; it includes unselected, hidden and locked linked layers, grouped by screen. Apply changes… opens configuration for the chosen layers. Preview/Program and sizing still use the current export options.
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
- Snap mirrored/opposite resizing to exact edge contact between both moving layers, including unequal sizes; preserve anchors/ratios, Alt bypass and Undo.
|
||||
|
||||
- Distinguish completely out-of-view layers from partial/complete output-screen overflow; give navigation versus positioning advice. Rename Fit selected to Zoom to selection.
|
||||
|
||||
- Give the canvas more space: compact reference hint/status, tighter viewport margins and footer. Warnings still wrap. Fix resize edge snapping at fractional viewport scales.
|
||||
|
|
|
|||
Loading…
Reference in New Issue