diff --git a/crates/midra-layout/src/gui.rs b/crates/midra-layout/src/gui.rs index ba67933..ec4904c 100644 --- a/crates/midra-layout/src/gui.rs +++ b/crates/midra-layout/src/gui.rs @@ -2171,6 +2171,46 @@ impl Editor { if toolbar_icon(ui, button(13), "Output format", ToolbarIcon::Output).clicked() { self.output_draft = Some(OutputDraft::new(output)); } + ui.scope_builder( + egui::UiBuilder::new() + .max_rect(button(16)) + .layout(egui::Layout::left_to_right(egui::Align::Center)), + |ui| { + ui.spacing_mut().interact_size.y = 32.0; + let before = self.snapping; + let menu = toolbar_menu(ui, " ", |ui| self.overlay_grid_options(ui)); + menu.response.widget_info(|| { + egui::WidgetInfo::labeled(egui::WidgetType::Button, true, "Overlay grid") + }); + let center = menu.response.rect.center(); + let color = if self.snapping.show_grid { + palette.cyan + } else { + palette.muted + }; + for n in [-1.0, 0.0, 1.0] { + ui.painter().line_segment( + [ + center + Vec2::new(n * 7.0, -7.0), + center + Vec2::new(n * 7.0, 7.0), + ], + Stroke::new(1.0_f32, color), + ); + ui.painter().line_segment( + [ + center + Vec2::new(-7.0, n * 7.0), + center + Vec2::new(7.0, n * 7.0), + ], + Stroke::new(1.0_f32, color), + ); + } + menu.response + .on_hover_text("Overlay grid — visibility, subdivisions and snapping"); + if before != self.snapping { + self.settings.save(&self.application_settings(ui.ctx())); + } + }, + ); let modifiers = ui.input(|i| i.modifiers); ui.scope_builder( egui::UiBuilder::new() @@ -2449,6 +2489,7 @@ impl Editor { (10, "Align"), (1, "Import"), (14, "Options"), + (16, "Grid"), ] { ui.painter().text( button(slot).center_bottom() + Vec2::new(0.0, 7.0), @@ -2861,6 +2902,28 @@ impl Editor { } else { screen_artwork(&screen, &self.backdrop_title, output); } + if self.snapping.show_grid { + let bounds = Rect::from_min_size(origin, Vec2::new(sw, sh) * scale); + let painter = screen + .painter + .with_clip_rect(screen.painter.clip_rect().intersect(bounds)); + for (axis, dimension) in output.into_iter().enumerate() { + for coordinate in self.snapping.grid_guides(dimension, axis) { + let endpoints = if axis == 0 { + [ + origin + Vec2::new(coordinate as f32 * scale, 0.0), + origin + Vec2::new(coordinate as f32 * scale, sh * scale), + ] + } else { + [ + origin + Vec2::new(0.0, coordinate as f32 * scale), + origin + Vec2::new(sw * scale, coordinate as f32 * scale), + ] + }; + painter.line_segment(endpoints, Stroke::new(1.0_f32, palette.grid)); + } + } + } screen_labels(&screen, output); if self.references.is_empty() { screen_reference_hint(&screen, output); @@ -3508,8 +3571,8 @@ enum ToolbarIcon { } // Keep related tools together when wrapping; reserve caption space per group. -fn toolbar_groups(width: f32, captions: bool) -> ([Rect; 16], Vec, f32) { - let mut buttons = [Rect::NOTHING; 16]; +fn toolbar_groups(width: f32, captions: bool) -> ([Rect; 17], Vec, f32) { + let mut buttons = [Rect::NOTHING; 17]; let mut groups = Vec::new(); let mut x = 24.0; let mut y = 20.0; @@ -3519,7 +3582,7 @@ fn toolbar_groups(width: f32, captions: bool) -> ([Rect; 16], Vec, f32) { &[2, 3], &[4, 5], &[6, 7, 8, 9], - &[10, 11, 12], + &[10, 11, 16, 12], &[13, 14], ] { let cell_width = |slot| match slot { @@ -4158,6 +4221,54 @@ mod tests { assert!(output.shapes.iter().any(|s| matches!(&s.shape, egui::Shape::Text(t) if t.galley.text().starts_with("Some layers are outside the view")))); } + #[test] + fn overlay_grid_remains_over_reference_images_and_can_be_hidden() { + let ctx = egui::Context::default(); + let mut app = Editor::default(); + let before = app.layout.layers().clone(); + let mut png = std::io::Cursor::new(Vec::new()); + image::RgbaImage::new(16, 9) + .write_to(&mut png, image::ImageFormat::Png) + .unwrap(); + for reference in [false, true] { + if reference { + app.load_reference( + &ctx, + &egui::DroppedFile { + name: "grid-guide.png".into(), + bytes: Some(png.get_ref().clone().into()), + ..Default::default() + }, + ); + app.wait_reference(); + } + for divisions in [[8, 6], [3, 4]] { + app.snapping.grid_divisions = divisions; + app.snapping.show_grid = true; + let visible = frame(&mut app, &ctx, vec![]); + let color = theme::palette(&ctx).grid; + let lines = |out: &egui::FullOutput| { + out.shapes.iter().filter(|shape| matches!(&shape.shape, egui::Shape::LineSegment { stroke, .. } if stroke.color == color)).count() + }; + let count = lines(&visible); + app.snapping.show_grid = false; + assert_eq!( + count - lines(&frame(&mut app, &ctx, vec![])), + (divisions[0] + divisions[1] + 2) as usize + ); + if reference { + let image = visible.shapes.iter().position(|shape| matches!(&shape.shape, egui::Shape::Mesh(mesh) if mesh.texture_id == app.references[0].texture.id())).unwrap(); + let grid = visible.shapes.iter().position(|shape| matches!(&shape.shape, egui::Shape::LineSegment { stroke, .. } if stroke.color == color)).unwrap(); + assert!(grid > image); + } + } + } + click_text(&mut app, &ctx, " "); + click_text(&mut app, &ctx, "Show overlay grid"); + assert!(app.snapping.show_grid); + assert_eq!(app.layout.layers(), &before); + } + #[test] fn fit_screen_keeps_output_labels_inside_the_viewport() { let mut png = std::io::Cursor::new(Vec::new()); @@ -4532,7 +4643,7 @@ mod tests { &[2, 3], &[4, 5], &[6, 7, 8, 9], - &[10, 11, 12], + &[10, 11, 16, 12], &[13, 14], ] { assert!( diff --git a/crates/midra-layout/src/main.rs b/crates/midra-layout/src/main.rs index 34d81d6..a2ae140 100644 --- a/crates/midra-layout/src/main.rs +++ b/crates/midra-layout/src/main.rs @@ -157,14 +157,6 @@ fn screen_artwork(ink: &Ink, title: &str, output: [u32; 2]) { let k = artwork_scale(output); ink.rect(0.0, 0.0, width, height, palette.canvas); screen_title(ink, title, output); - for n in 0..=8 { - let x = width * n as f32 / 8.0; - ink.line([x, 36.0 * k], [x, height], palette.grid); - } - for n in 1..=6 { - let y = height * n as f32 / 6.0; - ink.line([0.0, y], [width, y], palette.grid); - } ink.text( 24.0 * k, height - 78.0 * k, diff --git a/crates/midra-layout/src/menu_ui.rs b/crates/midra-layout/src/menu_ui.rs index 3562962..1edd5cb 100644 --- a/crates/midra-layout/src/menu_ui.rs +++ b/crates/midra-layout/src/menu_ui.rs @@ -66,6 +66,22 @@ impl Editor { ui.weak("Images & input snapshots"); self.reference_actions_menu(ui); } + pub(super) fn overlay_grid_options(&mut self, ui: &mut egui::Ui) { + ui.checkbox(&mut self.snapping.show_grid, "Show overlay grid"); + ui.checkbox(&mut self.snapping.grid, "Snap to overlay grid"); + if self.snapping.grid && !self.snapping.enabled { + ui.weak("Enable snapping with the magnet options to snap to the grid."); + } + ui.horizontal(|ui| { + ui.label("Columns"); + ui.add(egui::DragValue::new(&mut self.snapping.grid_divisions[0]).range(1..=64)); + }); + ui.horizontal(|ui| { + ui.label("Rows"); + ui.add(egui::DragValue::new(&mut self.snapping.grid_divisions[1]).range(1..=64)); + }); + ui.weak("Equal divisions of the output. Visibility and snapping are independent."); + } 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| { @@ -74,9 +90,11 @@ impl Editor { &mut self.snapping.screen_edges, "Screen edges, center & quarters", ); + ui.checkbox(&mut self.snapping.grid, "Overlay grid"); ui.checkbox(&mut self.snapping.layer_edges, "Visible layer edges") .on_hover_text("Includes contact between mirrored/opposite resizing layers."); }); + ui.collapsing("Overlay grid settings", |ui| self.overlay_grid_options(ui)); ui.weak("Alt: invert snapping · Shift: 10 px · Ctrl+Shift: 100 px"); } pub(super) fn snapping_menu(&mut self, ui: &mut egui::Ui) { diff --git a/crates/midra-layout/src/settings.rs b/crates/midra-layout/src/settings.rs index b0f2560..0436726 100644 --- a/crates/midra-layout/src/settings.rs +++ b/crates/midra-layout/src/settings.rs @@ -20,7 +20,7 @@ pub struct Settings { impl Default for Settings { fn default() -> Self { Self { - version: 6, + version: 7, autoconnect_at_startup: false, allow_sending_to_program: false, midra_host: String::new(), @@ -58,6 +58,9 @@ impl Settings { } value["snapping"] = serde_json::to_value(midra_layout::snapping::Snapping::default()) .map_err(|e| e.to_string())?; + for field in ["grid", "show_grid", "grid_divisions"] { + value["snapping"].as_object_mut().unwrap().remove(field); + } value["version"] = 3.into(); } if value["version"] == 3 { @@ -81,14 +84,36 @@ impl Settings { value["autoconnect_at_startup"] = false.into(); value["version"] = 6.into(); } + if value["version"] == 6 { + if !value["snapping"].is_object() { + return Err("snapping must be an object".into()); + } + for field in ["grid", "show_grid", "grid_divisions"] { + if value["snapping"].get(field).is_some() { + return Err(format!("Unexpected {field} in version 6 settings")); + } + } + value["snapping"]["grid"] = false.into(); + value["snapping"]["show_grid"] = true.into(); + value["snapping"]["grid_divisions"] = serde_json::json!([8, 6]); + value["version"] = 7.into(); + } let settings: Self = serde_json::from_value(value).map_err(|e| e.to_string())?; settings.validate()?; Ok(settings) } fn validate(&self) -> Result<(), String> { - if self.version != 6 { + if self.version != 7 { return Err(format!("unsupported settings version {}", self.version)); } + if self + .snapping + .grid_divisions + .iter() + .any(|n| !(1..=64).contains(n)) + { + return Err("Grid divisions must be between 1 and 64 per axis".into()); + } if self.recent_themes.is_empty() || self.recent_themes.len() > 3 || self.recent_themes[0] != self.theme @@ -226,7 +251,7 @@ mod tests { for text in [ "broken".to_string(), serde_json::to_string(&Settings { - version: 7, + version: 8, ..Default::default() }) .unwrap(), @@ -251,6 +276,32 @@ mod tests { assert_eq!(Store::at(blocker.join("settings.json")).1, settings); } #[test] + fn version_seven_grid_settings_round_trip_and_validate() { + let example = + include_str!("../../../docs/interfaces/midra-layout-settings-v7.example.json"); + assert_eq!(Settings::parse(example).unwrap(), Settings::default()); + let mut settings = Settings::default(); + settings.snapping.grid = true; + settings.snapping.show_grid = false; + settings.snapping.grid_divisions = [12, 9]; + assert_eq!( + Settings::parse(&serde_json::to_string(&settings).unwrap()).unwrap(), + settings + ); + for divisions in [[0, 6], [8, 65]] { + settings.snapping.grid_divisions = divisions; + assert!(Settings::parse(&serde_json::to_string(&settings).unwrap()).is_err()); + } + let mut legacy: serde_json::Value = serde_json::from_str(include_str!( + "../../../docs/interfaces/midra-layout-settings-v6.example.json" + )) + .unwrap(); + legacy["snapping"]["grid"] = true.into(); + assert!(Settings::parse(&legacy.to_string()).is_err()); + legacy["snapping"] = serde_json::Value::Null; + assert!(Settings::parse(&legacy.to_string()).is_err()); + } + #[test] fn version_six_migrates_with_autoconnect_disabled() { let example = include_str!("../../../docs/interfaces/midra-layout-settings-v6.example.json"); diff --git a/crates/midra-layout/src/snapping.rs b/crates/midra-layout/src/snapping.rs index b3a5ebb..a480ee5 100644 --- a/crates/midra-layout/src/snapping.rs +++ b/crates/midra-layout/src/snapping.rs @@ -8,6 +8,9 @@ pub struct Snapping { pub pixels: bool, pub screen_edges: bool, pub layer_edges: bool, + pub grid: bool, + pub show_grid: bool, + pub grid_divisions: [u32; 2], } impl Default for Snapping { fn default() -> Self { @@ -16,9 +19,21 @@ impl Default for Snapping { pixels: true, screen_edges: true, layer_edges: true, + grid: false, + show_grid: true, + grid_divisions: [8, 6], } } } +impl Snapping { + /// Output-relative overlay lines, bounded for rendering and snapping alike. + pub fn grid_guides(self, size: u32, axis: usize) -> Vec { + let count = self.grid_divisions[axis].clamp(1, 64); + (0..=count) + .map(|i| size as f64 * i as f64 / count as f64) + .collect() + } +} // Screen coordinates remain fractional for custom resolutions not divisible by four. fn screen_guides(size: u32) -> [f64; 5] { [0.0, 0.25, 0.5, 0.75, 1.0].map(|fraction| size as f64 * fraction) @@ -68,6 +83,9 @@ impl Layout { if options.screen_edges { edges.extend(screen_guides(self.formats.output[axis])); } + if options.grid { + edges.extend(options.grid_guides(self.formats.output[axis], axis)); + } if options.layer_edges { for (i, other) in self.layers.iter().enumerate() { if i != index && self.visible(i) { @@ -129,6 +147,12 @@ impl Layout { if options.screen_edges { targets.extend(screen_guides(self.formats.output[axis])); } + let grid_targets = if options.grid { + options.grid_guides(self.formats.output[axis], axis) + } else { + Vec::new() + }; + targets.extend(grid_targets.iter().copied()); if options.layer_edges { for (i, g) in before.layers.iter().enumerate() { if !selected[i] && self.visible[i] { @@ -147,11 +171,12 @@ impl Layout { .enumerate() { for target in &targets { - // Centers align to the interior screen guides; retain - // edge-to-edge behavior at screen/layer boundaries. + // Centers align to screen interior guides and overlay grid lines; + // other targets retain edge-to-edge behavior. if anchor == 2 && (!options.screen_edges || !screen_guides(self.formats.output[axis])[1..4].contains(target)) + && !grid_targets.contains(target) { continue; } @@ -202,6 +227,7 @@ impl Layout { pixels: true, screen_edges: false, layer_edges: false, + ..Default::default() }, 0.0, Some(spacing), @@ -288,6 +314,9 @@ impl Layout { if options.screen_edges { targets.extend(screen_guides(self.formats.output[axis])); } + if options.grid { + targets.extend(options.grid_guides(self.formats.output[axis], axis)); + } if options.layer_edges { for (i, g) in r.before.layers.iter().enumerate() { if !r.targets[i] && self.visible(i) { diff --git a/crates/midra-layout/tests/pivot.rs b/crates/midra-layout/tests/pivot.rs index 30e583f..fd8930c 100644 --- a/crates/midra-layout/tests/pivot.rs +++ b/crates/midra-layout/tests/pivot.rs @@ -229,6 +229,7 @@ fn pivot_placement_honors_screen_layer_pixel_and_grid_options() { pixels: false, screen_edges: true, layer_edges: false, + ..Default::default() }; assert_eq!( layout.snap_pivot(1, [3.0, 600.0], options, 6.0, None, true), diff --git a/crates/midra-layout/tests/snapping.rs b/crates/midra-layout/tests/snapping.rs index f305f0e..0aaac35 100644 --- a/crates/midra-layout/tests/snapping.rs +++ b/crates/midra-layout/tests/snapping.rs @@ -89,6 +89,7 @@ fn pixel_snap_can_be_disabled_and_numeric_entry_bypasses_it() { pixels, screen_edges: false, layer_edges: false, + ..Default::default() }, 6.0, ); @@ -117,6 +118,7 @@ fn resize_snaps_to_screen_keeps_anchor_and_undo() { pixels: false, screen_edges: true, layer_edges: false, + ..Default::default() }, 6.0, ); @@ -141,6 +143,7 @@ fn resize_can_bypass_snapping_and_cancel() { pixels: false, screen_edges: true, layer_edges: false, + ..Default::default() }; assert_eq!( layout.drag_to_snapped([g.x + g.width / 2.0, 2.0], options, 6.0), @@ -201,6 +204,7 @@ fn ratio_locked_corners_reach_fractional_layer_edges() { pixels: false, screen_edges: true, layer_edges: true, + ..Default::default() }, 6.0, ); @@ -417,6 +421,7 @@ fn mirrored_layers_snap_to_exact_contact_from_either_handle_and_keep_anchors() { pixels: false, screen_edges: false, layer_edges: true, + ..Default::default() }; let guides = layout.drag_to_snapped(point, options, 6.0); assert_eq!( @@ -488,7 +493,8 @@ fn meeting_snap_respects_disabled_options_and_requires_actual_edge_contact() { enabled, layer_edges, pixels: false, - screen_edges: false + screen_edges: false, + ..Default::default() }, 6.0 ), @@ -544,6 +550,7 @@ fn opposite_vertical_edges_snap_to_meet() { pixels: false, screen_edges: false, layer_edges: true, + ..Default::default() }, 6.0, ); @@ -632,3 +639,67 @@ fn screen_quarters_snap_resizes_and_pivots_and_respect_screen_toggle() { } } } + +#[test] +fn overlay_grid_snaps_moves_resizes_and_pivots_with_fractional_divisions() { + use midra_layout::ResizeHandle; + let options = Snapping { + enabled: true, + pixels: false, + screen_edges: false, + layer_edges: false, + grid: true, + show_grid: false, + grid_divisions: [7, 5], + }; + let mut layout = Layout::default(); + let x = 1920.0 / 7.0; + let y = 1080.0 / 5.0; + layout.select(Some(0)); + let g = layout.layers()[0]; + layout.start_drag([g.x, g.y]); + let guides = layout.drag_to_snapped([x + 2.0, y - 2.0], options, 6.0); + assert_eq!(guides, [Some(x), Some(y)]); + assert!((layout.layers()[0].x - x).abs() < 1e-8); + assert!((layout.layers()[0].y - y).abs() < 1e-8); + layout.finish_drag(); + layout.undo(); + assert_eq!(layout.layers()[0], g); + layout.start_handle_resize( + 0, + ResizeHandle::Right, + [g.x + g.width, g.center()[1]], + false, + ); + let target = 3.0 * 1920.0 / 7.0; + assert_eq!( + layout.drag_to_snapped([target - 2.0, g.center()[1]], options, 6.0), + [Some(target), None] + ); + assert!((layout.layers()[0].x + layout.layers()[0].width - target).abs() < 1e-8); + layout.cancel_drag(); + assert_eq!( + layout.snap_pivot(0, [x + 1.0, y - 1.0], options, 6.0, None, false), + ([x, y], [Some(x), Some(y)]) + ); + let disabled = Snapping { + grid: false, + ..options + }; + assert_eq!( + layout + .snap_pivot(0, [x + 1.0, y - 1.0], disabled, 6.0, None, false) + .1, + [None; 2] + ); + assert_eq!(options.grid_guides(1920, 0).len(), 8); + assert_eq!( + Snapping { + grid_divisions: [0, u32::MAX], + ..options + } + .grid_guides(1080, 1) + .len(), + 65 + ); +} diff --git a/docs/interfaces/midra-layout-settings-v7.example.json b/docs/interfaces/midra-layout-settings-v7.example.json new file mode 100644 index 0000000..4abed3d --- /dev/null +++ b/docs/interfaces/midra-layout-settings-v7.example.json @@ -0,0 +1,25 @@ +{ + "version": 7, + "theme": "midra", + "recent_themes": [ + "midra" + ], + "show_toolbar_icon_names": false, + "keep_aspect_ratio": true, + "show_source_pattern": false, + "snapping": { + "enabled": false, + "pixels": true, + "screen_edges": true, + "layer_edges": true, + "grid": false, + "show_grid": true, + "grid_divisions": [ + 8, + 6 + ] + }, + "midra_host": "", + "allow_sending_to_program": false, + "autoconnect_at_startup": false +} diff --git a/docs/interfaces/midra-layout-settings.md b/docs/interfaces/midra-layout-settings.md index 5cf48e0..37e066b 100644 --- a/docs/interfaces/midra-layout-settings.md +++ b/docs/interfaces/midra-layout-settings.md @@ -1,13 +1,13 @@ -# Midra Layout application settings, version 6 +# Midra Layout application settings, version 7 Implementation: `crates/midra-layout/src/settings.rs`. This per-user JSON file is independent of the [project JSON and SVG contracts](midra-layout.md). -[Complete default example](midra-layout-settings-v6.example.json). +[Complete default example](midra-layout-settings-v7.example.json). Version 1 files migrate automatically: the saved theme becomes the only entry in `recent_themes`, with all other preferences preserved. The [version 1 example](midra-layout-settings-v1.example.json) remains a migration fixture. Version 2 files then migrate by adding disabled snapping with all target types enabled. The [version 2 example](midra-layout-settings-v2.example.json) -remains a migration fixture too. Version 3 files migrate by adding an empty `midra_host`; the [version 3 example](midra-layout-settings-v3.example.json) remains a migration fixture. Version 4 files migrate by adding `allow_sending_to_program: false`; the [version 4 example](midra-layout-settings-v4.example.json) remains a migration fixture. Version 5 files migrate with `autoconnect_at_startup: false`; the [version 5 example](midra-layout-settings-v5.example.json) remains a migration fixture. Saving writes version 6; old applications reject it. +remains a migration fixture too. Version 3 files migrate by adding an empty `midra_host`; the [version 3 example](midra-layout-settings-v3.example.json) remains a migration fixture. Version 4 files migrate by adding `allow_sending_to_program: false`; the [version 4 example](midra-layout-settings-v4.example.json) remains a migration fixture. Version 5 files migrate with `autoconnect_at_startup: false`; the [version 5 example](midra-layout-settings-v5.example.json) remains a migration fixture. Version 6 files migrate with the overlay grid visible, snapping to it disabled, and `grid_divisions: [8, 6]`; the [version 6 example](midra-layout-settings-v6.example.json) remains a migration fixture. Saving writes version 7; old applications reject it. The `directories` 6 crate resolves `ProjectDirs::from("org", "beffroi", "midra-layout")`. The filename is `settings.json` beneath `config_dir()`: @@ -24,7 +24,7 @@ unknown theme names are rejected. There are no numeric coordinates or units. | Field | Values / default | | --- | --- | -| `version` | Integer `6` | +| `version` | Integer `7` | | `autoconnect_at_startup` | Boolean; default false. Try one background connection at application startup if the saved address is nonblank. | | `allow_sending_to_program` | Boolean; default false. Enables the Program destination in the exporter. Turning it off restores Preview; applies to quick Apply too. | | `midra_host` | Device IP address text; default `""`. Saved as typed, including incomplete drafts; validated when connecting. | @@ -33,7 +33,7 @@ unknown theme names are rejected. There are no numeric coordinates or units. | `show_toolbar_icon_names` | Boolean; default false | | `keep_aspect_ratio` | Boolean; default true | | `show_source_pattern` | Boolean; default false. Shows source patterns on other layers only during crop editing; normal editing always hides patterns. | -| `snapping` | Object with required boolean fields `enabled` (false), `pixels` (true), `screen_edges` (true; screen edges plus 25%, 50% and 75% guides on both axes), `layer_edges` (true); unknown fields rejected | +| `snapping` | Object with required boolean fields `enabled` (false), `pixels` (true), `screen_edges` (true; screen edges plus 25%, 50% and 75% guides on both axes), `layer_edges` (true), `grid` (false), `show_grid` (true), and `grid_divisions` ([8, 6]); unknown fields rejected | Loaded once at startup before the editor appears. Explicit Options changes save the current preferences and theme history immediately. The directory is created lazily; @@ -124,3 +124,22 @@ Alt bypasses these anchors and grids while inverting configured snapping as usua This adds no settings fields; pivot positions are saved per layer in projects. Recovery autosave is a separate `last_project.json` beside settings, not a settings field. See [recovery format](midra-layout-recovery.md). + +## Overlay grid + +`snapping.grid_divisions` contains integer column and row counts, each 1–64. +Grid lines are at `output_width * i / columns` and `output_height * j / rows`, +including output boundaries. Calculations retain fractional screen pixels (no +rounding); the same coordinates drive rendering, movement, resize and pivot +snapping. `show_grid` controls visibility independently of `grid`, which adds these +lines to the magnet targets when `snapping.enabled` is active. Movement snaps +layer edges and centers; resizing uses the existing anchor/ratio rules. Existing +six-logical-pixel proximity tolerance, release behavior and modifier priorities +remain unchanged; explicit 10/100 px grids take precedence. Crop-content resizing +is not snapped. Invalid subdivision counts are rejected on settings load. + +The Grid toolbar icon opens visibility, snapping and subdivision controls; they +also appear in snapping options/preferences. The overlay is drawn above example +artwork and reference pictures, below editable layers, clipped to the output. +It is an editor guide, omitted from all project/export artwork. Preferences save +immediately and survive project changes; v1–v6 migration does not alter geometry. diff --git a/docs/midra-layout/README.md b/docs/midra-layout/README.md index b85ed57..616b96c 100644 --- a/docs/midra-layout/README.md +++ b/docs/midra-layout/README.md @@ -444,6 +444,18 @@ stay selected across selection changes and project loads in this session; they are not saved to projects/settings and start off on launch. They affect layer movement/resize, not numeric edits or crop-content handles. +### Overlay grid + +The **Grid** toolbar icon opens **Show overlay grid**, **Snap to overlay grid**, +and **Columns / Rows** controls (1–64 each, default 8 × 6). The grid is drawn +above reference images and the sample artwork, below layers, across the full output. +Subdivisions scale with the output resolution and can fall on fractional pixels. + +Enable snapping in the magnet menu and **Overlay grid** to snap layer edges, +centers, resize handles and pivots to these lines. Showing and snapping are +independent; the 10/100 px modifier grids still take precedence. These options +are saved in application preferences. The guide is not included in exports. + ### Ctrl resize pivot With Pivot off, hold **Ctrl** (or select **Pivot**) to show a draggable crosshair on selected layers (center by diff --git a/docs/midra-layout/changelog.md b/docs/midra-layout/changelog.md index 485381c..6f62304 100644 --- a/docs/midra-layout/changelog.md +++ b/docs/midra-layout/changelog.md @@ -4,6 +4,8 @@ ## Unreleased +- Move the background grid out of the sample artwork into a full-output overlay above reference images. Add a Grid toolbar menu, independent visibility/snapping, and 1–64 columns/rows (default 8 × 6). Persist these preferences in settings v7 with migration from v1–v6; share fractional grid positions across movement, resizing and pivot snapping. Regression tests cover rendering order, toggles, snapping and settings compatibility. + - Keep the screen name and output resolution visible with reference images, reserving their fit-screen margin. Viewport tests check label visibility and clipping with and without imported images. - Double-click again in visual crop mode to finish editing; preserve selection and framing. Viewport regression coverage checks entering, exiting and reopening without geometry changes.