Distinguish horizontal mirror and opposite-handle resizing

This commit is contained in:
Dandaedre 2026-11-13 14:32:49 +01:00
parent 833f32a5eb
commit 333e247c7e
4 changed files with 88 additions and 23 deletions

View File

@ -996,8 +996,9 @@ impl Editor {
.width(w - 12.0)
.selected_text(match self.resize_mode {
ResizeMode::Individual => "Resize: individual layer",
ResizeMode::Same => "Same resize",
ResizeMode::Mirror => "Mirror resize",
ResizeMode::Same => "Same handles",
ResizeMode::Mirror => "Mirror horizontally",
ResizeMode::Opposite => "Opposite handles",
})
.show_ui(ui, |ui| {
ui.selectable_value(
@ -1005,12 +1006,21 @@ impl Editor {
ResizeMode::Individual,
"Resize: individual layer",
);
ui.selectable_value(&mut self.resize_mode, ResizeMode::Same, "Same resize");
ui.selectable_value(
&mut self.resize_mode,
ResizeMode::Same,
"Same handles",
);
ui.add_enabled_ui(self.layout.selected_indices().len() == 2, |ui| {
ui.selectable_value(
&mut self.resize_mode,
ResizeMode::Mirror,
"Mirror resize (two layers)",
"Mirror horizontally (two layers)",
);
ui.selectable_value(
&mut self.resize_mode,
ResizeMode::Opposite,
"Opposite handles (two layers)",
);
});
});
@ -1018,9 +1028,10 @@ impl Editor {
);
ui.put(Rect::from_min_size(ink.point(0.0, 292.0), Vec2::new(w, 52.0)), egui::Label::new(egui::RichText::new(
match self.resize_mode {
ResizeMode::Individual => "Choose Same or Mirror, then drag a selected layer's handle to resize the selection.",
ResizeMode::Individual => "Choose a shared resize mode, then drag a selected layer's handle to resize the selection.",
ResizeMode::Same => "Matching handles, equal proportional scaling. Drag any selected handle. Escape exits.",
ResizeMode::Mirror => "Opposite handles, equal proportional scaling. Exactly two layers. Escape exits.",
ResizeMode::Mirror => "Left/right mirrored handles, equal proportional scaling. Two layers. Escape exits.",
ResizeMode::Opposite => "Diagonally opposite corners, equal proportional scaling. Two layers. Escape exits.",
}
).size(12.0).color(MUTED)).wrap().halign(egui::Align::Min));
let shifted = Ink {
@ -1648,8 +1659,9 @@ impl Editor {
r.height() - 57.0,
match self.resize_mode {
ResizeMode::Individual => "Corners resize · Side handles keep opposite edge fixed · Shift-click selects",
ResizeMode::Same => "Same resize · Matching handles scale selected layers proportionally · Escape exits",
ResizeMode::Mirror => "Mirror resize · Opposite handles scale both layers proportionally · Escape exits",
ResizeMode::Same => "Same handles · Matching handles scale selected layers proportionally · Escape exits",
ResizeMode::Mirror => "Mirror horizontally · Left/right mirrored handles · Escape exits",
ResizeMode::Opposite => "Opposite handles · Opposite corners or edges · Escape exits",
},
12.0,
MUTED,
@ -2305,8 +2317,9 @@ mod tests {
#[test]
fn selected_resize_mode_control_keeps_selection_during_handle_drag() {
for (title, mode) in [
("Same resize", ResizeMode::Same),
("Mirror resize (two layers)", ResizeMode::Mirror),
("Same handles", ResizeMode::Same),
("Mirror horizontally (two layers)", ResizeMode::Mirror),
("Opposite handles (two layers)", ResizeMode::Opposite),
] {
let mut app = Editor::default();
app.layout.set_selection([true; 2]);

View File

@ -28,8 +28,23 @@ pub enum ResizeMode {
Individual,
Same,
Mirror,
Opposite,
}
impl ResizeHandle {
pub fn mirrored_horizontally(self) -> Self {
match self {
Self::Left => Self::Right,
Self::Right => Self::Left,
Self::Top | Self::Bottom => self,
Self::Corner(corner) => Self::Corner(match corner {
Corner::TopLeft => Corner::TopRight,
Corner::TopRight => Corner::TopLeft,
Corner::BottomLeft => Corner::BottomRight,
Corner::BottomRight => Corner::BottomLeft,
}),
}
}
pub fn opposite(self) -> Self {
match self {
Self::Top => Self::Bottom,
@ -786,9 +801,9 @@ impl Layout {
return Ok(());
}
let count = self.selected_indices().len();
if count < 2 || (mode == ResizeMode::Mirror && count != 2) {
if count < 2 || (matches!(mode, ResizeMode::Mirror | ResizeMode::Opposite) && count != 2) {
return Err(
"Select at least two layers for Same resize, or exactly two for Mirror resize."
"Select at least two layers for Same handles, or exactly two for Mirror horizontally / Opposite handles."
.into(),
);
}
@ -860,8 +875,12 @@ impl Layout {
continue;
}
let before = *geometry;
let handle = if r.mode == ResizeMode::Mirror && i != r.index {
r.handle.opposite()
let handle = if i != r.index {
match r.mode {
ResizeMode::Mirror => r.handle.mirrored_horizontally(),
ResizeMode::Opposite => r.handle.opposite(),
ResizeMode::Individual | ResizeMode::Same => r.handle,
}
} else {
r.handle
};

View File

@ -723,7 +723,7 @@ fn corner_alignment_to_unselected_reference_is_one_undo_step() {
#[test]
fn selected_resize_scales_proportionally_with_same_or_opposite_anchors() {
use midra_layout::{ResizeHandle as H, ResizeMode as M};
for mode in [M::Same, M::Mirror] {
for mode in [M::Same, M::Mirror, M::Opposite] {
for keep_ratio in [false, true] {
for initiator in 0..2 {
for (handle, _) in H::positions(Layout::default().layers()[0]) {
@ -778,8 +778,12 @@ fn selected_resize_scales_proportionally_with_same_or_opposite_anchors() {
< 1e-10
);
for i in 0..2 {
let actual = if mode == M::Mirror && i != initiator {
handle.opposite()
let actual = if i != initiator {
match mode {
M::Mirror => handle.mirrored_horizontally(),
M::Opposite => handle.opposite(),
_ => handle,
}
} else {
handle
};
@ -857,3 +861,28 @@ fn selected_resize_limits_cancel_and_protection_are_atomic() {
.is_err()
);
}
#[test]
fn resize_handle_modes_distinguish_horizontal_mirror_from_opposite() {
use midra_layout::ResizeHandle as H;
for (handle, mirrored, opposite) in [
(
H::Corner(Corner::BottomRight),
H::Corner(Corner::BottomLeft),
H::Corner(Corner::TopLeft),
),
(
H::Corner(Corner::TopRight),
H::Corner(Corner::TopLeft),
H::Corner(Corner::BottomLeft),
),
(H::Right, H::Left, H::Left),
(H::Top, H::Top, H::Bottom),
(H::Bottom, H::Bottom, H::Top),
] {
assert_eq!(handle.mirrored_horizontally(), mirrored);
assert_eq!(mirrored.mirrored_horizontally(), handle);
assert_eq!(handle.opposite(), opposite);
assert_eq!(opposite.opposite(), handle);
}
}

View File

@ -143,15 +143,19 @@ clipboard testing against a running draw.io instance remains to be done.
## Resize selected layers together
Select multiple layers, then choose **Same resize** or **Mirror resize** in the
Select multiple layers, then choose **Same handles**, **Mirror horizontally**, or **Opposite handles** in the
right-hand inspector’s resize dropdown. Drag a corner or side handle on any
selected layer to scale the selection together. Both modes use **equal
selected layer to scale the selection together. All three modes use **equal
proportional scaling**, not equal pixel additions: a 10% width increase applies
to every selected layer’s own width.
- **Same resize** uses the matching handle on every layer.
- **Mirror resize** requires exactly two layers. The other layer uses the opposite
handle: right/left, top/bottom, and diagonally opposite corners.
- **Same handles** uses the matching handle on every layer.
- **Mirror horizontally** requires exactly two layers. Left/right handles are
mirrored: bottom-right matches bottom-left, and top-right matches top-left.
Top and bottom midpoint handles remain top and bottom respectively.
- **Opposite handles** requires exactly two layers. The other layer uses the
opposite handle: right/left, top/bottom, and diagonally opposite corners
(bottom-right matches top-left). This was previously called Mirror resize.
- Each layer keeps the opposite edge or corner fixed. With aspect ratio locked,
both dimensions use the same scale; otherwise width and height scale
independently. Side handles affect only their axis when the ratio is unlocked.
@ -178,7 +182,7 @@ only their axis; corner buttons change both axes. Hover an icon for its label.
Every action preserves layer sizes and is one undo step, including corner moves.
The menu also works with one selected layer and a different reference layer.
The inspector lists each selected layer's resulting center coordinates; select
one layer for numeric size editing, or use Same/Mirror resize for the selection.
one layer for numeric size editing, or use a shared resize mode for the selection.
Paste/import accepts the full selection.
Text inputs receive normal text paste and arrow navigation while focused; they