Canvas context menu: common rows show an icon

The canvas menu draws its rows through craft-libs' rows_with_icons with a
table of 26 commands and icons already in assets/icons: edit, group,
smooth and join, bullets and numbers, grid, rulers, lock guides, fit
artboard, artboard and export rows. Rows without a fitting glyph stay
text only. The icons show in this menu only.

Part of #4602.
This commit is contained in:
ruchirguitar committed 2026-12-03 00:17:06 +05:30
1 parent 2276de06ca
commit 5937e03543
2 files changed
+60 -1

No files matched your search

+59 -1
View File
@@ -1,3 +1,5 @@
use craft::behavior::IconId;
use craft::menu::Item;
use craft::ui::canvas::CanvasSpace;
use craft::ui::contract::overlay::Anchor;
use craft::ui::contract::{Bind, ShowContainer as _, Trigger};
@@ -47,7 +49,7 @@ pub(crate) fn show(app: &mut VectorcraftApp, ui: &mut egui::Ui, space: &CanvasSp
.opened_by(opener, Trigger::Manual)
.anchor(Anchor::Point(at))
.open(Bind::bound(&mut open))
.show(ui, |ui, _| craft::menu::context::rows(ui, &nodes));
.show(ui, |ui, _| craft::menu::context::rows_with_icons(ui, &nodes, canvas_icon));
if shown.output.closed.is_some() || !open {
app.ui.context_menu_at = None;
app.ui.context_locked = None;
@@ -57,6 +59,42 @@ pub(crate) fn show(app: &mut VectorcraftApp, ui: &mut egui::Ui, space: &CanvasSp
}
}
/// The icon each canvas menu command shows in this menu, so a row can be found by its shape (#4602). A command
/// left out has no glyph that says what it does here, and shows its catalog icon, if any, or none.
const ICONS: &[(&str, &str)] = &[
("edit.undo", "undo-2"),
("edit.redo", "redo-2"),
("edit.cut", "scissors"),
("edit.copy", "copy"),
("edit.paste", "clipboard-paste"),
("edit.clear", "trash-2"),
("object.group", "group"),
("object.ungroup", "ungroup"),
("object.path.smooth", "dc-smooth"),
("object.objectsOnPath.attach", "dc-objects-on-path"),
("path.join", "dc-join"),
("type.applyBullets", "dc-para-bullets"),
("type.applyNumbers", "dc-para-numbers"),
("view.grid", "grid-3x3"),
("view.rulers", "ruler"),
("view.guides.lock", "lock"),
("view.fitArtboard", "maximize-2"),
("artboard.new", "file-plus"),
("artboard.duplicate", "copy"),
("artboard.copy", "copy"),
("artboard.cut", "scissors"),
("artboard.delete", "trash-2"),
("artboard.rearrange", "dc-rearrange"),
("artboard.setProps", "dc-artboard-options"),
("file.exportSelection", "share-2"),
("file.exportForScreens", "share-2"),
];
/// The canvas menu's icon for `item`: its command's entry in [`ICONS`].
fn canvas_icon(item: &Item) -> Option<IconId> {
ICONS.iter().find(|(id, _)| *id == item.command.id).map(|(_, icon)| IconId::new(icon))
}
/// The one-shot work of a request at screen point `at`: the facts the menu's rows read, and the selection.
fn prepare(app: &mut VectorcraftApp, space: &CanvasSpace, at: Pos2) {
let p = space.view.to_doc(at);
@@ -114,3 +152,23 @@ fn prepare_key(app: &mut VectorcraftApp, space: &CanvasSpace) -> Pos2 {
}
at
}
#[cfg(test)]
mod tests {
use craft::behavior::IconId;
use craft::ui::primitives::has_icon;
use super::ICONS;
/// Each canvas menu icon names a drawn icon and a command: a misspelt icon would leave its row's icon slot
/// empty, and a renamed command would quietly lose its icon.
#[test]
fn every_canvas_menu_icon_is_an_icon_of_a_command() {
crate::icons::register();
for (id, icon) in ICONS {
assert!(has_icon(&IconId::new(icon)), "{id}'s icon {icon} isn't an icon");
let ui_command = crate::menus::UI_COMMANDS.iter().any(|c| c.0 == *id);
assert!(vectorcraft_engine::find_command(id).is_some() || ui_command, "{id} isn't a command");
}
}
}
+1
View File
@@ -81,6 +81,7 @@ Artboard Options forwards the active Artboard tool's Scale Artwork with Artboard
| Date | Change | Summary |
|---|---|---|
| 2026-12-02 | minor | Canvas context menu: rows for edit, group, path, type, view and artboard commands show a leading icon from the app's icon set, so a row can be found by its shape; rows without a fitting glyph stay text only (#4602); scores and estimates unchanged |
| 2026-12-02 | minor | Headless (RFC-0052) column on the Summary table and every behaviour table: 365 unknown, with marking rules |
| 2026-11-24 | minor | G12: History row context menus use shared Craft List and Menu controls after rebasing onto the panel migration. App-specific actions retain the chosen snapshot across pending edits and dismiss on document switches; keyboard context requests and focus restoration use the shared runtime. Regression cases retained (#8845); scores and estimates unchanged. |
| 2026-11-21 | minor | G12/M14: History row context menus retain the chosen snapshot while the menu is open and pending edits settle; jumps settle typing before counting undo/redo, and discarded states report that they are unavailable. Shift+F10 opens the focused row menu, Escape restores row focus, and switching documents dismisses the popup. History checklist, area and milestone evidence updated (#8845); scores and estimates unchanged. |