graphic design tool
git clone https://git.lucas.co/cce-designer.git
feat: a Show Grid switch in the viewport menu's Guides group
The existing toggle_grid command as a marked row ahead of Show Origin.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CLAUDE.md | 3 ++-
src/app.rs | 5 +++--
src/main.rs | 23 ++++++++++++++++++++++-
3 files changed, 27 insertions(+), 4 deletions(-)
diff --git a/CLAUDE.md b/CLAUDE.md
index d242972..f48445e 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -1377,7 +1377,8 @@ multi-selection, so taking `Shift+L` now would have to be given back later.
### Display mode: the viewport menu, and smooth shading
The viewport's right-click menu carries the DISPLAY MODE under Frame All
-and View 1:1, in five groups a separator apart — guides (Show Origin, the
+and View 1:1, in five groups a separator apart — guides (Show Grid, Show
+Origin, the
scene furniture that is not the geometry); wireframe (switch,
thickness); points (Show Points, Point Size, and Group Marker Scale, which
multiplies it); overlays (Show Point Markers and its size, Show Point
diff --git a/src/app.rs b/src/app.rs
index b187b96..1e0ad84 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -4462,8 +4462,8 @@ impl State {
}
/// The viewport menu's rows and what each does, in groups a separator
- /// apart: framing; the GUIDES (Show Origin — the scene furniture that
- /// is not the geometry); the WIREFRAME (its switch and thickness); the
+ /// apart: framing; the GUIDES (Show Grid, Show Origin — the scene
+ /// furniture that is not the geometry); the WIREFRAME (its switch and thickness); the
/// POINTS
/// (the Show Points switch, point size, and the group marker scale that
/// multiplies it); the OVERLAYS (Show Point Markers and its size, Show
@@ -4486,6 +4486,7 @@ impl State {
// Guides: the scene furniture that is not the geometry.
row(&mut options, &mut actions, "-".into(), sep);
+ row(&mut options, &mut actions, format!("{} {}", mark(self.viewport().show_grid), label("toggle_grid", "Show Grid")), ViewportMenuAction::Command("toggle_grid"));
row(&mut options, &mut actions, format!("{} {}", mark(self.viewport().show_origin), label("toggle_origin", "Show Origin")), ViewportMenuAction::Command("toggle_origin"));
// Wireframe.
diff --git a/src/main.rs b/src/main.rs
index 062419a..a20d304 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1658,7 +1658,7 @@ mod tests {
.map(|g| g.to_vec())
.collect();
assert_eq!(groups[0], vec![A::FrameAll, A::OneToOne]);
- assert_eq!(groups[1], vec![A::Command("toggle_origin")]);
+ assert_eq!(groups[1], vec![A::Command("toggle_grid"), A::Command("toggle_origin")]);
assert_eq!(groups[2], vec![A::Command("toggle_wireframe"), A::WireThicknessSlider]);
assert_eq!(
groups[3],
@@ -1681,6 +1681,27 @@ mod tests {
assert!(options.iter().zip(&actions).all(|(o, a)| (o == "-") == (*a == A::Separator)), "separator rows line up");
}
+ /// Show Grid heads the Guides group, marked from the live flag; the row
+ /// runs the command.
+ #[test]
+ fn the_viewport_menu_toggles_show_grid() {
+ use crate::app::ViewportMenuAction as A;
+ let mut state = State::new(false);
+ state.viewport_mut().show_grid = true;
+ let row = |state: &State| {
+ let (options, actions) = state.viewport_menu_rows();
+ let i = actions.iter().position(|a| *a == A::Command("toggle_grid")).expect("a Show Grid row");
+ options[i].clone()
+ };
+ let label = crate::command::by_id("toggle_grid").unwrap().label;
+ assert_eq!(row(&state), format!("● {label}"));
+ state.run_viewport_menu_action(A::Command("toggle_grid"));
+ assert!(!state.viewport().show_grid);
+ assert_eq!(row(&state), format!("○ {label}"));
+ let kdl = fs::read_to_string(crate::app::DesignSettings::file_path()).expect("saved");
+ assert!(!crate::app::DesignSettings::from_kdl_str(&kdl).viewport.show_grid_enabled, "persisted");
+ }
+
/// Show Origin is a switch in the Guides group, marked from the live
/// flag; the row runs the command, which also keeps the viewport
/// menubar's Guides checkmark in step.