Expose snapping in context and quick settings menus

This commit is contained in:
Dandaedre 2026-11-14 12:03:04 +01:00
parent 20dd6c69eb
commit 66075aaf71
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
5 changed files with 83 additions and 7 deletions

View File

@ -1392,6 +1392,8 @@ impl Editor {
}
fn layer_context_menu(&mut self, ui: &mut egui::Ui) {
ui.set_min_width(210.0);
self.snapping_menu(ui);
ui.separator();
let selected = self.layout.selected_indices();
if let Some(i) = self.layout.selected() {
ui.weak(self.layout.layer_label(i));
@ -3108,6 +3110,56 @@ mod tests {
);
frame(app, ctx, vec![mouse(pos, false)]);
}
#[test]
fn quick_and_context_snapping_menus_save_the_same_options_without_editing_layers() {
for context in [false, true] {
let ctx = egui::Context::default();
let mut app = Editor::default();
let temp = tempfile::tempdir().unwrap();
let path = temp.path().join("settings.json");
app.settings = settings::Store::at(path.clone()).0;
app.layout.select(None);
let before = app.layout.layers().clone();
let formats = app.layout.formats().clone();
frame(&mut app, &ctx, vec![]);
let pos = if context {
Pos2::new(400.0, 700.0)
} else {
Pos2::new(408.0, 82.0)
};
let button = if context {
egui::PointerButton::Secondary
} else {
egui::PointerButton::Primary
};
let event = |pressed| egui::Event::PointerButton {
pos,
button,
pressed,
modifiers: egui::Modifiers::NONE,
};
frame(
&mut app,
&ctx,
vec![egui::Event::PointerMoved(pos), event(true)],
);
frame(&mut app, &ctx, vec![event(false)]);
click_text(&mut app, &ctx, "Snapping");
click_text(&mut app, &ctx, "Snap movement & resizing");
assert!(app.snapping.enabled);
for label in ["Pixel edges", "Screen edges", "Visible layer edges"] {
click_text(&mut app, &ctx, label);
}
assert!(
!app.snapping.pixels && !app.snapping.screen_edges && !app.snapping.layer_edges
);
let saved = settings::Store::at(path).1;
assert_eq!(saved.snapping, app.snapping);
assert_eq!(app.layout.layers(), &before);
assert_eq!(app.layout.formats(), &formats);
}
}
#[test]
fn mirror_resize_snaps_at_contact_through_release_and_alt_bypasses() {
for zoom in [0.75, 1.0] {

View File

@ -79,12 +79,35 @@ impl Editor {
self.reference_open = true;
}
}
pub(super) fn snapping_options(&mut self, ui: &mut egui::Ui) {
ui.checkbox(&mut self.snapping.enabled, "Snap movement & resizing");
ui.add_enabled_ui(self.snapping.enabled, |ui| {
ui.checkbox(&mut self.snapping.pixels, "Pixel edges");
ui.checkbox(&mut self.snapping.screen_edges, "Screen edges");
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");
}
pub(super) fn snapping_menu(&mut self, ui: &mut egui::Ui) {
ui.menu_button("Snapping", |ui| {
let before = self.snapping;
self.snapping_options(ui);
if before != self.snapping {
self.settings.save(&self.application_settings(ui.ctx()));
}
if let Some(error) = &self.settings.error {
ui.colored_label(ui.visuals().error_fg_color, error);
}
});
}
pub(super) fn viewport_options_menu(&mut self, ui: &mut egui::Ui) {
if ui.button("Open all settings…").clicked() {
self.preferences_open = true;
ui.close_menu();
}
ui.separator();
self.snapping_menu(ui);
let before = self.application_settings(ui.ctx());
let current = theme::Theme::current(ui.ctx());
ui.menu_button(format!("Theme: {}", current.name()), |ui| {

View File

@ -62,13 +62,8 @@ impl Editor {
ui.checkbox(&mut self.keep_aspect_ratio, "Keep aspect ratio when resizing");
ui.label("Applies to layer handles and numeric width/height edits. Crop zoom always keeps the source proportions.");
ui.separator();
ui.checkbox(&mut self.snapping.enabled, "Snap movement & resizing");
ui.add_enabled_ui(self.snapping.enabled, |ui| {
ui.checkbox(&mut self.snapping.pixels, "Pixel edges");
ui.checkbox(&mut self.snapping.screen_edges, "Screen edges");
ui.checkbox(&mut self.snapping.layer_edges, "Other visible layer edges");
});
ui.weak("Shift: 10 px grid · Ctrl+Shift: 100 px grid · Alt: bypass snapping. Applies to layer movement/resize, not numeric entry or crop-content handles.");
self.snapping_options(ui);
ui.weak("Applies to layer movement/resize, not numeric entry or crop-content handles.");
ui.separator();
ui.label("Arrow keys: move 1 pixel · Shift-arrow: move 10 pixels");
ui.label("Shift-click: add/remove a layer from selection");

View File

@ -538,6 +538,10 @@ presented as implemented until their mapping and transport are available.
### Movement snapping
The viewport right-click menu and quick Options menu both include **Snapping**:
enable movement/resizing snapping and choose pixel, screen or visible-layer edges.
These are the same automatically saved controls as Settings → Editing.
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

View File

@ -4,6 +4,8 @@
## Unreleased
- 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.
- Snap mirrored/opposite resizing to exact edge contact between both moving layers, including unequal sizes; preserve anchors/ratios, Alt bypass and Undo.