Skip to content

armgit / klad

Public Imported from GitHub
0

A drawing app built for agent/human collaboration

Rust

Menus regrouped, with short labels

Indicode BVc81cacf3eb7f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0e6a88e..3ed5c4f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,7 +19,7 @@ The first builds, and klad's licences.
- Messages say what happened and what to do next; when klad itself goes wrong it says so, and that your work is saved.
- Bones: a layer or group gets a skeleton (`klad bone`, the bone tool J), weights from the bones or painted (`klad weights`), and poses that bend the drawing (`klad pose`, pose mode); in-betweens of two poses turn the bones. The bone tool lists the skeleton, picks a bone in every mode, and moves ends, joints and whole bones with their children (`klad bone --move` with `--by`).
- A first start: the start window welcomes, offers first steps (draw a shape, fill it, hand the drawing to an agent, ticked off as you go; Help > First steps opens them again) and six sample drawings that open as copies (`klad samples` lists and copies them).
-- Menus: a menu bar (the Mac's own, an in-window one on Windows and Linux) holds every command, with its keys, ticks for what is on and greyed items for what cannot run now; File has close (cmd W) and recent drawings.
+- Menus: a menu bar (the Mac's own, an in-window one on Windows and Linux) holds every command in File, Edit, Tools, Layer, Frame, Animation, View, Window and Help, with short labels, its keys, ticks for what is on and greyed items for what cannot run now; File has close (cmd W) and recent drawings.
- Keys: layers, groups and shapes move, turn, scale and fade between frames with eases (`klad key`, the keys section of the inspector).
- Godot: `--godot-rig` exports a Skeleton2D with Polygon2D parts and the poses as animations; `--godot-scene` a parallax scene with a Parallax2D per depth plane.
- `klad paintover` (and "paint over" in the layers panel): brushwork from any picture, strokes that follow its forms and stop at its colour edges, big to small, detail where the picture has it; `--like` and `--frames` carry it through an animation without boiling.
diff --git a/Cargo.lock b/Cargo.lock
index e865a55..7486823 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1744,7 +1744,7 @@ dependencies = [
[[package]]
name = "klad-app"
-version = "0.1.1"
+version = "0.1.2"
dependencies = [
"anyhow",
"block2 0.6.2",
@@ -1773,7 +1773,7 @@ dependencies = [
[[package]]
name = "klad-brush"
-version = "0.1.1"
+version = "0.1.2"
dependencies = [
"anyhow",
"bytemuck",
@@ -1789,7 +1789,7 @@ dependencies = [
[[package]]
name = "klad-cli"
-version = "0.1.1"
+version = "0.1.2"
dependencies = [
"anyhow",
"clap",
@@ -1815,7 +1815,7 @@ dependencies = [
[[package]]
name = "klad-core"
-version = "0.1.1"
+version = "0.1.2"
dependencies = [
"anyhow",
"half",
@@ -1827,7 +1827,7 @@ dependencies = [
[[package]]
name = "klad-render"
-version = "0.1.1"
+version = "0.1.2"
dependencies = [
"anyhow",
"bytemuck",
diff --git a/Cargo.toml b/Cargo.toml
index 5cec737..5b221a9 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -3,7 +3,7 @@ resolver = "3"
members = ["crates/*"]
[workspace.package]
-version = "0.1.1"
+version = "0.1.2"
edition = "2024"
license-file = "LICENSE"
repository = "https://github.com/klad-app/klad"
diff --git a/crates/app/src/commands.rs b/crates/app/src/commands.rs
index bdd36da..20aaafb 100644
--- a/crates/app/src/commands.rs
+++ b/crates/app/src/commands.rs
@@ -351,6 +351,15 @@ impl Bindings {
}
}
+ pub fn menu_key(&self, cmd: Cmd) -> String {
+ let keys = self.keys(cmd);
+ keys.iter()
+ .find(|k| k.key == Key::Backspace)
+ .or(keys.first())
+ .map(Keys::label)
+ .unwrap_or_default()
+ }
+
pub fn is_default(&self, cmd: Cmd) -> bool {
!self.overrides.contains_key(&cmd)
}
@@ -2075,6 +2084,170 @@ impl Cmd {
}
}
+ pub fn menu(self) -> &'static str {
+ match self {
+ Cmd::Brush => "Brush",
+ Cmd::Eraser => "Eraser",
+ Cmd::Fill => "Fill",
+ Cmd::Pen => "Pen",
+ Cmd::ShapeTool => "Rectangles and ellipses",
+ Cmd::TextTool => "Text",
+ Cmd::BoneTool => "Bones",
+ Cmd::Symmetry => "Mirror painting",
+ Cmd::MakeRepeat => "Repeat",
+ Cmd::MakeScatter => "Scatter",
+ Cmd::MakeMirror => "Mirror",
+ Cmd::Unwrap => "Take shapes out",
+ Cmd::ImportPicture => "Import picture…",
+ Cmd::Shapes => "Select and move",
+ Cmd::Strokes => "Select strokes",
+ Cmd::Points => "Edit points",
+ Cmd::Note => "Note",
+ Cmd::Smaller => "Smaller brush",
+ Cmd::Bigger => "Bigger brush",
+ Cmd::Fit => "Fit",
+ Cmd::ActualSize => "100%",
+ Cmd::TurnRight => "Rotate right",
+ Cmd::TurnLeft => "Rotate left",
+ Cmd::Undo => "Undo",
+ Cmd::Redo => "Redo",
+ Cmd::Delete => "Delete",
+ Cmd::Deselect => "Deselect",
+ Cmd::Copy => "Copy",
+ Cmd::Paste => "Paste",
+ Cmd::SelectAll => "Select all",
+ Cmd::CutLasso => "Lasso cuts strokes",
+ Cmd::Recolour => "Recolour",
+ Cmd::Thinner => "Thinner",
+ Cmd::Thicker => "Thicker",
+ Cmd::FlipH => "Flip horizontal",
+ Cmd::FlipV => "Flip vertical",
+ Cmd::Corner => "Corner",
+ Cmd::Smooth => "Smooth",
+ Cmd::Simplify => "Simplify",
+ Cmd::MakePath => "Make path",
+ Cmd::AddSwatch => "Add colour to palette",
+ Cmd::NewPaintLayer => "New paint layer",
+ Cmd::NewVectorLayer => "New vector layer",
+ Cmd::ToggleVisible => "Show",
+ Cmd::ToggleLocked => "Lock",
+ Cmd::ToggleClip => "Clip to layer below",
+ Cmd::ToggleLockAlpha => "Lock alpha",
+ Cmd::AddMask => "Add mask",
+ Cmd::AddMaskHiding => "Add mask hiding all",
+ Cmd::PaintMask => "Paint on mask",
+ Cmd::BackToLayer => "Back to layer",
+ Cmd::RemoveMask => "Remove mask",
+ Cmd::ToggleMask => "Mask on",
+ Cmd::TintMask => "Show mask in red",
+ Cmd::OnionLayer => "This layer's onion",
+ Cmd::NextFrame => "Next frame",
+ Cmd::PrevFrame => "Previous frame",
+ Cmd::NextDrawing => "Next drawing",
+ Cmd::PrevDrawing => "Previous drawing",
+ Cmd::FirstFrame => "First frame",
+ Cmd::LastFrame => "Last frame",
+ Cmd::NewDrawing => "New drawing",
+ Cmd::NewDrawingAfter => "New drawing after",
+ Cmd::Duplicate => "Duplicate to next frame",
+ Cmd::Link => "Link a drawing here…",
+ Cmd::Unlink => "Unlink",
+ Cmd::DeleteDrawing => "Delete drawing",
+ Cmd::HoldLonger => "Hold longer",
+ Cmd::HoldShorter => "Hold shorter",
+ Cmd::InsertFrame => "Insert frame",
+ Cmd::InsertFrameAll => "Insert frame in every layer",
+ Cmd::RemoveFrame => "Remove frame",
+ Cmd::RemoveFrameAll => "Remove frame from every layer",
+ Cmd::ExposeOnes => "Ones",
+ Cmd::ExposeTwos => "Twos",
+ Cmd::ExposeThrees => "Threes",
+ Cmd::Play => "Play",
+ Cmd::LoopRange => "Loop range",
+ Cmd::Prepare => "Prepare frames",
+ Cmd::Onion => "Onion skin",
+ Cmd::OnionSettings => "Onion settings…",
+ Cmd::OnOnes => "Retime on ones",
+ Cmd::OnTwos => "Retime on twos",
+ Cmd::OnThrees => "Retime on threes",
+ Cmd::FitFrames => "Fit into n frames",
+ Cmd::Reverse => "Reverse",
+ Cmd::Pingpong => "Ping-pong",
+ Cmd::EveryLayer => "On every layer",
+ Cmd::Inbetween => "In-between…",
+ Cmd::RedoInbetweens => "Redo in-betweens",
+ Cmd::NewClip => "New clip",
+ Cmd::DeleteClip => "Delete clip",
+ Cmd::ClipLoops => "Loops",
+ Cmd::ClipOwnFps => "Own fps",
+ Cmd::ExportGodot => "Export to Godot",
+ Cmd::Palette => "Find a command…",
+ Cmd::Keys => "Keyboard shortcuts",
+ Cmd::HideAll => "Hide panels",
+ Cmd::HideDock => "Hide dock",
+ Cmd::LayersPane => "Layers",
+ Cmd::ToolPane => "Colour and brush",
+ Cmd::InspectorPane => "Inspector",
+ Cmd::NotesPane => "Notes",
+ Cmd::HistoryPane => "History",
+ Cmd::Timeline => "Timeline",
+ Cmd::Numbers => "Show numbers",
+ Cmd::Settings => "Settings…",
+ Cmd::BrushWindow => "Edit brush…",
+ Cmd::MessageLog => "Message log",
+ Cmd::Spin => "Spin the view",
+ Cmd::ResetNumbers => "Reset numbers",
+ Cmd::FlipView => "Flip",
+ Cmd::ResetRotation => "Upright",
+ Cmd::SwapColours => "Swap colours",
+ Cmd::TurnLeft90 => "Rotate 90° left",
+ Cmd::TurnRight90 => "Rotate 90° right",
+ Cmd::DuplicateInPlace => "Duplicate",
+ Cmd::NudgeLeft => "Nudge left",
+ Cmd::NudgeRight => "Nudge right",
+ Cmd::NudgeUp => "Nudge up",
+ Cmd::NudgeDown => "Nudge down",
+ Cmd::NewGroupLayer => "New group",
+ Cmd::NewAdjustLayer => "New adjustment layer",
+ Cmd::DuplicateLayer => "Duplicate",
+ Cmd::DeleteLayer => "Delete",
+ Cmd::GroupLayer => "Group",
+ Cmd::RenameLayer => "Rename",
+ Cmd::MoveEarlier => "Move earlier",
+ Cmd::MoveLater => "Move later",
+ Cmd::CopyCells => "Copy cells",
+ Cmd::PasteCells => "Paste cells",
+ Cmd::PasteCellsLinked => "Paste cells as links",
+ Cmd::ClipSettings => "Clip settings…",
+ Cmd::NewDocument => "New…",
+ Cmd::OpenDocument => "Open…",
+ Cmd::OpenRecent => "All recent drawings…",
+ Cmd::CopyPath => "Copy path",
+ Cmd::InstallCommand => "Install the klad command",
+ Cmd::ReportProblem => "Report a problem…",
+ Cmd::PaintOver => "Paint over…",
+ Cmd::CompareReference => "Compare with reference",
+ Cmd::About => "About klad and licences",
+ Cmd::Export => "Export…",
+ Cmd::AddFont => "Add font…",
+ Cmd::Refill => "Refill drawing",
+ Cmd::FillLike => "Fill like first drawing",
+ Cmd::ShowGaps => "Show gaps",
+ Cmd::ShowParts => "Show parts",
+ Cmd::ShowArcs => "Show arcs",
+ Cmd::CloseDocument => "Close",
+ Cmd::Quit => "Quit klad",
+ Cmd::FirstSteps => "First steps",
+ Cmd::Parallax | Cmd::Eyedropper | Cmd::Pan | Cmd::Zoom | Cmd::FlipFrames | Cmd::Roll | Cmd::SizeDrag => {
+ self.spec().name
+ }
+ }
+ }
+
+ pub fn ticks(self) -> bool {
+ !self.menu().ends_with('…')
+ }
+
pub fn find(id: &str) -> Option<Cmd> {
Cmd::ALL.into_iter().find(|c| c.spec().id == id)
}
@@ -2096,7 +2269,7 @@ pub struct Menu {
use Item::{Line, Run, Sub};
-pub const MENUS: [Menu; 7] = [
+pub const MENUS: [Menu; 9] = [
Menu {
title: "File",
items: &[
@@ -2105,12 +2278,12 @@ pub const MENUS: [Menu; 7] = [
Item::Recent,
Run(Cmd::CloseDocument),
Line,
- Run(Cmd::Export),
- Run(Cmd::ExportGodot),
- Line,
Run(Cmd::ImportPicture),
Run(Cmd::AddFont),
Line,
+ Run(Cmd::Export),
+ Run(Cmd::ExportGodot),
+ Line,
Run(Cmd::CopyPath),
Run(Cmd::InstallCommand),
Line,
@@ -2133,12 +2306,8 @@ pub const MENUS: [Menu; 7] = [
Run(Cmd::CutLasso),
Line,
Sub(
- "Selection",
+ "Transform",
&[
- Run(Cmd::Recolour),
- Run(Cmd::Thinner),
- Run(Cmd::Thicker),
- Line,
Run(Cmd::FlipH),
Run(Cmd::FlipV),
Run(Cmd::TurnLeft90),
@@ -2150,6 +2319,7 @@ pub const MENUS: [Menu; 7] = [
Run(Cmd::NudgeDown),
],
),
+ Sub("Strokes", &[Run(Cmd::Recolour), Run(Cmd::Thinner), Run(Cmd::Thicker)]),
Sub(
"Points",
&[
@@ -2164,7 +2334,7 @@ pub const MENUS: [Menu; 7] = [
],
},
Menu {
- title: "Draw",
+ title: "Tools",
items: &[
Run(Cmd::Brush),
Run(Cmd::Eraser),
@@ -2185,39 +2355,6 @@ pub const MENUS: [Menu; 7] = [
Line,
Run(Cmd::SwapColours),
Run(Cmd::AddSwatch),
- Line,
- Run(Cmd::Refill),
- Run(Cmd::FillLike),
- Run(Cmd::ShowGaps),
- ],
- },
- Menu {
- title: "View",
- items: &[
- Run(Cmd::Fit),
- Run(Cmd::ActualSize),
- Run(Cmd::TurnRight),
- Run(Cmd::TurnLeft),
- Run(Cmd::ResetRotation),
- Run(Cmd::FlipView),
- Line,
- Run(Cmd::Onion),
- Run(Cmd::OnionSettings),
- Run(Cmd::ShowParts),
- Run(Cmd::ShowArcs),
- Run(Cmd::CompareReference),
- Line,
- Run(Cmd::HideAll),
- Run(Cmd::HideDock),
- Run(Cmd::LayersPane),
- Run(Cmd::ToolPane),
- Run(Cmd::InspectorPane),
- Run(Cmd::NotesPane),
- Run(Cmd::HistoryPane),
- Run(Cmd::Timeline),
- Line,
- Run(Cmd::MessageLog),
- Sub("Numbers", &[Run(Cmd::Numbers), Run(Cmd::ResetNumbers), Run(Cmd::Spin)]),
],
},
Menu {
@@ -2237,7 +2374,6 @@ pub const MENUS: [Menu; 7] = [
Run(Cmd::ToggleLocked),
Run(Cmd::ToggleClip),
Run(Cmd::ToggleLockAlpha),
- Run(Cmd::OnionLayer),
Line,
Sub(
"Mask",
@@ -2252,7 +2388,7 @@ pub const MENUS: [Menu; 7] = [
],
),
Sub(
- "Shapes",
+ "Shape generators",
&[
Run(Cmd::MakeRepeat),
Run(Cmd::MakeScatter),
@@ -2261,24 +2397,23 @@ pub const MENUS: [Menu; 7] = [
],
),
Run(Cmd::PaintOver),
+ Line,
+ Run(Cmd::Refill),
+ Run(Cmd::ShowGaps),
],
},
Menu {
title: "Frame",
items: &[
- Run(Cmd::NextFrame),
- Run(Cmd::PrevFrame),
- Run(Cmd::NextDrawing),
- Run(Cmd::PrevDrawing),
Run(Cmd::FirstFrame),
+ Run(Cmd::PrevFrame),
+ Run(Cmd::NextFrame),
Run(Cmd::LastFrame),
+ Run(Cmd::PrevDrawing),
+ Run(Cmd::NextDrawing),
Line,
Run(Cmd::NewDrawing),
Run(Cmd::NewDrawingAfter),
- Sub(
- "New drawings on",
- &[Run(Cmd::ExposeOnes), Run(Cmd::ExposeTwos), Run(Cmd::ExposeThrees)],
- ),
Run(Cmd::Duplicate),
Run(Cmd::Link),
Run(Cmd::Unlink),
@@ -2288,15 +2423,28 @@ pub const MENUS: [Menu; 7] = [
Run(Cmd::HoldShorter),
Run(Cmd::MoveEarlier),
Run(Cmd::MoveLater),
+ Line,
Run(Cmd::InsertFrame),
Run(Cmd::InsertFrameAll),
Run(Cmd::RemoveFrame),
Run(Cmd::RemoveFrameAll),
- Line,
+ ],
+ },
+ Menu {
+ title: "Animation",
+ items: &[
Run(Cmd::Play),
Run(Cmd::LoopRange),
Run(Cmd::Prepare),
Line,
+ Run(Cmd::Onion),
+ Run(Cmd::OnionSettings),
+ Run(Cmd::OnionLayer),
+ Line,
+ Sub(
+ "New drawings on",
+ &[Run(Cmd::ExposeOnes), Run(Cmd::ExposeTwos), Run(Cmd::ExposeThrees)],
+ ),
Sub(
"Selected frames",
&[
@@ -2326,6 +2474,41 @@ pub const MENUS: [Menu; 7] = [
Run(Cmd::DeleteClip),
],
),
+ Line,
+ Run(Cmd::FillLike),
+ Run(Cmd::ShowParts),
+ Run(Cmd::ShowArcs),
+ ],
+ },
+ Menu {
+ title: "View",
+ items: &[
+ Run(Cmd::Fit),
+ Run(Cmd::ActualSize),
+ Line,
+ Run(Cmd::TurnRight),
+ Run(Cmd::TurnLeft),
+ Run(Cmd::ResetRotation),
+ Run(Cmd::FlipView),
+ Line,
+ Run(Cmd::CompareReference),
+ ],
+ },
+ Menu {
+ title: "Window",
+ items: &[
+ Run(Cmd::HideAll),
+ Run(Cmd::HideDock),
+ Line,
+ Run(Cmd::ToolPane),
+ Run(Cmd::LayersPane),
+ Run(Cmd::InspectorPane),
+ Run(Cmd::NotesPane),
+ Run(Cmd::HistoryPane),
+ Run(Cmd::Timeline),
+ Line,
+ Run(Cmd::MessageLog),
+ Sub("Numbers", &[Run(Cmd::Numbers), Run(Cmd::ResetNumbers), Run(Cmd::Spin)]),
],
},
Menu {
@@ -2344,16 +2527,12 @@ pub const MENUS: [Menu; 7] = [
#[cfg(any(target_os = "macos", test))]
pub const IN_APP_MENU: [Cmd; 2] = [Cmd::Settings, Cmd::Quit];
-pub fn menu_label(cmd: Cmd) -> String {
- let name = cmd.spec().name;
- let mut chars = name.chars();
- chars
- .next()
- .map_or_else(String::new, |c| c.to_uppercase().chain(chars).collect())
+pub fn menu_label(cmd: Cmd) -> &'static str {
+ cmd.menu()
}
pub fn menu_hint(menu: &Menu) -> String {
- let names: Vec<&str> = in_menus(menu.items).iter().take(4).map(|c| c.spec().name).collect();
+ let names: Vec<&str> = in_menus(menu.items).iter().take(4).map(|c| c.menu()).collect();
format!("{}: {}, ...", menu.title, names.join(", "))
}
@@ -2546,7 +2725,59 @@ mod tests {
"holds are gestures, not menu items"
);
assert!(IN_APP_MENU.iter().all(|c| listed.contains(c)));
- assert_eq!(menu_label(Cmd::NewDocument), "New drawing");
+ assert_eq!(menu_label(Cmd::NewDocument), "New…");
+ assert_eq!(Bindings::default().menu_key(Cmd::Delete), "Backspace");
+ assert_eq!(Bindings::default().menu_key(Cmd::Redo), "shift cmd Z");
+ }
+
+ #[test]
+ fn menu_labels_are_short_and_never_twice_in_one_menu() {
+ fn check(title: &str, items: &[Item]) {
+ let mut seen: Vec<&str> = Vec::new();
+ items.iter().for_each(|item| {
+ let label = match item {
+ Item::Run(cmd) => cmd.menu(),
+ Item::Sub(name, inner) => {
+ check(name, inner);
+ name
+ }
+ Item::Recent => "Open recent",
+ Item::Line => return,
+ };
+ assert!(!seen.contains(&label), "{label} twice in {title}");
+ assert!(label.chars().count() <= 30, "{label} in {title} is long for a menu");
+ seen.push(label);
+ });
+ assert!(
+ items.first() != Some(&Item::Line) && items.last() != Some(&Item::Line),
+ "{title} starts or ends with a line"
+ );
+ }
+ MENUS.iter().for_each(|m| check(m.title, m.items));
+ let titles: Vec<&str> = MENUS.iter().map(|m| m.title).collect();
+ assert_eq!(
+ titles,
+ [
+ "File",
+ "Edit",
+ "Tools",
+ "Layer",
+ "Frame",
+ "Animation",
+ "View",
+ "Window",
+ "Help"
+ ]
+ );
+ [
+ Cmd::Export,
+ Cmd::Settings,
+ Cmd::BrushWindow,
+ Cmd::ReportProblem,
+ Cmd::Link,
+ ]
+ .iter()
+ .for_each(|c| assert!(c.menu().ends_with('…'), "{c:?} opens a window"));
}
#[test]
diff --git a/crates/app/src/editor/commands.rs b/crates/app/src/editor/commands.rs
index a389af9..ebe199b 100644
--- a/crates/app/src/editor/commands.rs
+++ b/crates/app/src/editor/commands.rs
@@ -308,7 +308,10 @@ impl Editor {
pub(crate) fn menu_state(&self) -> crate::menus::Shown {
crate::menus::Shown {
off: Cmd::ALL.into_iter().filter(|c| self.can_run(*c).is_some()).collect(),
- on: Cmd::ALL.into_iter().filter(|c| self.is_on(*c) == Some(true)).collect(),
+ on: Cmd::ALL
+ .into_iter()
+ .filter(|c| c.ticks() && self.is_on(*c) == Some(true))
+ .collect(),
}
}
diff --git a/crates/app/src/editor/first.rs b/crates/app/src/editor/first.rs
index 8c351a8..460009c 100644
--- a/crates/app/src/editor/first.rs
+++ b/crates/app/src/editor/first.rs
@@ -95,7 +95,7 @@ impl Editor {
ui.add(
egui::Label::new(
RichText::new(
- "Done. File > Close the drawing shows the samples to look at; Help > Every key lists the keys.",
+ "Done. File > Close shows the samples to look at; Help > Keyboard shortcuts lists the keys.",
)
.color(theme::DONE),
)
diff --git a/crates/app/src/editor/panels.rs b/crates/app/src/editor/panels.rs
index 2ba7a5b..c156b9f 100644
--- a/crates/app/src/editor/panels.rs
+++ b/crates/app/src/editor/panels.rs
@@ -314,14 +314,8 @@ impl Editor {
ui.separator();
self.panel_checks(ui);
ui.separator();
- [
- (Cmd::Palette, "find a command"),
- (Cmd::Numbers, "numbers"),
- (Cmd::Settings, "settings"),
- ]
- .into_iter()
- .for_each(|(cmd, label)| {
- if self.command_button(ui, cmd, Some(label)).clicked() {
+ [Cmd::Palette, Cmd::Numbers, Cmd::Settings].into_iter().for_each(|cmd| {
+ if self.command_button(ui, cmd, Some(cmd.menu())).clicked() {
ui.close();
}
});
@@ -378,9 +372,15 @@ impl Editor {
fn menu_entry(&mut self, ui: &mut egui::Ui, cmd: Cmd) {
let label = commands::menu_label(cmd);
let can = self.can_run(cmd).is_none();
- let response = match self.is_on(cmd) {
- Some(mut on) => ui.add_enabled(can, egui::Checkbox::new(&mut on, label)),
- None => ui.add_enabled(can, egui::Button::new(label).shortcut_text(self.bindings.label(cmd))),
+ let keys = self.bindings.menu_key(cmd);
+ let response = match (self.is_on(cmd).filter(|_| cmd.ticks()), keys.is_empty()) {
+ (Some(mut on), true) => ui.add_enabled(can, egui::Checkbox::new(&mut on, label)),
+ (Some(mut on), false) => ui.add_enabled(
+ can,
+ egui::Checkbox::new(&mut on, (label, egui::Atom::grow(), RichText::new(keys).weak())),
+ ),
+ (None, true) => ui.add_enabled(can, egui::Button::new(label)),
+ (None, false) => ui.add_enabled(can, egui::Button::new(label).shortcut_text(keys)),
}
.hint(self.command_hint(cmd));
if response.clicked() {
@@ -415,19 +415,19 @@ impl Editor {
ui.label(RichText::new(&name).strong());
ui.separator();
[
- (Cmd::NewDocument, "new drawing"),
- (Cmd::OpenDocument, "open"),
- (Cmd::OpenRecent, "recent"),
- (Cmd::Export, "export"),
- (Cmd::AddFont, "add a font"),
- (Cmd::CopyPath, "copy path"),
- (Cmd::InstallCommand, "install the klad command"),
- (Cmd::ReportProblem, "report a problem"),
- (Cmd::About, "about and licences"),
+ Cmd::NewDocument,
+ Cmd::OpenDocument,
+ Cmd::OpenRecent,
+ Cmd::Export,
+ Cmd::AddFont,
+ Cmd::CopyPath,
+ Cmd::InstallCommand,
+ Cmd::ReportProblem,
+ Cmd::About,
]
.into_iter()
- .for_each(|(cmd, label)| {
- if self.command_button(ui, cmd, Some(label)).clicked() {
+ .for_each(|cmd| {
+ if self.command_button(ui, cmd, Some(cmd.menu())).clicked() {
ui.close();
}
});
@@ -487,17 +487,17 @@ impl Editor {
fn panel_checks(&mut self, ui: &mut egui::Ui) {
[
- (Cmd::ToolPane, Pane::Tool),
- (Cmd::LayersPane, Pane::Layers),
- (Cmd::InspectorPane, Pane::Inspector),
- (Cmd::NotesPane, Pane::Notes),
- (Cmd::HistoryPane, Pane::History),
+ Cmd::ToolPane,
+ Cmd::LayersPane,
+ Cmd::InspectorPane,
+ Cmd::NotesPane,
+ Cmd::HistoryPane,
+ Cmd::Timeline,
]
.into_iter()
- .for_each(|(cmd, pane)| {
- self.command_check(ui, cmd, pane.title());
+ .for_each(|cmd| {
+ self.command_check(ui, cmd, cmd.menu());
});
- self.command_check(ui, Cmd::Timeline, "timeline");
}
fn panels_menu(&mut self, ui: &mut egui::Ui, size: egui::Vec2, glyph: f32) {
diff --git a/crates/app/src/editor/ui_tests.rs b/crates/app/src/editor/ui_tests.rs
index 1a98215..da05334 100644
--- a/crates/app/src/editor/ui_tests.rs
+++ b/crates/app/src/editor/ui_tests.rs
@@ -202,7 +202,7 @@ fn the_strip_shrinks_then_folds_its_foot_when_the_window_is_short() {
);
short.get_by_role_and_label(Role::Button, theme::icon::MORE).click();
short.run_steps(2);
- short.get_by_label_contains("settings").click();
+ short.get_by_label_contains("Settings…").click();
short.run_steps(2);
assert!(
short.state().windows.settings,
@@ -2665,7 +2665,10 @@ fn first_steps_tick_as_a_shape_is_drawn_filled_and_handed_to_an_agent() {
h.get_by_label_contains("copy a request").click();
h.run_steps(2);
assert!(h.state().first.handed, "copying the request ticks the third");
- assert!(h.query_by_label_contains("Done. File > Close the drawing").is_some());
+ assert!(
+ h.query_by_label_contains("Done. File > Close shows the samples")
+ .is_some()
+ );
assert!(super::first::prompt(&path).contains(&format!("klad render \"{}\"", path.display())));
h.state_mut().invoke(Cmd::FirstSteps).unwrap();
h.run_steps(2);
@@ -2685,30 +2688,30 @@ fn the_menu_bar_reaches_commands_shows_their_state_and_greys_what_cannot_run() {
};
h.get_by_label("File").click();
h.run_steps(2);
- assert!(h.query_by_label_contains("Close the drawing").is_some());
- h.get_by_label("Export").click();
+ assert!(h.query_by_label("Close cmd W").is_some(), "items carry their keys");
+ h.get_by_label("Export… cmd E").click();
h.run_steps(3);
- assert!(h.state().windows.export, "File > Export opens the export window");
+ assert!(h.state().windows.export, "File > Export… opens the export window");
assert!(h.state().settings.layout.timeline);
- h.get_by_label("View").click();
+ h.get_by_label("Window").click();
h.run_steps(2);
h.get_by_label("Timeline").click();
h.run_steps(3);
- assert!(!h.state().settings.layout.timeline, "View > Timeline hides it");
+ assert!(!h.state().settings.layout.timeline, "Window > Timeline hides it");
h.get_by_label("Edit").click();
h.run_steps(2);
- h.hover_at(item(&h, "Selection").center());
+ h.hover_at(item(&h, "Strokes").center());
h.run_steps(3);
let recolour = h
- .query_all_by_label_contains("Recolour the selected strokes")
+ .query_all_by_label("Recolour")
.next()
- .expect("the selection submenu opens");
+ .expect("the strokes submenu opens");
assert!(recolour.accesskit_node().is_disabled(), "nothing selected greys it out");
h.key_press(Key::Escape);
h.run_steps(2);
h.get_by_label("File").click();
h.run_steps(2);
- h.get_by_label_contains("Close the drawing").click();
+ h.get_by_label("Close cmd W").click();
h.run_steps(2);
assert_eq!(h.state().wants, Some(super::Want::Close));
let _ = std::fs::remove_dir_all(&path);
diff --git a/crates/app/src/home.rs b/crates/app/src/home.rs
index ff0779a..ef86ca5 100644
--- a/crates/app/src/home.rs
+++ b/crates/app/src/home.rs
@@ -660,7 +660,7 @@ mod tests {
h.state_mut().editor.as_mut().unwrap().wants = None;
document_menu(&h).click();
h.run_steps(2);
- h.get_by_label(&format!("{} copy path", theme::icon::COPY)).click();
+ h.get_by_label(&format!("{} Copy path", theme::icon::COPY)).click();
h.run_steps(1);
let copied = h
.output()
@@ -733,11 +733,11 @@ mod tests {
document_menu(&h).click();
h.run_steps(2);
assert!(
- h.query_by_label(&format!("{} install the klad command", theme::icon::DOWNLOAD))
+ h.query_by_label(&format!("{} Install the klad command", theme::icon::DOWNLOAD))
.is_some()
);
assert_eq!(crate::editor::install_job().args, ["install"]);
- h.get_by_label(&format!("{} about and licences", theme::icon::INFO))
+ h.get_by_label(&format!("{} About klad and licences", theme::icon::INFO))
.click();
h.run_steps(3);
assert!(
diff --git a/crates/app/src/menus.rs b/crates/app/src/menus.rs
index ed62c82..b485fce 100644
--- a/crates/app/src/menus.rs
+++ b/crates/app/src/menus.rs
@@ -252,7 +252,7 @@ mod mac {
fn command(mtm: MainThreadMarker, target: &Target, cmd: Cmd, bindings: &Bindings) -> Retained<NSMenuItem> {
let (key, mask) = equivalent(&bindings.keys(cmd));
- let entry = item(mtm, &menu_label(cmd), Some(sel!(kladRun:)), &key, mask);
+ let entry = item(mtm, menu_label(cmd), Some(sel!(kladRun:)), &key, mask);
unsafe { entry.setTarget(Some(target)) };
entry.setTag(Cmd::ALL.iter().position(|c| *c == cmd).unwrap_or_default() as isize);
entry
@@ -360,37 +360,36 @@ mod mac {
klad.addItem(&NSMenuItem::separatorItem(mtm));
klad.addItem(&self::command(mtm, &target, Cmd::Quit, bindings));
bar.addItem(&holding(mtm, &klad));
- let window = menu(mtm, "Window", None);
- window.addItem(&system(mtm, "Minimize", sel!(performMiniaturize:), "m", command));
- window.addItem(&system(
- mtm,
- "Zoom",
- sel!(performZoom:),
- "",
- NSEventModifierFlags::empty(),
- ));
- window.addItem(&NSMenuItem::separatorItem(mtm));
- window.addItem(&system(
- mtm,
- "Bring all to front",
- sel!(arrangeInFront:),
- "",
- NSEventModifierFlags::empty(),
- ));
MENUS.iter().for_each(|m| {
- if m.title == "Help" {
- bar.addItem(&holding(mtm, &window));
- }
let built = menu(mtm, m.title, Some(&target));
fill(mtm, &built, m.items, &target, bindings, recent);
- bar.addItem(&holding(mtm, &built));
- if m.title == "Help" {
- app.setHelpMenu(Some(&built));
+ match m.title {
+ "Window" => {
+ built.addItem(&NSMenuItem::separatorItem(mtm));
+ built.addItem(&system(mtm, "Minimize", sel!(performMiniaturize:), "m", command));
+ built.addItem(&system(
+ mtm,
+ "Zoom",
+ sel!(performZoom:),
+ "",
+ NSEventModifierFlags::empty(),
+ ));
+ built.addItem(&system(
+ mtm,
+ "Bring all to front",
+ sel!(arrangeInFront:),
+ "",
+ NSEventModifierFlags::empty(),
+ ));
+ app.setWindowsMenu(Some(&built));
+ }
+ "Help" => app.setHelpMenu(Some(&built)),
+ _ => {}
}
+ bar.addItem(&holding(mtm, &built));
});
app.setMainMenu(Some(&bar));
app.setServicesMenu(Some(&services));
- app.setWindowsMenu(Some(&window));
super::NATIVE.store(true, Ordering::Relaxed);
}
}
diff --git a/docs/DESIGN.md b/docs/DESIGN.md
index caec31c..d76d981 100644
--- a/docs/DESIGN.md
+++ b/docs/DESIGN.md
@@ -1,4 +1,4 @@
-_Last updated: 2026-11-06 18:35_
+_Last updated: 2026-11-07 08:55_
# klad: design
@@ -438,7 +438,7 @@ Scripts are any language that prints edit ops as JSON lines into `klad apply`. G
- Tool options and selections (M4 batch 2): a bar over the canvas holds the active tool's settings (brush: picker, size, opacity, flow, and a "more" menu for hardness, lightest size, curve, taper, stabiliser and smoothing; fill: reference, gap, tolerance, grow, opacity; strokes: cut at the lasso edge, select all; points: corner, smooth, simplify, make it a path). The strip shows the eraser while the eraser brush or the pen's eraser end is on, and two colours (the current one over the second; X or a click swaps them; picking a colour from a swatch, the hex field or the eyedropper makes the old one the second). cmd alt drag sideways on the canvas sizes the brush (doubling every 120 pt), the circle staying where the drag began. H flips the view left-right (the view's mappings and the GPU matrix mirror; the document does not change); the status line's zoom takes a click for 100% and a double-click to fit, its rotation a click to turn upright. A selection bar sits under (or over) the selection's box: for strokes flips, quarter turns, recolour, thinner, thicker, opacity, copy, paste, duplicate in place, delete, deselect; for a shape flips (sx or sy negated and its rotation mirrored), quarter turns, duplicate in place (an `add` of the node without ids, above it), delete, deselect; for points corner, smooth, nudges, delete. Arrows nudge strokes, a shape or points by 1 px, 10 px with shift. Strokes select across layers (M5 batch 2 round 1): cmd or shift click on rows in the layers panel adds paint layers to the active one (marked with a blue edge); S then lassos, clicks and selects all on all of them, and the selection (one part per layer) moves, turns, scales, flips, recolours, cuts at the lasso edge, copies and deletes as one edit, each layer's marks staying on their layer. A selection on several layers drags as its outline (no GPU lift) and lands on release; copies of several layers paste back into their own layers, a copy of one layer into the active one. The strip's panels button lists the five panels and the timeline with a tick each, so a closed panel always has a way back. U draws rectangles and ellipses on a vector layer (shift for a square or circle, alt from the centre, rounded corners for rectangles; fill, outline and width shared with the pen, the fill in the first colour and the outline in the second, as for the pen's paths) as `rect` and `ellipse` nodes. Mirror painting (the brush bar's "mirror" and its axis) paints every stroke's mirror image as it is drawn, in a second stroke buffer landed after the first, and commits both as plain marks in one history step. Handles are drawn at 12 pt and hit within 12 pt (`grab`); shapes whose rotation is a quarter turn get edge handles too (`lift::stretched` scales their own axis). Pen events that arrive while a shape move or point edit is being written are held and replayed in order after it. The colour and brush pane shows the palette (swatches drag to reorder; the x in a hovered swatch's corner, or a right-click, removes it), recent colours, size presets and the brushes as tiles, each with a sample stroke drawn by `klad-brush` once per brush definition.
- First start (S8.7, `start.rs`, `editor/first.rs`, `klad_core::samples`): until the settings say `welcomed` (set when any drawing opens, or by "Not now"), the start window opens with a welcome offering first steps. First steps make `first steps.klad` (1280 by 800 on paper, one paint layer) in the drawings folder and open it with a small window of three steps that tick as they happen: a brush stroke is saved, a fill is saved, the request for an agent is copied (a sentence with the drawing's path asking the agent to read `klad skill`, render the drawing and add a shadow; "install the klad command" sits next to it). Help > First steps opens and closes the window on any drawing. The checklist is the editor's alone: it teaches the hands on the canvas, and an agent's first steps are `klad skill`. Revisit the third step when klad is an MCP server (S8.10). Under the recent drawings the start window shows the samples: the drawings `samples/shipped.json` names (name, bundle, a line on what it shows), each a card with its thumbnail and that line; a click copies it into the drawings folder without its `.cache` (`samples::copy`, `<name>.klad` or `<name> 2.klad`) and opens the copy, so a sample is never changed. `klad samples` lists the same set and `--copy <name> [--into folder]` copies one (default the current folder). Samples are found like the fonts: `KLAD_SAMPLES`, then `samples/` next to the binary, `../Resources/samples`, `../share/klad/samples`, and a source checkout's `samples/` up to five folders above the binary (where they exist after `just samples`; a sample not built is left out). `packaging/samples.sh` puts them in every build: it builds any that are missing with that build's `klad` (through the sample's `build.sh`, `PYTHON` naming the interpreter), copies them without caches, and renders each one's `<name>.thumb.png` next to it at 336 px, so the start window never renders into the app (a thumbnail outside the bundle is used as it is; only recent drawings' `.cache/thumb.png` are remade when the drawing changes). `app.sh` puts them in `Resources/samples`, `archive.sh` in the archive's `samples/` and the AppImage's `usr/share/klad/samples`; the six weigh about 4 MB.
- Messages and problem reports (S8.8, `report.rs`): a message says what happened and what to do next ("nothing to fill there: click inside closed lines, or raise the gap so small openings close"); a refusal names the step that makes the command possible. Errors that mean klad itself went wrong (an invariant broken, a picture missing that should be there) are `report::Bug`s: the editor says "something went wrong inside klad (what), everything up to your last edit is saved; Help > Report a problem copies what an issue needs" instead of the bare detail; a job whose CLI crashed reads the same, and a job that failed says "<job> did not finish: <the CLI's reason>". Every error message, job failure and crash of the editor or the CLI is appended to `klad.log` next to the settings (`KLAD_LOG` overrides it; past 512 KB the older half goes), one dated line each. Help > Report a problem opens a window with the report as it will be copied: klad's version and where it ran, the system (macOS version, the Linux distribution, Windows' version, and the processor), a place for what happened, the drawing's size, the last 40 messages and the last 40 lines of the log, with the home folder written as `~` and the drawing's folder as `<the drawing's folder>`. "include the drawing" zips the drawing without its cache next to it (`<name> for a report.zip`, stored entries, written by klad itself) and the report names the file to attach; "copy the report" copies it and "open klad's issues" opens GitHub. Nothing is sent by klad. `klad report [--drawing <bundle>]` prints the same report from the command line (version, system, log, the drawing zipped).
-- Menus (S8.6, `commands::MENUS`, `menus.rs`): one list of menus (File, Edit, Draw, View, Layer, Frame, Help) holds every command but the holds (pan, zoom, the eyedropper, flipping, rolling, the parallax preview and sizing on the canvas, which are gestures), so the menus, the palette and the keys stay one list; a test fails when a command is in no menu or in two. Items are the commands' names with their first letter capitalised and their keys; toggles show a tick; a command that cannot run now is greyed out (its reason is the palette's). On macOS the list becomes the system menu bar (`menus::install`, rebuilt when the keys or the recent drawings change): an app menu with About, Settings, Services, hide and Quit, then the list, Window and Help. Items target one Objective-C object (`KladMenuTarget`, `define_class!`) whose `kladRun:` queues the command for the next frame (the editor runs it through `Editor::invoke` as any key would) and whose `validateMenuItem:` reads a snapshot of what is off and on that the app refreshes every 0.4 s. The item keys are shown but not claimed: the object is each menu's delegate and answers no to `menuHasKeyEquivalent:forEvent:target:action:`, so a key still reaches the editor's own dispatch (which knows holds, repeats and text fields) and nothing runs twice; only the app menu's own keys (cmd , cmd Q cmd H) and Window's cmd M are AppKit's. On Windows and Linux (and in tests) the same list is an egui menu bar over the window, hidden with the panels (Tab). File > Open recent lists the last ten drawings; File > Close the drawing (cmd W, refused while a job runs) goes back to the start window, where only new, open, recent and quit run. Settings and Quit sit in the app menu on macOS and in Edit and File elsewhere; About (with the licences) is in Help everywhere and also in the macOS app menu.
+- Menus (S8.6, `commands::MENUS`, `menus.rs`): one list of menus holds every command but the holds (pan, zoom, the eyedropper, flipping, rolling, the parallax preview and sizing on the canvas, which are gestures), so the menus, the palette and the keys stay one list; a test fails when a command is in no menu or in two. The menus, in order: File (new, open, recent, close; import; export; the path and the command line tool), Edit (undo; copy, paste, duplicate, delete; selecting; Transform, Strokes and Points submenus), Tools (the tools, the brush, the colours), Layer (new, duplicate, rename, group, delete; show, lock, clip, lock alpha; Mask and Shape generators submenus, paint over; refill and gaps), Frame (stepping, drawings, holds and moves, inserting and removing frames), Animation (playback, onion skin, exposure, Selected frames and Clip submenus, the checks across frames), View (zoom, rotation, flip, the reference), Window (the panels, the message log, numbers) and Help. Each command has a short menu label (`Cmd::menu`: "Show", "Clip to layer below", "Export…"), since the menu says what it acts on, while the palette and hints keep the longer names; "…" marks a command that opens a window. Items show one key each (Backspace for delete); toggles show a tick, except commands that open a window; a command that cannot run now is greyed out (its reason is the palette's). A test keeps labels unique in each menu and under 30 characters. On macOS the list becomes the system menu bar (`menus::install`, rebuilt when the keys or the recent drawings change): an app menu with About, Settings, Services, hide and Quit, then the list, whose Window menu also gets the system's Minimize, Zoom and Bring all to front (it is the app's windows menu). Items target one Objective-C object (`KladMenuTarget`, `define_class!`) whose `kladRun:` queues the command for the next frame (the editor runs it through `Editor::invoke` as any key would) and whose `validateMenuItem:` reads a snapshot of what is off and on that the app refreshes every 0.4 s. The item keys are shown but not claimed: the object is each menu's delegate and answers no to `menuHasKeyEquivalent:forEvent:target:action:`, so a key still reaches the editor's own dispatch (which knows holds, repeats and text fields) and nothing runs twice; only the app menu's own keys (cmd , cmd Q cmd H) and Window's cmd M are AppKit's. On Windows and Linux (and in tests) the same list is an egui menu bar over the window, hidden with the panels (Tab). File > Open recent lists the last ten drawings; File > Close the drawing (cmd W, refused while a job runs) goes back to the start window, where only new, open, recent and quit run. Settings and Quit sit in the app menu on macOS and in Edit and File elsewhere; About (with the licences) is in Help everywhere and also in the macOS app menu.
- Messages and jobs (M4 batch 1): every result, refusal and error goes through `Editor::say` with a tone (info, done, refused, error). Done and refused messages show for 3.5 and 6 s as a toast next to the pointer where the user acted (jobs' messages at the bottom right), errors until dismissed, info only in the status line; the status line shows the latest message (a click opens the message log, the last 200 with times), the frame, where the next stroke goes ("draws into c12 on lines, frames 4 to 7"), running jobs with a cancel button, slow internal work (preparing a selection, drawing an edited path, loading a frame), zoom and rotation. Times that used to be status text (stroke, fill, edit, undo, sync, frame step, last play, last job) are kept by name for the numbers window. Background jobs (in-betweens, Godot export) run the same `klad` binary through one job list (`jobs.rs`); when the CLI exits with code 75 (the document changed while it computed) the job runs again, up to three times, so an edit made in the editor meanwhile is never overwritten.
- Tools: brush, eraser, smudge, fill (inside lines, gap closing), lasso select and transform, move/rotate/scale handles, path point editing, eyedropper.
- Stroke select (S, M2): click picks the topmost stroke or fill on the active paint layer under the pointer, a dragged loop picks every stroke whose samples are all inside it and every fill whose pixels are, shift adds or toggles. With "a lasso cuts strokes at its edge" (on by default) the loop also takes the parts of strokes and fills crossing it: the selection shows the dashed lasso and the parts that will move, and the first edit (move, recolour, delete, ...) writes one `lasso` op that splits them, after which the selection is the moved marks. The selection shows as thin lines and a box with corner handles (uniform scale), edge handles (stretch one axis; dragging past the other edge flips) and a rotate knob; dragging moves it on the GPU (the selected marks drawn alone, over the cel replayed without them) and release writes one `transform` or `lasso` op. The inspector recolours (the current colour), makes thinner or thicker, sets opacity, flips left-right or up-down and deletes, each as one history step. The selection is shared with the agent as addresses.