From dcc0c4bc12da13fcef3c9ca6373f9eba30d3e91f Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Sat, 14 Nov 2026 12:03:59 +0100 Subject: [PATCH] Temporarily invert snapping while Alt is held --- crates/midra-layout/src/gui.rs | 55 +++++++++++++++++++++++- crates/midra-layout/src/menu_ui.rs | 2 +- docs/interfaces/midra-layout-settings.md | 2 +- docs/midra-layout.md | 8 ++-- docs/midralayout/changelog.md | 2 + 5 files changed, 62 insertions(+), 7 deletions(-) diff --git a/crates/midra-layout/src/gui.rs b/crates/midra-layout/src/gui.rs index ee1494f..c70ad70 100644 --- a/crates/midra-layout/src/gui.rs +++ b/crates/midra-layout/src/gui.rs @@ -1684,7 +1684,7 @@ impl Editor { } else { let mut snapping = self.snapping; if modifiers.alt { - snapping.enabled = false; + snapping.enabled = !snapping.enabled; } self.layout .drag_to_snapped(point, snapping, 6.0 / scale as f64) @@ -3110,6 +3110,59 @@ mod tests { ); frame(app, ctx, vec![mouse(pos, false)]); } + #[test] + fn alt_temporarily_inverts_move_and_resize_snapping_and_overrides_grids() { + for enabled in [false, true] { + for resize in [false, true] { + for shift in [false, true] { + for ctrl in [false, true] { + let mut app = Editor::default(); + app.snapping.enabled = enabled; + app.snapping.pixels = false; + app.snapping.layer_edges = false; + let before = app.layout.layers().clone(); + let saved = app.snapping; + let point = if resize { + app.layout.start_handle_resize( + 1, + ResizeHandle::Right, + [1800.0, 360.0], + false, + ); + [1918.0, 360.0] + } else { + app.layout.start_drag([1160.0, 180.0]); + [1278.0, 180.0] + }; + let guides = app.drag_with_modifiers( + point, + egui::Modifiers { + alt: true, + shift, + ctrl, + ..Default::default() + }, + 0.75, + ); + assert_eq!(guides[0], if enabled { None } else { Some(1920.0) }); + let g = app.layout.layers()[1]; + assert_eq!(g.x + g.width, if enabled { 1918.0 } else { 1920.0 }); + assert_eq!(app.snapping, saved); + // Releasing Alt restores the stored setting without a pointer move. + let guides = app.drag_with_modifiers(point, egui::Modifiers::NONE, 0.75); + assert_eq!(guides[0], if enabled { Some(1920.0) } else { None }); + let g = app.layout.layers()[1]; + assert_eq!(g.x + g.width, if enabled { 1920.0 } else { 1918.0 }); + app.layout.finish_drag(); + app.layout.undo(); + assert_eq!(app.layout.layers(), &before); + assert_eq!(app.snapping, saved); + } + } + } + } + } + #[test] fn quick_and_context_snapping_menus_save_the_same_options_without_editing_layers() { for context in [false, true] { diff --git a/crates/midra-layout/src/menu_ui.rs b/crates/midra-layout/src/menu_ui.rs index 4881a4a..96f60a7 100644 --- a/crates/midra-layout/src/menu_ui.rs +++ b/crates/midra-layout/src/menu_ui.rs @@ -87,7 +87,7 @@ impl Editor { ui.checkbox(&mut self.snapping.layer_edges, "Visible layer edges") .on_hover_text("Includes contact between mirrored/opposite resizing layers."); }); - ui.weak("Alt: bypass · Shift: 10 px · Ctrl+Shift: 100 px"); + ui.weak("Alt: invert snapping · Shift: 10 px · Ctrl+Shift: 100 px"); } pub(super) fn snapping_menu(&mut self, ui: &mut egui::Ui) { ui.menu_button("Snapping", |ui| { diff --git a/docs/interfaces/midra-layout-settings.md b/docs/interfaces/midra-layout-settings.md index 74d344f..e954c8b 100644 --- a/docs/interfaces/midra-layout-settings.md +++ b/docs/interfaces/midra-layout-settings.md @@ -105,7 +105,7 @@ 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. -Shift temporarily overrides snapping with a 10-screen-pixel grid for layer movement and resizing; Ctrl+Shift uses 100 pixels. Alt bypasses both grids and ordinary snapping, including on release. These modifiers do not change the saved options or settings version. +Shift temporarily overrides snapping with a 10-screen-pixel grid for layer movement and resizing; Ctrl+Shift uses 100 pixels. Alt overrides both grids and temporarily inverts the saved snapping-enabled value (off becomes on; on becomes off), including on release. The chosen pixel/screen/layer-edge targets still apply. These modifiers do not change the saved options or settings version. **Settings → Midra integration → Allow sending to Program** saves immediately. Restore default settings disables it. Projects do not override this application preference; the Preview/Program destination itself remains session-only. diff --git a/docs/midra-layout.md b/docs/midra-layout.md index c3f8a4d..a4aa45e 100644 --- a/docs/midra-layout.md +++ b/docs/midra-layout.md @@ -546,7 +546,7 @@ Enable **Settings → Editing → Snap movement & resizing** and choose pixel, screen-edge and/or other-visible-layer-edge targets. Nearby edges show a guide; the proximity radius stays six logical pixels at any zoom. A selection moves as a rigid group. Hidden layers are ignored; visible locked layers can be targets. -Hold **Alt** to bypass snapping. Turning snapping on/off alone never moves layers. +Hold **Alt** to temporarily invert snapping: off when enabled, on when disabled. Turning snapping on/off alone never moves layers. Exact numeric entry and nudges bypass proximity snapping; resize handles snap while preserving their anchors/ratios, and crop-content handles retain their existing behavior. One drag remains one undo step, with Escape to cancel. @@ -616,7 +616,7 @@ failed replacements keep the current image. Decoder work is serialized to bound peak memory. Minification uses linear filtering, magnification nearest-neighbor. Embedded reference decoding during project load remains synchronous. -Resize snapping now uses the same preference and Alt bypass as movement snapping. +Resize snapping now uses the same preference and Alt inversion as movement snapping. It preserves opposite anchors, aspect ratio and group-resize proportions. Guides appear only when the resulting handle reaches the target; crop-content gestures remain unsnapped. At 2 logical pixels per screen pixel, adaptive coordinate rulers @@ -670,7 +670,7 @@ Layer rows use padlock and eye icon buttons for locking and visibility, with too Hold **Shift** while moving or resizing layers to snap to a **10 px grid**; **Ctrl+Shift** uses a **100 px grid**. These temporary grids override ordinary pixel/edge snapping, even when snapping is disabled in Settings. **Alt** -bypasses both. The modifier state on release determines the final position. +overrides both grids and temporarily inverts ordinary snapping. The modifier state on release determines the final position. Grid coordinates are screen pixels measured from the screen's top-left, independent of viewport zoom. Group movement snaps the selection's bounding top-left and keeps relative spacing. Resize snapping keeps opposite anchors and group proportions; @@ -684,7 +684,7 @@ 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. +continue resizing, or hold Alt to temporarily invert snapping. 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. diff --git a/docs/midralayout/changelog.md b/docs/midralayout/changelog.md index c6ae048..3388ea9 100644 --- a/docs/midralayout/changelog.md +++ b/docs/midralayout/changelog.md @@ -4,6 +4,8 @@ ## Unreleased +- Hold Alt to temporarily invert movement/resize snapping (on ↔ off), overriding Shift grids without changing saved settings. + - Add Snapping controls to viewport right-click and quick Options menus; share and automatically save the same editing settings. - In Adjust layer crop mode, alignment buttons move zoomed content within the fixed layer box; preserve zoom and support Undo.