From 98a0911899eab6dbd22d07316ab0b73ec5d226e4 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Sat, 14 Nov 2026 11:39:19 +0100 Subject: [PATCH] Keep the selected Midra resize mode throughout the session --- crates/midra-layout/src/gui.rs | 84 ++++++++++++++++++++++----- crates/midra-layout/src/project_ui.rs | 19 ++++++ docs/interfaces/midra-layout.md | 4 +- docs/midra-layout.md | 9 ++- docs/midralayout/changelog.md | 2 + 5 files changed, 101 insertions(+), 17 deletions(-) diff --git a/crates/midra-layout/src/gui.rs b/crates/midra-layout/src/gui.rs index 7ed3737..609d19f 100644 --- a/crates/midra-layout/src/gui.rs +++ b/crates/midra-layout/src/gui.rs @@ -475,9 +475,6 @@ impl Editor { self.layer_order = order; } self.fields_edited = false; - if self.layout.selected_indices().len() < 2 { - self.resize_mode = ResizeMode::Individual; - } if let Some(i) = self.layout.selected() { let g = self.layout.layers()[i]; let [x, y] = self.corner.offsets_on(g, self.layout.formats().output); @@ -666,7 +663,6 @@ impl Editor { } if ctx.input(|i| i.key_pressed(egui::Key::Escape)) { self.edit_content = false; - self.resize_mode = ResizeMode::Individual; self.layout.cancel_drag(); if let Some(m) = self.marquee.take() { self.layout.set_selection(m.previous); @@ -1518,9 +1514,9 @@ 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 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 => "Left/right mirrored handles, equal proportional scaling. Two layers. Escape exits.", - ResizeMode::Opposite => "Diagonally opposite corners, equal proportional scaling. Two layers. Escape exits.", + ResizeMode::Same => "Matching handles, equal proportional scaling. Drag any selected handle. Escape cancels drag.", + ResizeMode::Mirror => "Left/right mirrored handles, equal proportional scaling. Two layers. Escape cancels drag.", + ResizeMode::Opposite => "Diagonally opposite corners, equal proportional scaling. Two layers. Escape cancels drag.", } ).size(12.0).color(palette.muted)).wrap().halign(egui::Align::Min)); let shifted = Ink { @@ -1639,6 +1635,13 @@ impl Editor { } None } + fn active_resize_mode(&self) -> ResizeMode { + if self.layout.selected_indices().len() < 2 { + ResizeMode::Individual + } else { + self.resize_mode + } + } fn workspace(&mut self, ui: &mut egui::Ui) { let palette = theme::palette(ui.ctx()); let r = ui.max_rect(); @@ -1999,7 +2002,7 @@ impl Editor { corner, point, self.keep_aspect_ratio, - self.resize_mode, + self.active_resize_mode(), ) { self.layout.gesture_error = Some(e); } @@ -2368,11 +2371,11 @@ impl Editor { ink.text( 24.0, r.height() - 57.0, - if self.edit_content { "Crop mode · Drag crop handles to zoom content · Drag image to reposition · Click outside to finish" } else { match self.resize_mode { + if self.edit_content { "Crop mode · Drag crop handles to zoom content · Drag image to reposition · Click outside to finish" } else { match self.active_resize_mode() { ResizeMode::Individual => "Corners resize · Side handles keep opposite edge fixed · Shift-click selects", - 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", + ResizeMode::Same => "Same handles · Matching handles scale selected layers proportionally · Escape cancels drag", + ResizeMode::Mirror => "Mirror horizontally · Left/right mirrored handles · Escape cancels drag", + ResizeMode::Opposite => "Opposite handles · Opposite corners or edges · Escape cancels drag", } }, 12.0, palette.muted, @@ -3610,6 +3613,61 @@ mod tests { assert!(output.platform_output.commands.iter().any(|c|matches!(c,egui::OutputCommand::CopyText(text) if text.contains("Width: 300 px") && text.contains("Height: 251 px")))); assert_eq!(app.layout.layers()[1], g); } + #[test] + fn resize_choice_survives_deselection_and_single_layer_gestures() { + for mode in [ResizeMode::Same, ResizeMode::Mirror, ResizeMode::Opposite] { + let ctx = egui::Context::default(); + let mut app = Editor { + resize_mode: mode, + ..Default::default() + }; + app.layout.select(None); + app.sync(); + frame(&mut app, &ctx, vec![key(egui::Key::Escape)]); + assert_eq!(app.resize_mode, mode); + app.layout.select(Some(1)); + app.sync(); + assert_eq!(app.active_resize_mode(), ResizeMode::Individual); + let before = app.layout.layers().clone(); + let output = frame(&mut app, &ctx, vec![]); + let start = layer_rects(&output)[1].right_center(); + let end = start + Vec2::new(25.0, 0.0); + frame( + &mut app, + &ctx, + vec![egui::Event::PointerMoved(start), mouse(start, true)], + ); + frame(&mut app, &ctx, vec![egui::Event::PointerMoved(end)]); + frame(&mut app, &ctx, vec![mouse(end, false)]); + assert_eq!(app.layout.layers()[0], before[0]); + assert!(app.layout.layers()[1].width > before[1].width); + assert_eq!(app.resize_mode, mode); + app.layout.undo(); + app.sync(); + assert_eq!(*app.layout.layers(), before); + app.layout.redo(); + app.sync(); + assert_eq!(app.resize_mode, mode); + app.layout.set_selection([true; 2]); + app.sync(); + assert_eq!(app.active_resize_mode(), mode); + // Pair-only modes remain selected but refuse three-layer resizing. + app.layout.add_layer().unwrap(); + app.layout.set_selection([true; 3]); + app.sync(); + let result = app.layout.start_selected_resize( + 0, + ResizeHandle::Right, + [0.0, 0.0], + true, + app.active_resize_mode(), + ); + assert_eq!(result.is_ok(), mode == ResizeMode::Same); + app.layout.cancel_drag(); + assert_eq!(app.resize_mode, mode); + } + } + #[test] fn selected_resize_mode_control_keeps_selection_during_handle_drag() { for (title, mode) in [ @@ -3663,7 +3721,7 @@ mod tests { app.layout.undo(); assert_eq!(*app.layout.layers(), before); frame(&mut app, &ctx, vec![key(egui::Key::Escape)]); - assert_eq!(app.resize_mode, ResizeMode::Individual); + assert_eq!(app.resize_mode, mode); } } #[test] diff --git a/crates/midra-layout/src/project_ui.rs b/crates/midra-layout/src/project_ui.rs index 4991ec7..55bc066 100644 --- a/crates/midra-layout/src/project_ui.rs +++ b/crates/midra-layout/src/project_ui.rs @@ -62,6 +62,7 @@ impl Editor { device: std::mem::take(&mut self.device), settings: std::mem::take(&mut self.settings), snapping: self.snapping, + resize_mode: self.resize_mode, layout, reference, corner: e.position_corner, @@ -289,6 +290,24 @@ impl Editor { #[cfg(test)] mod tests { use super::*; + #[test] + fn opening_project_preserves_session_resize_choice() { + let ctx = egui::Context::default(); + for mode in [ResizeMode::Same, ResizeMode::Mirror, ResizeMode::Opposite] { + let mut app = Editor { + resize_mode: mode, + ..Default::default() + }; + app.install_project(&ctx, Project::from_layout(&Layout::default())) + .unwrap(); + assert_eq!(app.resize_mode, mode); + assert_eq!(app.active_resize_mode(), ResizeMode::Individual); + app.layout.set_selection([true; 2]); + app.sync(); + assert_eq!(app.active_resize_mode(), mode); + } + } + #[test] fn project_restores_reference_and_editor_and_failed_image_load_keeps_current_work() { let ctx = egui::Context::default(); diff --git a/docs/interfaces/midra-layout.md b/docs/interfaces/midra-layout.md index 56250f2..ab67823 100644 --- a/docs/interfaces/midra-layout.md +++ b/docs/interfaces/midra-layout.md @@ -110,7 +110,9 @@ Projects larger than 96 MiB are rejected. Save includes **applied values only**. Pending text/format/import drafts, open dialogs, undo/redo history, crop-edit mode, resize mode, and provisional device -export calculations are not persisted. Names and folder labels are stored. Removing layers does not renumber surviving +export calculations are not persisted. The current resize mode stays selected +when opening another project in the same session; a fresh launch starts with +Individual mode. Names and folder labels are stored. Removing layers does not renumber surviving IDs; adding a layer consumes `next_layer_id`. Unused input slots are retained to preserve shared-source references. Loading starts a fresh history. Loading requires a replacement confirmation; failed loading leaves current work intact. Writes use diff --git a/docs/midra-layout.md b/docs/midra-layout.md index d7057e4..3896b07 100644 --- a/docs/midra-layout.md +++ b/docs/midra-layout.md @@ -175,9 +175,12 @@ to every selected layer’s own width. independently. Side handles affect only their axis when the ratio is unlocked. - Minimum sizes constrain the shared scale. Invalid geometry rejects the whole update. Crops adjust with sizing, and one Undo restores all layers and crops. -- **Escape** cancels an active drag and exits the mode. Choose **Resize: individual - layer** to return to normal handles; reducing the selection below two also - leaves group resize. Locking/hiding during a drag cancels the entire gesture. +- The last resize mode stays selected for the session, including after selection + changes, Escape, Undo/Redo and project loads. A single selected layer resizes + individually; reselecting multiple layers reuses the chosen mode. Mirror and + Opposite still require exactly two layers. Choose **Resize: individual layer** + to change back explicitly. **Escape** cancels an active drag without resetting + the choice. Locking/hiding during a drag cancels the entire gesture. ## Align selected layers diff --git a/docs/midralayout/changelog.md b/docs/midralayout/changelog.md index 9397ed0..e1ab7e2 100644 --- a/docs/midralayout/changelog.md +++ b/docs/midralayout/changelog.md @@ -4,6 +4,8 @@ ## Unreleased +- Keep the chosen resize mode through selection changes, Escape, Undo/Redo and project loads in the current session; single-layer resizing still works normally. + - “Options save automatically” is non-selectable informational text. - Reorder layers with manager ↑/↓ buttons or drag-and-drop in the inspector. One-step Undo; IDs, links, crops and pending names follow the layer. Test save/reload and SVG order.