SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Context menus, radial menu and rename popover on the UI kit
Nathan Danea3e2fe25bb51
diff --git a/assets/icons/ui/source/glyphs.rs b/assets/icons/ui/source/glyphs.rsindex e2dda8574e..241bd18cbb 100644--- a/assets/icons/ui/source/glyphs.rs+++ b/assets/icons/ui/source/glyphs.rs@@ -146,11 +146,3 @@ pub(crate) fn cross(p: &egui::Painter, r: Rect, s: Stroke) {p.line_segment([r.left_top(), r.right_bottom()], s);p.line_segment([r.right_top(), r.left_bottom()], s);}-pub(crate) fn radial_centre(p: &egui::Painter, c: Pos2, direction: Option<(egui::Vec2, bool)>, t: crate::theme::Tokens) {- p.circle(c, 15.0, t.panel.gamma_multiply(0.92), Stroke::new(1.0, t.border));- if let Some((d, enabled)) = direction {- p.line_segment([c + d * 6.0, c + d * 15.0], Stroke::new(3.0, if enabled { t.accent } else { t.border }));- } else {- p.circle_filled(c, 3.0, t.text_dim);- }-}diff --git a/crates/ui-egui/src/context_menu.rs b/crates/ui-egui/src/context_menu.rsindex f036911757..da64bd1832 100644--- a/crates/ui-egui/src/context_menu.rs+++ b/crates/ui-egui/src/context_menu.rs@@ -11,15 +11,12 @@//! state; [`items`] lists them and [`run_item`] runs one, so the control channel (`ui.menu`,//! `ui.menuPick`) and tests reach everything a click does.-use crate::fonts::RichTextExt as _;-use egui::{Align2, Color32, FontId, Pos2, Rect, Sense, Stroke, Vec2, pos2, vec2};+use egui::{Color32, Pos2, Rect, Sense, Vec2, pos2, vec2};use serde::Serialize;use serde_json::{Value, json};use solidcraft_engine::Sel;-use crate::theme::Tokens;--use crate::{SolveApp, icons};+use crate::SolveApp;/// What a menu is about.#[derive(Clone, Debug, Default, PartialEq, Serialize, serde::Deserialize)]@@ -104,6 +101,10 @@ pub struct Item {pub icon: String,#[serde(skip_serializing_if = "Option::is_none")]pub params: Option<Value>,+ #[serde(skip_serializing_if = "Vec::is_empty")]+ pub children: Vec<Item>,+ #[serde(skip_serializing_if = "Option::is_none")]+ pub swatch: Option<[u8; 3]>,}impl Item {@@ -112,10 +113,28 @@ impl Item {act(id, label, icon)}pub fn sep() -> Item {- Item { id: "-".into(), label: String::new(), shortcut: String::new(), enabled: false, icon: String::new(), params: None }+ Item {+ id: "-".into(),+ label: String::new(),+ shortcut: String::new(),+ enabled: false,+ icon: String::new(),+ params: None,+ children: Vec::new(),+ swatch: None,+ }}fn heading(label: &str) -> Item {- Item { id: format!("#{label}"), label: label.into(), shortcut: String::new(), enabled: false, icon: String::new(), params: None }+ Item {+ id: format!("#{label}"),+ label: label.into(),+ shortcut: String::new(),+ enabled: false,+ icon: String::new(),+ params: None,+ children: Vec::new(),+ swatch: None,+ }}fn is_sep(&self) -> bool {self.id == "-"@@ -155,12 +174,23 @@ pub(crate) fn cmd(app: &SolveApp, id: &str, label: &str) -> Item {enabled: info.as_ref().is_some_and(|i| i.enabled),icon: info.map(|i| i.icon.to_string()).unwrap_or_default(),params: None,+ children: Vec::new(),+ swatch: None,}}/// A view action (`ui.*`).pub(crate) fn act(id: &str, label: &str, icon: &str) -> Item {- Item { id: id.into(), label: label.into(), shortcut: String::new(), enabled: true, icon: icon.into(), params: None }+ Item {+ id: id.into(),+ label: label.into(),+ shortcut: String::new(),+ enabled: true,+ icon: icon.into(),+ params: None,+ children: Vec::new(),+ swatch: None,+ }}/// Menu state kept between frames. The anchor is `app.viewport.context_menu`.@@ -169,6 +199,8 @@ pub struct MenuState {pub target: Target,/// The list row chosen with the arrow keys (Enter runs it).pub key_row: Option<usize>,+ submenu: Option<usize>,+ submenu_key: Option<usize>,/// The radial ring is shown (viewport menus).pub radial: bool,/// The right button is held through the menu: releasing over a direction picks it.@@ -215,8 +247,8 @@ pub struct Rename {/// Radial slots, clockwise from the top.const DIRS: usize = 8;/// Half axes of the ring of radial items.-const RX: f32 = 118.0;-const RY: f32 = 84.0;+const RX: f32 = crate::ui_kit::RADIAL_RADIUS;+const RY: f32 = crate::ui_kit::RADIAL_RADIUS;// ---------------------------------------------------------------------------------------------// What the menus offer@@ -310,8 +342,8 @@ pub fn items(app: &SolveApp, target: &Target) -> Vec<Item> {Target::Body { name } => body_items(app, std::slice::from_ref(name), true),Target::Sketch { id } => sketch_items(app, *id),Target::Feature { id } => vec![- act("ui.editFeature", "Edit Feature", "").with(json!({"feature":id})).on(app.session.doc.feature(*id).is_some()),- act("ui.findTimeline", "Find in Timeline", "").with(json!({"feature":id})).on(app.session.doc.feature(*id).is_some()),+ act("ui.editFeature", "Edit Feature", "edit").with(json!({"feature":id})).on(app.session.doc.feature(*id).is_some()),+ act("ui.findTimeline", "Find in Timeline", "rollback").with(json!({"feature":id})).on(app.session.doc.feature(*id).is_some()),],Target::Plane { id } => plane_items(app, *id),Target::OriginPlane { name } => origin_plane_items(app, name),@@ -354,6 +386,43 @@ pub fn items(app: &SolveApp, target: &Target) -> Vec<Item> {v.push(Item::sep());v.push(act("ui.groupSelected", "Group Selected", "folder").with(p));}+ for item in &mut v {+ if item.id != "ui.appearance" {+ continue;+ }+ let original = item.clone();+ let params = item.params.clone().unwrap_or_else(|| {+ let faces: Vec<_> = app+ .session+ .selection+ .iter()+ .filter_map(|s| match s {+ Sel::Face { body, point, .. } => Some(json!({"body":body,"point":[point.x, point.y, point.z]})),+ _ => None,+ })+ .collect();+ if faces.is_empty() { json!({"bodies": touched_bodies(app)}) } else { json!({"faces":faces}) }+ });+ let targets = if let Some(component) = params.get("component").and_then(Value::as_u64).filter(|id| *id != 0) {+ json!({"components": [component.to_string()]})+ } else {+ params+ };+ item.children.push(original);+ if ["bodies", "components", "faces"].iter().any(|key| targets.get(key).and_then(Value::as_array).is_some_and(|v| !v.is_empty())) {+ for look in crate::dialogs_appearance::builtin() {+ let mut params = targets.clone();+ params["appearance"] = json!(look.name);+ params["color"] = json!(crate::dialogs_appearance::hex(look.color));+ params["opacity"] = json!(look.opacity);+ let mut child = cmd(app, "appearance.assign", &look.name).with(params);+ child.swatch = Some(look.color);+ item.children.push(child);+ }+ item.children.push(Item::sep());+ item.children.push(cmd(app, "appearance.assign", "Remove override").with(targets));+ }+ }v}@@ -1421,6 +1490,8 @@ pub fn open(app: &mut SolveApp, at: Pos2) {/// Open a menu for a target (the radial ring only for the viewport).pub fn open_for(app: &mut SolveApp, at: Pos2, target: Target) {app.menu.key_row = None;+ app.menu.submenu = None;+ app.menu.submenu_key = None;app.menu.radial = target == Target::Viewport && app.preferences.radial_context_menu;app.menu.target = target;app.menu.flick = false;@@ -1483,7 +1554,9 @@ pub fn pick(app: &mut SolveApp, key: &str) -> Result<Value, String> {let Some(at) = app.viewport.context_menu else { return Err("no menu is open".into()) };let target = app.menu.target.clone();let mut all = if app.menu.radial { radial_items(app) } else { Vec::new() };- all.extend(items(app, &target));+ let roots = items(app, &target);+ all.extend(roots.iter().cloned());+ all.extend(roots.into_iter().flat_map(|item| item.children));let item =all.into_iter().find(|i| !i.is_sep() && !i.is_heading() && (i.id == key || i.label == key)).ok_or_else(|| format!("no menu item `{key}`"))?;if !item.enabled {@@ -1496,8 +1569,8 @@ pub fn pick(app: &mut SolveApp, key: &str) -> Result<Value, String> {/// Where the radial menu goes so its ring stays on screen.fn radial_center(at: Pos2, screen: Rect) -> Pos2 {- let mx = RX + 165.0;- let my = RY + 34.0;+ let mx = RX + 4.0;+ let my = RY + 4.0;let x = if screen.width() > 2.0 * mx { at.x.clamp(screen.left() + mx, screen.right() - mx) } else { screen.center().x };let y = if screen.height() > 2.0 * my { at.y.clamp(screen.top() + my, screen.bottom() - my) } else { screen.center().y };pos2(x, y)@@ -1505,15 +1578,15 @@ fn radial_center(at: Pos2, screen: Rect) -> Pos2 {/// Height of a list of items as [`list_row`] draws them in [`menu_frame`] (margins and border).fn list_height(items: &[Item]) -> f32 {- 10.0 + items+ 14.0 + items.iter().map(|i| {if i.is_sep() {- 7.0+ 11.0} else if i.is_heading() {- 20.0- } else {24.0+ } else {+ 30.0}}).sum::<f32>()@@ -1522,16 +1595,16 @@ fn list_height(items: &[Item]) -> f32 {/// Where the list goes next to a ring centred at `c`: below it when it fits, otherwise beside/// it (right, else left), kept on screen.fn list_place(c: Pos2, h: f32, screen: Rect) -> Pos2 {- let below = c.y + RY + 26.0;+ let below = c.y + RY + 12.0;if below + h <= screen.bottom() - 4.0 {return pos2((c.x - LIST_W / 2.0).clamp(screen.left() + 4.0, (screen.right() - LIST_W - 4.0).max(screen.left())), below);}let y = (c.y - h / 2.0).clamp(screen.top() + 4.0, (screen.bottom() - h - 4.0).max(screen.top()));- let right = c.x + RX + 170.0;+ let right = c.x + RX + 12.0;if right + LIST_W <= screen.right() - 4.0 {return pos2(right, y);}- pos2((c.x - RX - 170.0 - LIST_W).max(screen.left() + 4.0), y)+ pos2((c.x - RX - 12.0 - LIST_W).max(screen.left() + 4.0), y)}/// Width of list menus.@@ -1565,28 +1638,6 @@ fn sector(d: Vec2) -> Option<usize> {Some((k.rem_euclid(DIRS as i64)) as usize)}-/// The rectangle of radial slot `k` with a label of `size`.-fn slot_rect(c: Pos2, k: usize, size: Vec2) -> Rect {- let a = (k as f32 * 45.0).to_radians();- let p = c + vec2(a.sin() * RX, -a.cos() * RY);- let (sx, sy) = (a.sin(), -a.cos());- let ax = if sx > 0.3 {- 0.0- } else if sx < -0.3 {- 1.0- } else {- 0.5- };- let ay = if sy > 0.9 {- 0.0- } else if sy < -0.9 {- 1.0- } else {- 0.5- };- Rect::from_min_size(p - vec2(size.x * ax, size.y * ay), size)-}-/// Press-and-hold of the right button in the viewport opens the menu; releasing over a/// direction picks it.fn track_hold(app: &mut SolveApp, ctx: &egui::Context) {@@ -1650,7 +1701,6 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) {show_rename(app, ctx);crate::design_properties::show_object(app, ctx);let Some(at) = app.viewport.context_menu else { return };- let t = Tokens::get();let screen = ctx.content_rect();let target = app.menu.target.clone();let list = items(app, &target);@@ -1663,43 +1713,12 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) {} else if app.menu.radial {let c = radial_center(at, screen);let radial = radial_items(app);- let area = Rect::from_center_size(c, vec2(2.0 * (RX + 165.0), 2.0 * (RY + 34.0)));+ let area = Rect::from_center_size(c, vec2(2.0 * (RX + 4.0), 2.0 * (RY + 4.0)));inside |= pointer.is_some_and(|p| area.contains(p));let hot = pointer.and_then(|p| sector(p - c));let resp = crate::frame::area(egui::Id::new("sc_marking_menu")).fixed_pos(area.min).order(egui::Order::Foreground).show(ctx, |ui| {- let (r, _) = ui.allocate_exact_size(area.size(), Sense::hover());- let painter = ui.painter_at(r.expand(4.0));- let font = FontId::proportional(crate::theme::Tokens::get().font_button);- // Centre: a ring with a pointer toward the hot direction.- let direction = hot.zip(pointer).map(|(k, p)| ((p - c).normalized(), radial.get(k).is_some_and(|i| i.enabled)));- crate::icons::glyphs::radial_centre(&painter, c, direction, t);- for (k, item) in radial.iter().enumerate() {- let display_label = crate::i18n::tr_label(&item.label);- let galley = painter.layout_no_wrap(display_label.to_string(), font.clone(), if item.enabled { t.text } else { t.text_dim });- let size = vec2(galley.size().x + 40.0, 28.0);- let rr = slot_rect(c, k, size);- let resp = ui.interact(rr, ui.id().with(("radial", k)), Sense::click());- let lit = item.enabled && (resp.hovered() || hot == Some(k));- painter.rect(- rr,- 14.0,- if lit { t.accent_soft } else { t.panel },- Stroke::new(1.0, if lit { t.accent } else { t.border }),- egui::StrokeKind::Inside,- );- let ir = Rect::from_center_size(pos2(rr.left() + 16.0, rr.center().y), vec2(16.0, 16.0));- let ink = if item.enabled { t.icon } else { t.border };- if !item.icon.is_empty() {- icons::paint(&painter, ir, &item.icon, ink, t.icon_fill, t.accent);- }- painter.galley(pos2(rr.left() + 30.0, rr.center().y - galley.size().y / 2.0), galley, t.text);- if resp.clicked() && item.enabled {- picked = Some(item.clone());- }- if item.enabled {- resp.on_hover_text(crate::i18n::tr_label(&item.shortcut).to_string());- }- }+ let _ = ui.allocate_exact_size(area.size(), Sense::hover());+ picked = crate::ui_kit::radial_menu(ui, c, &radial, hot).or(picked.take());});inside |= resp.response.contains_pointer();list_place(c, list_height(&list), screen)@@ -1707,32 +1726,49 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) {place(at, Vec2::ZERO, vec2(LIST_W, list_height(&list)), screen)};- // Up/Down choose a row of the list, Enter runs it.- let (up, down, enter) = ctx.input(|i| (i.key_pressed(egui::Key::ArrowUp), i.key_pressed(egui::Key::ArrowDown), i.key_pressed(egui::Key::Enter)));- let usable: Vec<usize> = list.iter().enumerate().filter(|(_, i)| i.enabled && !i.is_sep() && !i.is_heading()).map(|(k, _)| k).collect();- if up || down {- let at = app.menu.key_row.and_then(|r| usable.iter().position(|u| *u == r));- let next = match (at, down) {- (None, true) => Some(0),- (None, false) => usable.len().checked_sub(1),- (Some(k), true) => Some((k + 1) % usable.len().max(1)),- (Some(k), false) => Some((k + usable.len().max(1) - 1) % usable.len().max(1)),- };- app.menu.key_row = next.and_then(|k| usable.get(k).copied());- }- if enter && let Some(item) = app.menu.key_row.and_then(|r| list.get(r)) {- picked = Some(item.clone());+ let had_submenu = app.menu.submenu.is_some();+ let enabled: Vec<_> = list.iter().map(|i| i.enabled && !i.is_sep() && !i.is_heading()).collect();+ if app.menu.submenu.is_none() {+ let enter = crate::ui_kit::Menu::navigate(ctx, &enabled, &mut app.menu.key_row);+ let right = ctx.input(|i| i.key_pressed(egui::Key::ArrowRight));+ if let Some(k) = app.menu.key_row+ && let Some(item) = list.get(k)+ {+ if (right || enter) && !item.children.is_empty() {+ app.menu.submenu = Some(k);+ app.menu.submenu_key = item.children.iter().position(|c| c.enabled);+ } else if enter {+ picked = Some(item.clone());+ }+ }+ } else if ctx.input(|i| i.key_pressed(egui::Key::ArrowLeft)) {+ app.menu.submenu = None;+ app.menu.submenu_key = None;}+ let mut submenu_row = None;let key_row = app.menu.key_row;let resp =crate::frame::area(egui::Id::new("sc_context_menu")).fixed_pos(list_at).constrain(true).order(egui::Order::Foreground).show(ctx, |ui| {if target == Target::Workspace {- picked = workspace_menu(ui, &list, key_row, (screen.bottom() - list_at.y).max(160.0)).or(picked.take());+ picked = crate::ui_kit::workspace_menu(ui, &list, key_row, (screen.bottom() - list_at.y).max(160.0)).or(picked.take());} else {menu_frame(ui, |ui| {for (k, item) in list.iter().enumerate() {- if let Some(p) = list_row_lit(ui, item, key_row == Some(k)) {- picked = Some(p);+ if item.children.is_empty() {+ if let Some(p) = list_row_lit(ui, item, key_row == Some(k)) {+ picked = Some(p);+ }+ } else {+ let row = kit_item(item, key_row == Some(k) || app.menu.submenu == Some(k)).show(ui);+ if item.enabled && ((row.hovered() && ctx.input(|i| i.pointer.delta() != Vec2::ZERO)) || row.clicked()) {+ if app.menu.submenu != Some(k) {+ app.menu.submenu_key = None;+ }+ app.menu.submenu = Some(k);+ }+ if app.menu.submenu == Some(k) {+ submenu_row = Some((k, row.rect));+ }}}});@@ -1740,6 +1776,41 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) {});inside |= resp.response.contains_pointer() || resp.response.rect.contains(pointer.unwrap_or(Pos2::ZERO));+ if let Some((k, row)) = submenu_row+ && let Some(parent) = list.get(k)+ {+ let enabled: Vec<_> = parent.children.iter().map(|i| i.enabled && !i.is_sep() && !i.is_heading()).collect();+ if had_submenu+ && crate::ui_kit::Menu::navigate(ctx, &enabled, &mut app.menu.submenu_key)+ && let Some(child) = app.menu.submenu_key.and_then(|r| parent.children.get(r))+ {+ picked = Some(child.clone());+ }+ let sub = crate::ui_kit::Menu::submenu(ctx, egui::Id::new("sc_context_submenu"), row, list_height(&parent.children), |ui| {+ egui::ScrollArea::vertical().max_height((screen.height() - 28.0).max(30.0)).show(ui, |ui| {+ for (n, child) in parent.children.iter().enumerate() {+ if child.is_sep() {+ crate::ui_kit::Menu::separator(ui);+ continue;+ }+ if child.is_heading() {+ crate::ui_kit::Menu::heading(ui, &child.label);+ continue;+ }+ // Child commands may share an id (swatches); preserve the parent handle+ // and publish a distinct identity for every adjacent submenu action.+ let handle = format!("{}:{}", child.id, child.label);+ let mut row = kit_item(child, app.menu.submenu_key == Some(n));+ row.id = &handle;+ if row.show(ui).clicked() && child.enabled {+ picked = Some(child.clone());+ }+ }+ });+ });+ inside |= sub.response.contains_pointer() || pointer.is_some_and(|p| sub.response.rect.contains(p));+ }+let (primary, secondary, esc) = ctx.input(|i| {(i.pointer.button_pressed(egui::PointerButton::Primary),@@ -1759,221 +1830,51 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) {}}-/// Workspace cards retain the context-menu items and dispatch, including keyboard and-/// control-channel picks. Only the presentation differs from ordinary command lists.-fn workspace_menu(ui: &mut egui::Ui, items: &[Item], key_row: Option<usize>, height: f32) -> Option<Item> {- let t = Tokens::get();- let mut picked = None;- egui::Frame::popup(ui.style()).fill(t.panel).stroke(Stroke::new(1.0, t.border)).corner_radius(10.0).inner_margin(9).show(ui, |ui| {- ui.set_width(450.0);- ui.spacing_mut().item_spacing.y = 0.0;- ui.add_space(4.0);- ui.label(- egui::RichText::new(crate::i18n::tr("ui.ribbon_workspace").to_uppercase())- .size(crate::theme::Tokens::get().font_small)- .semibold()- .color(t.text_dim),- );- ui.add_space(8.0);- egui::ScrollArea::vertical().id_salt("workspace_menu_rows").max_height((height - 116.0).max(60.0)).show(ui, |ui| {- for (k, item) in items.iter().enumerate() {- let (slug, description, tabs) = match item.label.as_str() {- "Design" => ("design", "ui.workspace_design_description", Some("ui.workspace_design_tabs")),- "Render" => ("render", "ui.workspace_render_description", Some("ui.workspace_render_tabs")),- "Animation" => ("animation", "ui.workspace_animation_description", None),- "Simulation" => ("simulation", "ui.workspace_simulation_description", None),- "Manufacture" => ("manufacture", "ui.workspace_manufacture_description", None),- "Drawing" => ("drawing", "ui.workspace_drawing_description", None),- _ => continue,- };- let planned = tabs.is_none();- let current = item.shortcut == "current";- let (accent, soft) = if !planned && slug == "render" {- (t.render_fill, t.render_soft)- } else {- let accent = if planned { t.text_dim } else { t.accent };- (accent, t.panel.lerp_to_gamma(accent, 0.10))- };- let (r, resp) = ui- .allocate_exact_size(vec2(450.0, if planned { 60.0 } else { 72.0 }), if item.enabled { Sense::click() } else { Sense::hover() });- for handle in [format!("menu:{}", item.id), format!("workspace:menu:{slug}")] {- crate::scenario::publish_target(&handle, r);- }- if current || (item.enabled && (resp.hovered() || key_row == Some(k))) {- ui.painter().rect_filled(r, 5.0, soft);- }- ui.painter().rect_filled(Rect::from_min_max(r.min + vec2(2.0, 7.0), pos2(r.left() + 6.0, r.bottom() - 7.0)), 2.0, accent);- let tile = Rect::from_center_size(pos2(r.left() + 40.0, r.center().y), vec2(44.0, 44.0));- ui.painter().rect_filled(tile, 9.0, if planned { t.panel_header } else { soft });- if !item.icon.is_empty() {- icons::paint_icon(ui.painter(), tile.shrink(7.0), &item.icon, if item.enabled { 1.0 } else { 0.35 });- }- let text = if item.enabled { t.text } else { t.text_dim };- let name = crate::i18n::tr_label(&item.label);- let x = r.left() + 74.0;- let y = r.top() + 17.0;- let galley = egui::WidgetText::from(egui::RichText::new(name).semibold().size(crate::theme::Tokens::get().font_heading).color(text))- .into_galley(ui, Some(egui::TextWrapMode::Extend), f32::INFINITY, egui::TextStyle::Button);- let badge_x = x + galley.size().x + 9.0;- let origin = pos2(x, y - galley.size().y / 2.0);- let ppp = ui.ctx().pixels_per_point().max(0.5);- let origin = pos2((origin.x * ppp).round() / ppp, (origin.y * ppp).round() / ppp);- ui.painter().galley(origin, galley, text);- let badge = crate::i18n::tr(if planned {- "ui.workspace_planned"- } else if current {- "ui.workspace_current"- } else {- "ui.workspace_available"- });- let badge = ui.painter().layout_no_wrap(- badge.to_string(),- FontId::proportional(crate::theme::Tokens::get().font_small),- if current { t.on_accent } else { accent },- );- let badge_rect = Rect::from_min_size(pos2(badge_x, y - 8.0), badge.size() + vec2(12.0, 3.0));- ui.painter().rect_filled(badge_rect, 8.0, if current { accent } else { soft });- ui.painter().galley(badge_rect.min + vec2(6.0, 1.5), badge, accent);- let line = |content: String, y: f32| {- let mut job =- egui::text::LayoutJob::simple_singleline(content, FontId::proportional(crate::theme::Tokens::get().font_body), text);- job.wrap.max_width = r.right() - x - 6.0;- job.wrap.max_rows = 1;- job.wrap.break_anywhere = false;- let galley = ui.painter().layout_job(job);- ui.painter().galley(pos2(x, y), galley, text);- };- line(crate::i18n::tr(description).to_string(), r.top() + 29.0);- if let Some(tabs) = tabs {- // Translate each tab even when this composed message falls back to English.- let labels = crate::i18n::tr(tabs).split('·').map(|label| crate::i18n::tr_label(label.trim())).collect::<Vec<_>>().join(" · ");- line(labels, r.top() + 47.0);- }- resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, item.enabled, name));- if resp.clicked() && item.enabled {- picked = Some(item.clone());- }- }- });- ui.add_space(6.0);- ui.separator();- ui.add_space(6.0);- ui.add(- egui::Label::new(- egui::RichText::new(crate::i18n::tr("ui.workspace_footer")).size(crate::theme::Tokens::get().font_small).color(t.text_dim),- )- .wrap(),- );- ui.add_space(4.0);- });- picked-}--/// The frame every menu uses.+/// Shared kit surface; legacy callers retain their menu positioning and dispatch.pub fn menu_frame<R>(ui: &mut egui::Ui, add: impl FnOnce(&mut egui::Ui) -> R) -> R {- let t = Tokens::get();- egui::Frame::new()- .fill(t.panel)- .stroke(Stroke::new(1.0, t.border))- .corner_radius(6.0)- .inner_margin(egui::Margin::symmetric(4, 4))- .shadow(egui::Shadow {- offset: [0, 3],- blur: 12,- spread: 0,- color: Color32::from_black_alpha(if crate::theme::is_dark() { 110 } else { 50 }),- })- .show(ui, |ui| {- ui.set_width(LIST_W - 10.0);- ui.spacing_mut().item_spacing.y = 0.0;- add(ui)- })- .inner+ crate::ui_kit::Menu::show(ui, LIST_W, add)}-/// A compact menu button with an explicit semantic icon, for native egui popup menus.pub fn button(ui: &mut egui::Ui, label: &str, icon: &str) -> egui::Response {button_enabled(ui, label, icon, true)}-/// The disabled form keeps its icon visible and dims it with the menu row.pub fn button_enabled(ui: &mut egui::Ui, label: &str, icon: &str, enabled: bool) -> egui::Response {- let response = ui- .add_enabled_ui(enabled, |ui| {- let icon_id = ui.id().with(("menu_icon", label));- let row = egui::Button::new((egui::Atom::custom(icon_id, vec2(16.0, 16.0)), label)).min_size(vec2(180.0, 22.0)).atom_ui(ui);- if let Some(rect) = row.rect(icon_id) {- icons::paint_icon(ui.painter(), rect, icon, if enabled { 1.0 } else { 0.35 });- }- row.response- })- .inner;- crate::scenario::publish_handle(&format!("menu:{label}"), response.rect.center());- response+ let mut item = crate::ui_kit::MenuItem::new(label, label, icon);+ item.enabled = enabled;+ item.show(ui)}-/// One list row; the item when it was clicked.pub fn list_row(ui: &mut egui::Ui, item: &Item) -> Option<Item> {list_row_lit(ui, item, false)}-/// A list row, drawn highlighted when `lit` (the keyboard's choice).pub fn list_row_lit(ui: &mut egui::Ui, item: &Item, lit: bool) -> Option<Item> {- let t = Tokens::get();- let w = LIST_W - 10.0;if item.is_sep() {- let (r, _) = ui.allocate_exact_size(vec2(w, 7.0), Sense::hover());- ui.painter().hline(r.x_range().shrink(6.0), r.center().y, Stroke::new(1.0, t.border));+ crate::ui_kit::Menu::separator(ui);return None;}if item.is_heading() {- let text = ui.painter().layout(- crate::i18n::tr_label(&item.label).to_uppercase(),- FontId::proportional(crate::theme::Tokens::get().font_panel),- t.text_dim,- w - 16.0,- );- let (r, _) = ui.allocate_exact_size(vec2(w, (text.size().y + 8.0).max(20.0)), Sense::hover());- ui.painter().galley(pos2(r.left() + 8.0, r.top() + 4.0), text, t.text_dim);+ crate::ui_kit::Menu::heading(ui, &item.label);return None;}- let (r, resp) = ui.allocate_exact_size(vec2(w, 24.0), if item.enabled { Sense::click() } else { Sense::hover() });- crate::scenario::publish_handle(&format!("menu:{}", item.id), r.center());- if item.enabled && (resp.hovered() || lit) {- ui.painter().rect_filled(r.shrink2(vec2(2.0, 1.0)), 4.0, t.hover);- }- let ink = if item.enabled { t.icon } else { t.border };- if !item.icon.is_empty() {- icons::paint(- ui.painter(),- Rect::from_center_size(pos2(r.left() + 16.0, r.center().y), vec2(16.0, 16.0)),- &item.icon,- ink,- t.icon_fill,- t.accent,- );- }- let text = if item.enabled { t.text } else { t.text_dim.gamma_multiply(0.75) };- let display_label = crate::i18n::tr_label(&item.label);- resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, item.enabled, display_label));- ui.painter().text(- pos2(r.left() + 32.0, r.center().y),- Align2::LEFT_CENTER,- display_label,- FontId::proportional(crate::theme::Tokens::get().font_button),- text,- );- if !item.shortcut.is_empty() {- let display_shortcut = crate::i18n::tr_label(&item.shortcut);- ui.painter().text(- pos2(r.right() - 10.0, r.center().y),- Align2::RIGHT_CENTER,- display_shortcut,- FontId::proportional(crate::theme::Tokens::get().font_caption),- t.text_dim,- );+ let row = kit_item(item, lit);+ (row.show(ui).clicked() && item.enabled).then(|| item.clone())+}++fn kit_item(item: &Item, lit: bool) -> crate::ui_kit::MenuItem<'_> {+ crate::ui_kit::MenuItem {+ id: &item.id,+ label: &item.label,+ icon: &item.icon,+ shortcut: if item.shortcut == "current" { "" } else { &item.shortcut },+ enabled: item.enabled,+ highlighted: lit,+ danger: item.icon == "delete",+ checked: (item.shortcut == "current").then_some(true),+ swatch: item.swatch.map(|c| Color32::from_rgb(c[0], c[1], c[2])),+ submenu: !item.children.is_empty(),}- (item.enabled && resp.clicked()).then(|| item.clone())}fn show_rename(app: &mut SolveApp, ctx: &egui::Context) {@@ -1983,31 +1884,9 @@ fn show_rename(app: &mut SolveApp, ctx: &egui::Context) {return;}let Some(mut r) = app.menu.rename.take() else { return };- let t = Tokens::get();let mut done: Option<bool> = None;let resp = crate::frame::area(egui::Id::new("sc_rename")).fixed_pos(r.at).constrain(true).order(egui::Order::Foreground).show(ctx, |ui| {- menu_frame(ui, |ui| {- ui.add_space(2.0);- ui.label(egui::RichText::new(crate::i18n::tr_label("Rename")).size(crate::theme::Tokens::get().font_small).color(t.text_dim));- let te = ui.add(egui::TextEdit::singleline(&mut r.text).desired_width(200.0).id(egui::Id::new("sc_rename_text")));- if !r.focused {- // Start with the whole name selected, ready to type over.- let id = egui::Id::new("sc_rename_text");- if let Some(mut st) = egui::TextEdit::load_state(ui.ctx(), id) {- let n = r.text.chars().count();- st.cursor.set_char_range(Some(egui::text::CCursorRange::two(egui::text::CCursor::new(0), egui::text::CCursor::new(n))));- st.store(ui.ctx(), id);- }- te.request_focus();- r.focused = true;- }- if te.lost_focus() {- done = Some(ui.input(|i| i.key_pressed(egui::Key::Enter)));- }- if ui.input(|i| i.key_pressed(egui::Key::Escape)) {- done = Some(false);- }- })+ done = crate::ui_kit::rename_menu(ui, &mut r.text, &mut r.focused);});if ctx.input(|i| i.pointer.any_pressed()) && !resp.response.contains_pointer() && r.focused {done = Some(true);@@ -2103,7 +1982,7 @@ mod tests {let p = list_place(c, 400.0, screen);let r = Rect::from_min_size(p, vec2(LIST_W, 400.0));assert!(screen.contains_rect(r), "{at:?}: {r:?}");- let ring = Rect::from_center_size(c, vec2(2.0 * (RX + 160.0), 2.0 * RY));+ let ring = Rect::from_center_size(c, vec2(2.0 * RX, 2.0 * RY));assert!(!ring.intersects(r), "{at:?}: list {r:?} over ring {ring:?}");}}@@ -2125,10 +2004,7 @@ mod tests {let screen = Rect::from_min_size(Pos2::ZERO, vec2(1200.0, 800.0));for at in [pos2(2.0, 2.0), pos2(1199.0, 799.0), pos2(600.0, 400.0), pos2(-50.0, 900.0)] {let c = radial_center(at, screen);- for k in 0..DIRS {- let r = slot_rect(c, k, vec2(160.0, 28.0));- assert!(screen.contains_rect(r), "{at:?} slot {k}: {r:?}");- }+ assert!(screen.contains_rect(Rect::from_center_size(c, vec2(2.0 * RX, 2.0 * RY))));}}}@@ -2144,7 +2020,7 @@ mod workspace_menu_tests {let app = SolveApp::new(Default::default(), Default::default());let list = items(&app, &Target::Workspace);let mut output = ctx.run_ui(egui::RawInput::default(), |ui| {- workspace_menu(ui, &list, None, 1000.0);+ crate::ui_kit::workspace_menu(ui, &list, None, 1000.0);});output.textures_delta.clear();let titles: Vec<_> = outputdiff --git a/crates/ui-egui/src/dialogs_appearance.rs b/crates/ui-egui/src/dialogs_appearance.rsindex acee40a301..5560a9d8d5 100644--- a/crates/ui-egui/src/dialogs_appearance.rs+++ b/crates/ui-egui/src/dialogs_appearance.rs@@ -25,7 +25,7 @@ pub struct Look {}/// Built-in looks, used until the engine offers a library (`appearance.library`).-fn builtin() -> Vec<Look> {+pub(crate) fn builtin() -> Vec<Look> {let l = |cat: &str, name: &str, c: [u8; 3], o: f64| Look { name: name.into(), category: cat.into(), color: c, opacity: o, pbr: None };vec![l("Metal", "Aluminum - Satin", [196, 199, 204], 1.0),diff --git a/crates/ui-egui/src/menu_tests.rs b/crates/ui-egui/src/menu_tests.rsindex f38dd17596..26830b3e5b 100644--- a/crates/ui-egui/src/menu_tests.rs+++ b/crates/ui-egui/src/menu_tests.rs@@ -853,3 +853,111 @@ fn contribution_unresolvable_face_does_not_edit_the_body_creator() {assert!(!find(&items, "Find in Timeline").enabled);assert!(!find(&items, "Find in Browser").enabled);}++#[test]+fn every_context_target_has_identified_icon_rows_including_submenus() {+ fn check(rows: &[Item]) {+ for row in rows {+ assert!(!row.id.is_empty(), "missing menu identity: {row:?}");+ let structural = row.id == "-" || row.id.starts_with('#');+ let planned = row.id == "ui.workspace" && row.shortcut == "coming later";+ assert!(structural || planned || !row.icon.is_empty(), "missing menu icon: {row:?}");+ if !row.icon.is_empty() {+ assert!(!crate::icon_svg::resolve(&row.icon).placeholder, "placeholder: {}", row.icon);+ }+ check(&row.children);+ }+ }+ let mut app = sample_app();+ let feature = app.session.doc.features[0].id;+ app.run("construct.plane.offset", json!({"base":"XY","offset":5})).unwrap();+ let plane = app.session.doc.features.last().unwrap().id;+ let part = app.run("component.create", json!({"name":"Menu part"})).unwrap()["component"].as_u64().unwrap();+ let occurrence = app.session.doc.occurrence_of(part).unwrap().id;+ let group_id = app.run("browser.group", json!({"component":0,"folder":"bodies","items":[body(&app)]})).unwrap()["group"].as_u64().unwrap();+ for target in [+ Target::Viewport,+ Target::Body { name: body(&app) },+ Target::Sketch { id: feature },+ Target::Plane { id: plane },+ Target::Feature { id: feature },+ Target::OriginPlane { name: "XY".into() },+ Target::Component { id: part },+ Target::Occurrence { path: vec![occurrence] },+ Target::Group { id: group_id, scope: "c0".into() },+ Target::Origin,+ Target::Units,+ Target::ToolbarCommand { id: "solid.extrude".into() },+ Target::Toolbar,+ Target::Workspace,+ Target::NamedViews,+ Target::NamedView { name: "Top".into() },+ Target::Canvas { id: 1 },+ Target::Section,+ Target::Folder { component: 0, folder: "bodies".into(), scope: "c0".into() },+ ] {+ let rows = context_menu::items(&app, &target);+ assert!(!rows.is_empty(), "unexercised target: {target:?}");+ check(&rows);+ }+ let sample = solidcraft_engine::sample::samples().into_iter().find(|s| s.name == "Hinge Assembly").unwrap();+ let mut assembly = SolveApp::new(Session::default(), Services::default());+ assembly.session.run_script(&(sample.script)()).unwrap();+ assert!(!assembly.session.doc.assembly.joints.is_empty());+ for joint in &assembly.session.doc.assembly.joints {+ let rows = context_menu::items(&assembly, &Target::Joint { id: joint.id });+ assert!(!rows.is_empty());+ check(&rows);+ }+ check(&context_menu::radial_items(&app));+}++#[test]+fn appearance_submenu_swatches_apply_to_the_clicked_body_and_keep_library_action() {+ let mut app = sample_app();+ let name = body(&app);+ let rows = context_menu::items(&app, &Target::Body { name: name.clone() });+ let appearance = find(&rows, "Appearance");+ assert_eq!(appearance.children[0].id, "ui.appearance");+ assert_eq!(appearance.children[0].params, appearance.params);+ let swatch = appearance.children.iter().find(|row| row.swatch.is_some()).unwrap();+ context_menu::run_item(&mut app, swatch, pos2(0.0, 0.0));+ assert_eq!(app.session.doc.appearances.bodies[&name].color, swatch.swatch.unwrap());+}++#[test]+fn appearance_submenu_keyboard_opens_beside_parent_and_left_returns_to_it() {+ use crate::scenario::{Harness, rect_of};+ let mut h = Harness::new();+ h.app = sample_app();+ h.frames(3);+ let target = Target::Body { name: body(&h.app) };+ let rows = context_menu::items(&h.app, &target);+ context_menu::open_for(&mut h.app, pos2(400.0, 180.0), target);+ let index = rows.iter().position(|i| i.id == "ui.appearance").unwrap();+ h.app.menu.key_row = Some(index);+ h.frames(2);+ h.step(&json!({"key":"ArrowRight"})).unwrap();+ let parent = rect_of("menu:ui.appearance").unwrap();+ let child = rect_of("menu:appearance.assign:Aluminum - Satin").unwrap();+ assert!(child.left() >= parent.right() || child.right() <= parent.left(), "submenu overlaps parent: {parent:?}, {child:?}");+ assert!(h.app.dialog.is_none(), "opening submenu must not execute its first child");+ h.step(&json!({"key":"ArrowLeft"})).unwrap();+ h.frames(2);+ assert!(rect_of("menu:appearance.assign:Aluminum - Satin").is_none(), "Left closes the submenu");+ h.step(&json!({"key":"Escape"})).unwrap();+ assert!(h.app.viewport.context_menu.is_none());+}++#[test]+fn narrow_overflow_submenu_keeps_opening_click_and_accepts_the_next_click() {+ use crate::scenario::Harness;+ let mut h = Harness::new();+ h.call("ui.resize", json!({"width":200,"height":800}));+ h.step(&json!({"click":{"handle":"toolbar:overflow"}})).unwrap();+ h.step(&json!({"widget":"CREATE"})).unwrap();+ assert!(h.app.dialog.is_none(), "opening a submenu must not run Extrude beneath its opener");+ assert!(crate::scenario::handle_at("toolbar:solid.extrude").is_some());+ h.step(&json!({"click":{"handle":"toolbar:solid.extrude"}})).unwrap();+ assert!(matches!(h.app.dialog.as_ref().map(|d| &d.kind), Some(crate::dialogs::Kind::Extrude { .. })));+}diff --git a/crates/ui-egui/src/timeline.rs b/crates/ui-egui/src/timeline.rsindex 3cd106f06b..1303b71711 100644--- a/crates/ui-egui/src/timeline.rs+++ b/crates/ui-egui/src/timeline.rs@@ -448,7 +448,7 @@ fn timeline_contents(app: &mut SolveApp, ui: &mut egui::Ui, floating: bool) {edit = Some(*id);}let sketch_of = kind.profile_sketch();- resp.context_menu(|ui| {+ crate::ui_kit::Menu::context(&resp, |ui| {if crate::context_menu::button(ui, crate::i18n::tr_label("Edit Feature"), "edit").clicked() {edit = Some(*id);ui.close();diff --git a/crates/ui-egui/src/timeline_left.rs b/crates/ui-egui/src/timeline_left.rsindex bdb8e2db1d..8a6c845941 100644--- a/crates/ui-egui/src/timeline_left.rs+++ b/crates/ui-egui/src/timeline_left.rs@@ -82,7 +82,7 @@ pub fn left_timeline(app: &mut SolveApp, ui: &mut egui::Ui) {ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {let count = selected_feature_ids(app).len() + app.tree.picked_timeline_groups.len();if count > 0 {- ui.menu_button(format!("{count} selected"), |ui| selection_actions(app, ui, &groups));+ crate::ui_kit::Menu::button(ui, format!("{count} selected"), |ui| selection_actions(app, ui, &groups));}});});@@ -600,7 +600,7 @@ fn vertical_group_row(if response.secondary_clicked() && !selected {select_only(app, TimelineItem::Group(group.id));}- response.context_menu(|ui| {+ crate::ui_kit::Menu::context(&response, |ui| {if crate::context_menu::button(ui, "Rename Folder", "rename").clicked() {crate::context_menu::start_rename(app, crate::context_menu::RenameWhat::TimelineGroup(group.id), rect.center());ui.close();@@ -775,7 +775,7 @@ fn vertical_features(app: &mut SolveApp, ui: &mut egui::Ui) {if response.secondary_clicked() && !selected {select_only(app, TimelineItem::Feature(*id));}- response.context_menu(|ui| {+ crate::ui_kit::Menu::context(&response, |ui| {if crate::context_menu::button(ui, "Edit Feature", "edit").clicked() {edit = Some(*id);ui.close();diff --git a/crates/ui-egui/src/toolbar.rs b/crates/ui-egui/src/toolbar.rsindex 849a91b39c..9f317a9d3c 100644--- a/crates/ui-egui/src/toolbar.rs+++ b/crates/ui-egui/src/toolbar.rs@@ -478,7 +478,7 @@ fn file_menu(app: &mut SolveApp, ctx: &egui::Context) {.fixed_pos(pos2(ctx.data(|d| d.get_temp::<f32>(egui::Id::new("sc_file_menu_x"))).unwrap_or(100.0), APP_BAR_HEIGHT)).order(egui::Order::Foreground).show(ctx, |ui| {- egui::Frame::popup(ui.style()).show(ui, |ui| {+ crate::ui_kit::Menu::frame().show(ui, |ui| {ui.set_min_width(190.0);ui.visuals_mut().widgets.inactive.weak_bg_fill = Color32::TRANSPARENT;ui.visuals_mut().widgets.inactive.bg_stroke = Stroke::NONE;@@ -501,7 +501,7 @@ fn file_menu(app: &mut SolveApp, ctx: &egui::Context) {});close = true;}- ui.menu_button(app.tr("ui.open_recent"), |ui| {+ crate::ui_kit::Menu::button(ui, app.tr("ui.open_recent"), |ui| {for path in app.home.recent.clone() {let missing = !solidcraft_engine::io::vfs::exists(&path);let label = format!("{path}{}", if missing { " (missing)" } else { "" });@@ -1369,9 +1369,9 @@ pub fn toolbar(app: &mut SolveApp, ui: &mut egui::Ui) {if !overflow.is_empty() {let at = Rect::from_min_size(pos2(px.min(right - finish_width - 40.0), top + 4.0), vec2(38.0, BUTTON_HEIGHT));ui.scope_builder(egui::UiBuilder::new().max_rect(at), |ui| {- let response = ui.menu_button("»", |ui| {+ let response = crate::ui_kit::Menu::button(ui, "»", |ui| {for (panel, cmds) in &overflow {- ui.menu_button(*panel, |ui| {+ crate::ui_kit::Menu::button(ui, *panel, |ui| {if tab == "SKETCH" && *panel == "CREATE" {sketch_create_menu(app, ui, cmds, &mut menu, &mut toggle);return;@@ -1553,9 +1553,8 @@ fn ribbon_tooltip(app: &SolveApp, response: egui::Response, command: &solidcraft})}-fn section_frame(ui: &egui::Ui) -> egui::Frame {- let t = Tokens::get();- egui::Frame::popup(ui.style()).fill(t.panel).stroke(Stroke::new(1.0, t.border)).corner_radius(8.0)+fn section_frame(_ui: &egui::Ui) -> egui::Frame {+ crate::ui_kit::Menu::frame()}fn section_heading(ui: &mut egui::Ui, label: &str, width: f32) {@@ -1629,24 +1628,15 @@ fn dropdown_row(app: &SolveApp, ui: &mut egui::Ui, c: &'static solidcraft_enginecrate::scenario::publish_handle(&format!("toolbar:{}", c.id), rect.center());crate::scenario::publish_handle(&format!("dropdown:{}", c.id), rect.center());let hot = info.enabled && (pointer_on || resp.has_focus());- let p = ui.painter();+ let mut row = crate::ui_kit::MenuItem::new(c.id, &label, c.icon);+ row.enabled = info.enabled;+ row.highlighted = hot;+ row.shortcut = c.shortcut.unwrap_or("");+ row.paint(ui, rect, &resp, 26.0);if hot {- p.rect_filled(rect, 3.0, t.hover);crate::scenario::publish_handle(&format!("dropdown_hot:{}", c.id), rect.center());}- // The icon keeps its semantic accent in a drop-down as well as on the ribbon.- let (ink, fill, acc, text) = if info.enabled {- let acc = command_accent(c.icon);- (t.icon, t.icon_fill, acc, t.text)- } else {- (t.border, t.panel_header, t.border, t.text_dim)- };- let ir = Rect::from_center_size(pos2(rect.left() + 6.0 + 10.0, rect.center().y), vec2(20.0, 20.0));- icons::paint(p, ir, c.icon, ink, fill, acc);- p.text(pos2(ir.right() + 8.0, rect.center().y), Align2::LEFT_CENTER, &label, FontId::proportional(t.font_button), text);- if let Some(k) = c.shortcut {- p.text(pos2(pr.left() - 4.0, rect.center().y), Align2::RIGHT_CENTER, k, FontId::monospace(t.font_button), t.text_dim);- }+ let p = ui.painter();if pointer_on || resp.has_focus() {if pin.hovered() {p.rect_filled(pr, 3.0, t.border.gamma_multiply(0.6));@@ -1684,7 +1674,7 @@ fn sketch_create_menu(for f in crate::sketch_families::FAMILIES {let variants: Vec<_> = f.commands.iter().filter_map(|id| cmds.iter().find(|c| c.id == *id).copied()).collect();if !variants.is_empty() {- let response = ui.menu_button(app.tr_label(f.label).to_string(), |ui| {+ let response = crate::ui_kit::Menu::button(ui, app.tr_label(f.label).to_string(), |ui| {dropdown_keys(app, ui, &variants);sketch_menu_rows(app, ui, &variants, menu, toggle);});diff --git a/crates/ui-egui/src/ui_kit/actions.rs b/crates/ui-egui/src/ui_kit/actions.rsindex 6a2fc22468..2d79c0d440 100644--- a/crates/ui-egui/src/ui_kit/actions.rs+++ b/crates/ui-egui/src/ui_kit/actions.rs@@ -291,7 +291,7 @@ fn publish_button(ui: &Ui, response: &Response, label: &str) {/// Nested action menu in a dense table. Tokens: scope control/font tokens.pub(crate) fn action_menu<R>(ui: &mut Ui, label: &str, add: impl FnOnce(&mut Ui) -> R) -> egui::InnerResponse<Option<R>> {- let response = ui.menu_button(crate::i18n::tr_label(label), |ui| super::scope(ui, add));+ let response = super::Menu::button(ui, crate::i18n::tr_label(label), |ui| super::scope(ui, add));scenario::publish_target(&format!("dialog:menu:{label}"), response.response.rect);response}@@ -374,17 +374,11 @@ pub(crate) fn icon_label_button(ui: &mut Ui, label: &str, icon: &str, enabled: bresponse}-/// Ribbon overflow action; keeps its native atom identity, shortcut, accessibility and behaviour.-/// Tokens: space_16 and the existing icon palette; button chrome inherits the menu style.+/// Ribbon overflow action on the shared menu row, retaining shortcut, accessibility and enabled state.+/// Tokens: MenuItem's typography, spacing and semantic icon palette.pub(crate) fn command_menu_button(ui: &mut Ui, id: &str, label: &str, icon: &str, shortcut: &str, enabled: bool) -> Response {- ui.add_enabled_ui(enabled, |ui| {- let atom = ui.id().with(("overflow_icon", id));- let side = Tokens::get().space_16;- let row = egui::Button::new((egui::Atom::custom(atom, vec2(side, side)), label)).shortcut_text(shortcut).atom_ui(ui);- if let Some(rect) = row.rect(atom) {- crate::icons::paint_icon(ui.painter(), rect, icon, if enabled { 1.0 } else { 0.35 });- }- row.response- })- .inner+ let mut item = super::MenuItem::new(id, label, icon);+ item.shortcut = shortcut;+ item.enabled = enabled;+ item.show(ui)}diff --git a/crates/ui-egui/src/ui_kit/checks.rs b/crates/ui-egui/src/ui_kit/checks.rsindex 7dfd005114..bb42827e46 100644--- a/crates/ui-egui/src/ui_kit/checks.rs+++ b/crates/ui-egui/src/ui_kit/checks.rs@@ -11,7 +11,7 @@ pub(super) fn box_at(ui: &Ui, center: egui::Pos2) -> Rect {}/// One path for every tick, including menu rows. Mixed state uses a horizontal bar.-fn paint_check_glyph(painter: &egui::Painter, square: Rect, mixed: bool, ink: egui::Color32) {+pub(super) fn paint_check_glyph(painter: &egui::Painter, square: Rect, mixed: bool, ink: egui::Color32) {let t = Tokens::get();let mark = square.shrink(t.space_3);let points = if mixed { vec![mark.left_center(), mark.right_center()] } else { vec![mark.left_center(), mark.center_bottom(), mark.right_top()] };@@ -76,4 +76,4 @@ pub(crate) fn checkbox_indeterminate(ui: &mut Ui, label: &str, value: &mut bool,#[cfg(test)]#[path = "checks_tests.rs"]-mod tests;+pub(super) mod tests;diff --git a/crates/ui-egui/src/ui_kit/checks_tests.rs b/crates/ui-egui/src/ui_kit/checks_tests.rsindex 58ad821dfb..d985964a64 100644--- a/crates/ui-egui/src/ui_kit/checks_tests.rs+++ b/crates/ui-egui/src/ui_kit/checks_tests.rs@@ -76,7 +76,7 @@ fn checkbox_shapes(output: &egui::FullOutput) -> Vec<(Rect, Vec<egui::epaint::Cl/// Small CPU rasteriser for egui's actual tessellated triangles, including the font/icon atlas./// This keeps screenshots and pixel comparisons deterministic without requiring a display/GPU.-fn raster(+pub(crate) fn raster(ctx: &egui::Context,mut shapes: Vec<egui::epaint::ClippedShape>,ppp: f32,@@ -162,7 +162,7 @@ fn raster(pixels}-fn textures_update(textures: &mut HashMap<egui::TextureId, egui::ColorImage>, delta: &egui::TexturesDelta) {+pub(crate) fn textures_update(textures: &mut HashMap<egui::TextureId, egui::ColorImage>, delta: &egui::TexturesDelta) {for (id, deltas) in &delta.set {for delta in deltas {let egui::ImageData::Color(image) = &delta.image;diff --git a/crates/ui-egui/src/ui_kit/fields.rs b/crates/ui-egui/src/ui_kit/fields.rsindex 0adde22231..2c4b832b6d 100644--- a/crates/ui-egui/src/ui_kit/fields.rs+++ b/crates/ui-egui/src/ui_kit/fields.rs@@ -9,7 +9,7 @@ use egui::{Response, RichText, Ui, vec2};/// One alignment policy for every kit text input. Align the galley itself rather than/// approximating font metrics with integer margins (Plex Mono and Sans differ).-fn text_input(edit: egui::TextEdit<'_>) -> egui::TextEdit<'_> {+pub(super) fn text_input(edit: egui::TextEdit<'_>) -> egui::TextEdit<'_> {let t = Tokens::get();edit.vertical_align(egui::Align::Center).margin(vec2(t.form_inset, 0.0)).min_size(vec2(0.0, t.control_height))}diff --git a/crates/ui-egui/src/ui_kit/gallery.rs b/crates/ui-egui/src/ui_kit/gallery.rsindex 2ee64c1e7c..68f98238ce 100644--- a/crates/ui-egui/src/ui_kit/gallery.rs+++ b/crates/ui-egui/src/ui_kit/gallery.rs@@ -28,6 +28,66 @@ macro_rules! element {// One entry per element/variant: names, rendering and geometry expectations stay together.const ELEMENTS: &[Element] = &[+ element!("menu", |ui, _| {+ Menu::show(ui, 268.0, |ui| {+ Menu::heading(ui, "Body");+ MenuItem::new("gallery:normal", "Properties", "measure").show(ui);+ let mut item = MenuItem::new("gallery:hover", "Hide", "eye");+ item.highlighted = true;+ item.shortcut = "H";+ item.show(ui);+ item = MenuItem::new("gallery:open", "Appearance", "appearance");+ item.submenu = true;+ item.highlighted = true;+ item.show(ui);+ item = MenuItem::new("gallery:disabled", "Paste", "paste");+ item.enabled = false;+ item.shortcut = "Ctrl+V";+ item.show(ui);+ item = MenuItem::new("gallery:checked", "Show Origin", "origin");+ item.checked = Some(true);+ item.show(ui);+ item.checked = Some(false);+ item.id = "gallery:unchecked";+ item.show(ui);+ item = MenuItem::new("gallery:swatch", "Aluminum - Satin", "appearance");+ item.swatch = Some(Tokens::get().control_border);+ item.show(ui);+ Menu::separator(ui);+ item = MenuItem::new("gallery:danger", "Delete", "delete");+ item.danger = true;+ item.shortcut = "Del";+ item.show(ui);+ });+ }),+ element!("menu_submenu", |ui, _| {+ ui.horizontal_top(|ui| {+ Menu::show(ui, 244.0, |ui| {+ let mut item = MenuItem::new("parent", "Appearance", "appearance");+ item.submenu = true;+ item.highlighted = true;+ item.show(ui);+ });+ Menu::show(ui, 236.0, |ui| {+ Menu::heading(ui, "Appearance");+ let mut item = MenuItem::new("look", "Aluminum - Satin", "appearance");+ item.swatch = Some(Tokens::get().control_border);+ item.show(ui);+ });+ });+ }),+ element!("rename_menu", |ui, s| {+ rename_menu(ui, &mut s.value, &mut false);+ }),+ element!("radial_menu", |ui, _| {+ let (r, _) = ui.allocate_exact_size(vec2(360.0, 360.0), egui::Sense::hover());+ let app = crate::test_support::sample_app();+ radial_menu(ui, r.center(), &crate::context_menu::radial_items(&app), Some(3));+ }),+ element!("workspace_menu", |ui, _| {+ let app = crate::test_support::sample_app();+ workspace_menu(ui, &crate::context_menu::items(&app, &crate::context_menu::Target::Workspace), None, 550.0);+ }),element!("window", "dialog:footer", Some("dialog:ok"), |ui, _| {Window::new(ui.id().with("window"), "settings", "Preferences").content(ui,@@ -622,6 +682,11 @@ const ELEMENTS: &[Element] = &[fn example(ui: &mut Ui, element: &Element) -> (&'static str, Option<&'static str>) {let mut sample = Sample { value: "12 mm".into(), second: "25 mm".into(), selected: 0, checked: true };let rect = ui.scope(|ui| (element.draw)(ui, &mut sample)).response.rect;+ if matches!(element.name, "menu" | "menu_submenu" | "rename_menu" | "workspace_menu") {+ // A popup's elevation is painted outside its layout rectangle. Reserve those+ // actual shadow bounds as part of the gallery sample, keeping the paint guard strict.+ ui.expand_to_include_rect(rect + Menu::frame().shadow.margin());+ }scenario::publish_rect("gallery:allocation", rect);(element.rect, element.handle)}@@ -951,7 +1016,9 @@ fn gallery_covers_every_inline_element() {"disclosure.rs","fields.rs","layout.rs",+ "menu.rs","metrics.rs",+ "radial.rs","reports.rs","status.rs","table.rs",@@ -971,3 +1038,46 @@ fn gallery_covers_every_inline_element() {}}}++/// Render actual egui geometry without a desktop window. Opt-in PNGs are reviewer evidence.+#[test]+fn menu_board_in_both_themes() {+ use super::checks::tests::{raster, textures_update};+ use std::collections::HashMap;+ let previous = crate::theme::is_dark();+ for dark in [false, true] {+ crate::theme::set_dark(dark);+ let ctx = crate::fonts::test_context();+ ctx.set_visuals(if dark { egui::Visuals::dark() } else { egui::Visuals::light() });+ let mut textures = HashMap::new();+ let bounds = egui::Rect::from_min_size(egui::Pos2::ZERO, vec2(1100.0, 760.0));+ let mut app = crate::test_support::sample_app();+ app.last_command = Some(("solid.extrude".into(), "Extrude".into()));+ let items = crate::context_menu::radial_items(&app);+ let mut image = None;+ for _ in 0..3 {+ let mut output = ctx.run_ui(egui::RawInput { screen_rect: Some(bounds), ..Default::default() }, |ui| {+ ui.painter().rect_filled(bounds, 0.0, Tokens::get().panel);+ for (name, at) in+ [("menu", egui::pos2(30.0, 30.0)), ("menu_submenu", egui::pos2(30.0, 430.0)), ("rename_menu", egui::pos2(630.0, 430.0))]+ {+ ui.scope_builder(egui::UiBuilder::new().max_rect(egui::Rect::from_min_size(at, vec2(550.0, 350.0))), |ui| {+ example(ui, ELEMENTS.iter().find(|e| e.name == name).unwrap());+ });+ }+ ui.allocate_rect(egui::Rect::from_min_size(egui::pos2(630.0, 30.0), vec2(360.0, 360.0)), egui::Sense::hover());+ radial_menu(ui, egui::pos2(810.0, 210.0), &items, Some(3));+ });+ textures_update(&mut textures, &output.textures_delta);+ output.textures_delta.clear();+ image = Some(raster(&ctx, output.shapes, output.pixels_per_point, bounds, &textures));+ }+ let image = image.unwrap();+ assert!(image.pixels().any(|p| p.0[3] != 0));+ if let Ok(dir) = std::env::var("SOLIDCRAFT_MENU_EVIDENCE") {+ std::fs::create_dir_all(&dir).unwrap();+ image.save(std::path::Path::new(&dir).join(if dark { "menus-dark.png" } else { "menus-light.png" })).unwrap();+ }+ }+ crate::theme::set_dark(previous);+}diff --git a/crates/ui-egui/src/ui_kit/menu.rs b/crates/ui-egui/src/ui_kit/menu.rsnew file mode 100644index 0000000000..6b9806bcb0--- /dev/null+++ b/crates/ui-egui/src/ui_kit/menu.rs@@ -0,0 +1,438 @@+//! Menus share one popup surface and one row painter. Command dispatch stays with callers.+use crate::{context_menu::Item, fonts::RichTextExt as _, icons, theme::Tokens};+use egui::{Color32, FontId, Rect, Response, Sense, Stroke, Ui, pos2, vec2};++pub(crate) struct Menu;++impl Menu {+ pub(crate) fn context<R>(response: &Response, add: impl FnOnce(&mut Ui) -> R) -> Option<egui::InnerResponse<R>> {+ egui::Popup::context_menu(response).frame(Self::frame()).show(add)+ }++ pub(crate) fn button<R>(ui: &mut Ui, label: impl Into<egui::WidgetText>, add: impl FnOnce(&mut Ui) -> R) -> egui::InnerResponse<Option<R>> {+ let previous = ui.style().clone();+ let frame = Self::frame();+ let style = ui.style_mut();+ style.spacing.menu_margin = frame.inner_margin;+ style.visuals.menu_corner_radius = frame.corner_radius;+ style.visuals.popup_shadow = frame.shadow;+ style.visuals.window_fill = frame.fill;+ style.visuals.window_stroke = frame.stroke;+ let nested = egui::menu::is_in_menu(ui);+ let button = egui::Button::new(label.into());+ let response = ui.add(if nested { button.right_text(egui::menu::SubMenuButton::RIGHT_ARROW) } else { button });+ let popup_id = if nested { egui::menu::SubMenu::id_from_widget_id(response.id) } else { egui::Popup::default_response_id(&response) };+ let was_open = ui.ctx().read_response(popup_id).is_some();+ let gate_id = popup_id.with("opening_click");+ let first_click = !was_open || ui.ctx().data(|d| d.get_temp::<bool>(gate_id)).unwrap_or(true);+ let (opening_press, released) = ui.input(|i| {+ (+ first_click+ && (i.pointer.any_down() || i.pointer.any_released())+ && i.pointer.press_origin().or_else(|| i.pointer.interact_pos()).is_some_and(|p| response.rect.contains(p)),+ i.pointer.any_released(),+ )+ });+ let content = |ui: &mut Ui| {+ ui.spacing_mut().item_spacing.y = 0.0;+ // The opening gesture belongs to the parent even when a narrow popup overlaps it.+ ui.ctx().data_mut(|d| d.insert_temp(gate_id, first_click && !released));+ ui.add_enabled_ui(!opening_press, add).inner+ };+ let popup = if nested {+ let submenu = egui::menu::SubMenu::new();+ let submenu = if opening_press {+ submenu.config(egui::menu::MenuConfig::new().close_behavior(egui::PopupCloseBehavior::CloseOnClickOutside))+ } else {+ submenu+ };+ submenu.show(ui, &response, content)+ } else {+ egui::Popup::menu(&response).frame(frame).show(content)+ };+ let response = egui::InnerResponse { response, inner: popup.map(|r| r.inner) };+ ui.set_style(previous);+ response+ }++ pub(crate) fn frame() -> egui::Frame {+ let t = Tokens::get();+ egui::Frame::NONE+ .fill(t.dialog_body)+ .stroke(Stroke::new(1.0, t.dialog_border))+ .corner_radius(t.radius_xl)+ .inner_margin(egui::Margin::symmetric(t.space_6 as i8, t.space_6 as i8))+ .shadow(egui::Shadow {+ offset: [0, t.space_14 as i8],+ blur: (t.space_24 + t.space_12) as u8,+ spread: 0,+ color: t.app_bar.gamma_multiply(0.18),+ })+ }++ pub(crate) fn show<R>(ui: &mut Ui, width: f32, add: impl FnOnce(&mut Ui) -> R) -> R {+ Self::frame()+ .show(ui, |ui| {+ ui.set_width((width - Tokens::get().space_6 * 2.0 - 2.0).max(0.0));+ ui.spacing_mut().item_spacing.y = 0.0;+ ui.with_layout(egui::Layout::top_down(egui::Align::Min), add).inner+ })+ .inner+ }++ pub(crate) fn separator(ui: &mut Ui) {+ let t = Tokens::get();+ let (r, _) = ui.allocate_exact_size(vec2(ui.available_width(), t.space_10 + 1.0), Sense::hover());+ ui.painter().hline(r.x_range(), r.center().y, Stroke::new(1.0, t.dialog_rule));+ }++ pub(crate) fn heading(ui: &mut Ui, label: &str) {+ let t = Tokens::get();+ let (r, _) = ui.allocate_exact_size(vec2(ui.available_width(), t.space_24), Sense::hover());+ let mut job =+ egui::text::LayoutJob::simple_singleline(crate::i18n::tr_label(label).to_uppercase(), crate::fonts::semibold(t.font_small), t.form_dim);+ for section in &mut job.sections {+ section.format.extra_letter_spacing = t.font_small * t.font_section_tracking;+ }+ let galley = ui.painter().layout_job(job);+ ui.painter().galley(pos2(r.left() + t.space_8, r.center().y - galley.size().y / 2.0), galley, t.form_dim);+ }++ /// Bounded keyboard navigation skips disabled entries and structural rows.+ pub(crate) fn navigate(ctx: &egui::Context, enabled: &[bool], selected: &mut Option<usize>) -> bool {+ let (up, down, enter) =+ ctx.input(|i| (i.key_pressed(egui::Key::ArrowUp), i.key_pressed(egui::Key::ArrowDown), i.key_pressed(egui::Key::Enter)));+ let usable: Vec<_> = enabled.iter().enumerate().filter_map(|(k, on)| on.then_some(k)).collect();+ if up || down {+ let at = selected.and_then(|r| usable.iter().position(|u| *u == r));+ let len = usable.len().max(1);+ let next = match (at, down) {+ (None, true) => 0,+ (None, false) => len - 1,+ (Some(k), true) => (k + 1) % len,+ (Some(k), false) => (k + len - 1) % len,+ };+ *selected = usable.get(next).copied();+ }+ enter && selected.is_some_and(|k| enabled.get(k).copied().unwrap_or(false))+ }++ /// Place a submenu beside its row, flipping at the screen edge.+ pub(crate) fn submenu<R>(ctx: &egui::Context, id: egui::Id, row: Rect, height: f32, add: impl FnOnce(&mut Ui) -> R) -> egui::InnerResponse<R> {+ let screen = ctx.content_rect();+ let width = crate::context_menu::LIST_W;+ let x = if row.right() + width <= screen.right() { row.right() } else { (row.left() - width).max(screen.left()) };+ let at = pos2(x, row.top().min((screen.bottom() - height).max(screen.top())));+ crate::frame::area(id).fixed_pos(at).order(egui::Order::Foreground).show(ctx, |ui| Self::show(ui, width, add))+ }+}++/// Shared row states. Swatches are document colour data; chrome always uses Tokens.+pub(crate) struct MenuItem<'a> {+ pub id: &'a str,+ pub label: &'a str,+ pub icon: &'a str,+ pub shortcut: &'a str,+ pub enabled: bool,+ pub highlighted: bool,+ pub checked: Option<bool>,+ pub swatch: Option<Color32>,+ pub danger: bool,+ pub submenu: bool,+}++impl<'a> MenuItem<'a> {+ pub(crate) fn new(id: &'a str, label: &'a str, icon: &'a str) -> Self {+ Self { id, label, icon, shortcut: "", enabled: true, highlighted: false, checked: None, swatch: None, danger: false, submenu: false }+ }++ pub(crate) fn show(&self, ui: &mut Ui) -> Response {+ let t = Tokens::get();+ // Areas first measure intrinsic content. Filling their provisional available+ // width would make a flipped submenu cover its parent and consume the opening click.+ let width = if ui.is_sizing_pass() {+ let label = ui.painter().layout_no_wrap(crate::i18n::tr_label(self.label).to_string(), FontId::proportional(t.font_label), t.form_ink);+ let shortcut = ui.painter().layout_no_wrap(self.shortcut.to_string(), FontId::monospace(t.font_small), t.form_dim);+ let trailing = if self.submenu { t.space_16 } else { 0.0 };+ (t.control_height + t.space_2 + label.size().x + shortcut.size().x + t.space_24 + trailing).min(ui.available_width())+ } else {+ ui.available_width()+ };+ let (r, response) =+ ui.allocate_exact_size(vec2(width, t.control_height + t.space_2), if self.enabled { Sense::click() } else { Sense::hover() });+ self.paint(ui, r, &response, 0.0);+ response+ }++ /// Ribbon rows retain their own drag/focus IDs and reserve a trailing pin target.+ pub(crate) fn paint(&self, ui: &Ui, r: Rect, response: &Response, trailing: f32) {+ let t = Tokens::get();+ let enabled = self.enabled && ui.is_enabled();+ let hot = enabled && (self.highlighted || response.hovered() || response.has_focus());+ let ink = if self.danger {+ t.form_error+ } else if hot {+ t.form_primary+ } else {+ t.form_ink+ };+ let dim = if self.danger {+ t.form_error+ } else if hot {+ t.form_primary+ } else {+ t.form_dim+ };+ let painter = ui.painter().with_clip_rect(ui.clip_rect().intersect(r));+ let mut painter = painter;+ if !enabled {+ painter.multiply_opacity(0.4);+ }+ if hot {+ painter.rect_filled(r, t.control_radius, t.accent_soft);+ }+ let icon = Rect::from_center_size(pos2(r.left() + t.control_height / 2.0, r.center().y), vec2(t.space_16, t.space_16));+ if let Some(on) = self.checked {+ if on {+ super::checks::paint_check_glyph(&painter, icon, false, t.form_primary);+ }+ } else if let Some(color) = self.swatch {+ painter.rect(icon, t.radius_sm, color, Stroke::new(1.0, t.control_border), egui::StrokeKind::Inside);+ } else if !self.icon.is_empty() {+ if self.danger || hot {+ icons::paint_ink(&painter, icon, self.icon, dim);+ } else {+ icons::paint_icon(&painter, icon, self.icon, 1.0);+ }+ }+ let label = crate::i18n::tr_label(self.label);+ let mut right = r.right() - t.space_8 - trailing;+ if self.submenu {+ let c = pos2(right - t.space_4, r.center().y);+ painter.add(egui::Shape::line(+ vec![c + vec2(-t.space_2, -t.space_4), c + vec2(t.space_2, 0.0), c + vec2(-t.space_2, t.space_4)],+ Stroke::new(1.0, dim),+ ));+ right -= t.space_16;+ }+ if !self.shortcut.is_empty() {+ let key = painter.layout_no_wrap(crate::i18n::tr_label(self.shortcut).to_string(), FontId::monospace(t.font_small), dim);+ painter.galley(pos2(right - key.size().x, r.center().y - key.size().y / 2.0), key.clone(), dim);+ right -= key.size().x + t.space_8;+ }+ let left = r.left() + t.control_height + t.space_2;+ let mut job = egui::text::LayoutJob::simple_singleline(label.to_string(), FontId::proportional(t.font_label), ink);+ job.wrap.max_width = (right - left).max(0.0);+ job.wrap.max_rows = 1;+ let galley = painter.layout_job(job);+ painter.galley(pos2(left, r.center().y - galley.size().y / 2.0), galley, ink);+ response.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, enabled, label));+ crate::scenario::publish_target(&format!("menu:{}", self.id), r);+ if enabled && response.hovered() {+ ui.ctx().set_cursor_icon(egui::CursorIcon::PointingHand);+ }+ }+}++pub(crate) fn workspace_menu(ui: &mut egui::Ui, items: &[Item], key_row: Option<usize>, height: f32) -> Option<Item> {+ let t = Tokens::get();+ let width = t.form_card_width + t.form_label_width * 2.0 + t.space_24 + t.space_16 + t.space_6;+ let mut picked = None;+ Menu::frame().inner_margin(t.space_8 + 1.0).show(ui, |ui| {+ ui.set_width(width);+ ui.spacing_mut().item_spacing.y = 0.0;+ ui.add_space(t.space_4);+ ui.label(+ egui::RichText::new(crate::i18n::tr("ui.ribbon_workspace").to_uppercase())+ .size(crate::theme::Tokens::get().font_small)+ .semibold()+ .color(t.text_dim),+ );+ ui.add_space(t.space_8);+ egui::ScrollArea::vertical().id_salt("workspace_menu_rows").max_height((height - 116.0).max(60.0)).show(ui, |ui| {+ for (k, item) in items.iter().enumerate() {+ let (slug, description, tabs) = match item.label.as_str() {+ "Design" => ("design", "ui.workspace_design_description", Some("ui.workspace_design_tabs")),+ "Render" => ("render", "ui.workspace_render_description", Some("ui.workspace_render_tabs")),+ "Animation" => ("animation", "ui.workspace_animation_description", None),+ "Simulation" => ("simulation", "ui.workspace_simulation_description", None),+ "Manufacture" => ("manufacture", "ui.workspace_manufacture_description", None),+ "Drawing" => ("drawing", "ui.workspace_drawing_description", None),+ _ => continue,+ };+ let planned = tabs.is_none();+ let current = item.shortcut == "current";+ let (accent, soft) = if !planned && slug == "render" {+ (t.render_fill, t.render_soft)+ } else {+ let accent = if planned { t.text_dim } else { t.accent };+ (accent, t.panel.lerp_to_gamma(accent, 0.10))+ };+ let (r, resp) = ui.allocate_exact_size(+ vec2(width, if planned { t.space_24 * 2.0 + t.space_12 } else { t.space_24 * 3.0 }),+ if item.enabled { Sense::click() } else { Sense::hover() },+ );+ for handle in [format!("menu:{}", item.id), format!("workspace:menu:{slug}")] {+ crate::scenario::publish_target(&handle, r);+ }+ if current || (item.enabled && (resp.hovered() || key_row == Some(k))) {+ ui.painter().rect_filled(r, 5.0, soft);+ }+ ui.painter().rect_filled(+ Rect::from_min_max(r.min + vec2(t.space_2, t.space_6 + 1.0), pos2(r.left() + 6.0, r.bottom() - 7.0)),+ 2.0,+ accent,+ );+ let tile = Rect::from_center_size(+ pos2(r.left() + 40.0, r.center().y),+ vec2(t.space_24 + t.space_16 + t.space_4, t.space_24 + t.space_16 + t.space_4),+ );+ ui.painter().rect_filled(tile, 9.0, if planned { t.panel_header } else { soft });+ if !item.icon.is_empty() {+ icons::paint_icon(ui.painter(), tile.shrink(t.space_6 + 1.0), &item.icon, if item.enabled { 1.0 } else { 0.35 });+ }+ let text = if item.enabled { t.text } else { t.text_dim };+ let name = crate::i18n::tr_label(&item.label);+ let x = r.left() + 74.0;+ let y = r.top() + 17.0;+ let galley = egui::WidgetText::from(egui::RichText::new(name).semibold().size(crate::theme::Tokens::get().font_heading).color(text))+ .into_galley(ui, Some(egui::TextWrapMode::Extend), f32::INFINITY, egui::TextStyle::Button);+ let badge_x = x + galley.size().x + 9.0;+ let origin = pos2(x, y - galley.size().y / 2.0);+ let ppp = ui.ctx().pixels_per_point().max(0.5);+ let origin = pos2((origin.x * ppp).round() / ppp, (origin.y * ppp).round() / ppp);+ ui.painter().galley(origin, galley, text);+ let badge = crate::i18n::tr(if planned {+ "ui.workspace_planned"+ } else if current {+ "ui.workspace_current"+ } else {+ "ui.workspace_available"+ });+ let badge = ui.painter().layout_no_wrap(+ badge.to_string(),+ FontId::proportional(crate::theme::Tokens::get().font_small),+ if current { t.on_accent } else { accent },+ );+ let badge_rect = Rect::from_min_size(pos2(badge_x, y - 8.0), badge.size() + vec2(t.space_12, t.space_3));+ ui.painter().rect_filled(badge_rect, 8.0, if current { accent } else { soft });+ ui.painter().galley(badge_rect.min + vec2(t.space_6, t.space_3 / 2.0), badge, accent);+ let line = |content: String, y: f32| {+ let mut job =+ egui::text::LayoutJob::simple_singleline(content, FontId::proportional(crate::theme::Tokens::get().font_body), text);+ job.wrap.max_width = r.right() - x - 6.0;+ job.wrap.max_rows = 1;+ job.wrap.break_anywhere = false;+ let galley = ui.painter().layout_job(job);+ ui.painter().galley(pos2(x, y), galley, text);+ };+ line(crate::i18n::tr(description).to_string(), r.top() + 29.0);+ if let Some(tabs) = tabs {+ // Translate each tab even when this composed message falls back to English.+ let labels = crate::i18n::tr(tabs).split('·').map(|label| crate::i18n::tr_label(label.trim())).collect::<Vec<_>>().join(" · ");+ line(labels, r.top() + 47.0);+ }+ resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, item.enabled, name));+ if resp.clicked() && item.enabled {+ picked = Some(item.clone());+ }+ }+ });+ ui.add_space(t.space_6);+ ui.separator();+ ui.add_space(t.space_6);+ ui.add(+ egui::Label::new(+ egui::RichText::new(crate::i18n::tr("ui.workspace_footer")).size(crate::theme::Tokens::get().font_small).color(t.text_dim),+ )+ .wrap(),+ );+ ui.add_space(t.space_4);+ });+ picked+}++/// Rename keeps the stable editor identity and selects the whole initial name.+pub(crate) fn rename_menu(ui: &mut Ui, value: &mut String, focused: &mut bool) -> Option<bool> {+ let t = Tokens::get();+ let mut done = None;+ Menu::show(ui, t.form_card_width, |ui| {+ super::scope(ui, |ui| {+ Menu::heading(ui, "Rename");+ let id = egui::Id::new("sc_rename_text");+ let response = ui.add(super::fields::text_input(egui::TextEdit::singleline(value).id(id)).desired_width(ui.available_width()));+ crate::scenario::publish_target("rename:name", response.rect);+ if !*focused {+ if let Some(mut state) = egui::TextEdit::load_state(ui.ctx(), id) {+ state.cursor.set_char_range(Some(egui::text::CCursorRange::two(+ egui::text::CCursor::new(0),+ egui::text::CCursor::new(value.chars().count()),+ )));+ state.store(ui.ctx(), id);+ }+ response.request_focus();+ *focused = true;+ }+ if ui.input(|i| i.key_pressed(egui::Key::Enter)) {+ done = Some(true);+ }+ if ui.input(|i| i.key_pressed(egui::Key::Escape)) {+ done = Some(false);+ }+ match super::footer(ui, "OK", "Cancel", !value.trim().is_empty(), super::Footer::default()) {+ super::Action::Ok => done = Some(true),+ super::Action::Cancel => done = Some(false),+ _ => {}+ }+ })+ });+ done+}++#[cfg(test)]+mod tests {+ use super::*;+ use crate::test_support::{key, pointer};++ #[test]+ fn menu_navigation_skips_disabled_rows_and_wraps() {+ let ctx = crate::fonts::test_context();+ let mut selected = None;+ let mut accepted = false;+ let mut frame = |events| {+ let mut output = ctx.run_ui(egui::RawInput { events, ..Default::default() }, |ui| {+ accepted = Menu::navigate(ui.ctx(), &[true, false, true], &mut selected);+ });+ output.textures_delta.clear();+ (selected, accepted)+ };+ assert_eq!(frame(key(egui::Key::ArrowDown)), (Some(0), false));+ assert_eq!(frame(key(egui::Key::ArrowDown)), (Some(2), false));+ assert_eq!(frame(key(egui::Key::ArrowDown)), (Some(0), false));+ assert_eq!(frame(key(egui::Key::ArrowUp)), (Some(2), false));+ assert_eq!(frame(key(egui::Key::Enter)), (Some(2), true));+ }++ #[test]+ fn disabled_menu_rows_are_inert_and_live_rows_accept_clicks() {+ for enabled in [false, true] {+ let ctx = crate::fonts::test_context();+ let target = std::cell::Cell::new(Rect::NOTHING);+ let clicked = std::cell::Cell::new(false);+ let mut draw = |ui: &mut Ui| {+ Menu::show(ui, 268.0, |ui| {+ let mut item = MenuItem::new("paste", "Paste", "paste");+ item.enabled = enabled;+ let response = item.show(ui);+ target.set(response.rect);+ clicked.set(clicked.get() || response.clicked());+ });+ };+ super::super::test_support::frame(&ctx, vec![], &mut draw);+ let at = target.get().center();+ super::super::test_support::frame(&ctx, pointer(at, true), &mut draw);+ super::super::test_support::frame(&ctx, pointer(at, false), &mut draw);+ assert_eq!(clicked.get(), enabled);+ }+ }+}diff --git a/crates/ui-egui/src/ui_kit/mod.rs b/crates/ui-egui/src/ui_kit/mod.rsindex 9f89297fcb..6bc4050d23 100644--- a/crates/ui-egui/src/ui_kit/mod.rs+++ b/crates/ui-egui/src/ui_kit/mod.rs@@ -9,8 +9,10 @@ mod confirm;mod disclosure;mod fields;mod layout;+mod menu;mod metrics;pub(crate) mod panel;+mod radial;mod reports;mod status;mod table;@@ -24,10 +26,12 @@ pub(crate) use confirm::{Confirm, Tone};pub(crate) use disclosure::*;pub(crate) use fields::*;pub(crate) use layout::*;+pub(crate) use menu::{Menu, MenuItem, rename_menu, workspace_menu};pub(crate) use metrics::{ContentWidth, header_height, row_height, table_row_height};pub(crate) use panel::{ComputeStatus, FeatureOptions, Panel, Part, Window, WindowPage};#[cfg(test)]pub(crate) use panel::{collapsible_header, header};+pub(crate) use radial::{RADIAL_RADIUS, radial_menu};pub(crate) use reports::*;pub(crate) use status::*;pub(crate) use table::*;diff --git a/crates/ui-egui/src/ui_kit/radial.rs b/crates/ui-egui/src/ui_kit/radial.rsnew file mode 100644index 0000000000..1e1146e77d--- /dev/null+++ b/crates/ui-egui/src/ui_kit/radial.rs@@ -0,0 +1,188 @@+//! Analytic rounded annular sectors, following the board's offset-and-round construction.+use crate::{context_menu::Item, theme::Tokens};+use egui::{Align2, Color32, FontId, Pos2, Rect, Sense, Stroke, Ui, Vec2, vec2};+use std::f32::consts::{FRAC_PI_2, FRAC_PI_4, PI, TAU};++pub(crate) const RADIAL_RADIUS: f32 = 150.0;+const INNER: f32 = 56.0;+const GAP: f32 = 4.0;+const CORNER: f32 = 9.0;+const STEPS: usize = 16;++fn unit(a: f32) -> Vec2 {+ vec2(a.cos(), a.sin())+}++/// Two equally sampled boundaries; their ends are joined by parallel straight sides.+/// The four joins are circular arcs of radius CORNER, tangent to both adjacent edges.+fn boundaries(k: usize) -> (Vec<Pos2>, Vec<Pos2>) {+ let am = -FRAC_PI_2 + (k % 8) as f32 * FRAC_PI_4;+ let a0 = am - FRAC_PI_4 / 2.0;+ let a1 = am + FRAC_PI_4 / 2.0;+ let d = GAP / 2.0 + CORNER;+ let ro = RADIAL_RADIUS - CORNER;+ let ri = INNER + CORNER;+ let outer0 = a0 + (d / ro).asin();+ let outer1 = a1 - (d / ro).asin();+ let inner0 = a0 + (d / ri).asin();+ let inner1 = a1 - (d / ri).asin();+ let po0 = Pos2::ZERO + unit(outer0) * ro;+ let po1 = Pos2::ZERO + unit(outer1) * ro;+ let pi0 = Pos2::ZERO + unit(inner0) * ri;+ let pi1 = Pos2::ZERO + unit(inner1) * ri;+ let arc = |out: &mut Vec<Pos2>, center: Pos2, radius: f32, from: f32, to: f32| {+ for j in 0..=STEPS {+ out.push(center + unit(from + (to - from) * j as f32 / STEPS as f32) * radius);+ }+ };+ let mut outer = Vec::new();+ arc(&mut outer, po0, CORNER, a0 - FRAC_PI_2, outer0);+ arc(&mut outer, Pos2::ZERO, RADIAL_RADIUS, outer0, outer1);+ arc(&mut outer, po1, CORNER, outer1, a1 + FRAC_PI_2);+ let mut inner = Vec::new();+ arc(&mut inner, pi0, CORNER, a0 - FRAC_PI_2, inner0 - PI);+ arc(&mut inner, Pos2::ZERO, INNER, inner0, inner1);+ arc(&mut inner, pi1, CORNER, inner1 - PI, a1 + FRAC_PI_2 - TAU);+ (outer, inner)+}++fn contains(k: usize, at: Vec2) -> bool {+ if !at.is_finite() || !(INNER..=RADIAL_RADIUS).contains(&at.length()) {+ return false;+ }+ let (outer, inner) = boundaries(k);+ let outline: Vec<_> = outer.into_iter().chain(inner.into_iter().rev()).collect();+ let Some(last) = outline.last() else {+ return false;+ };+ let mut previous = *last;+ let mut inside = false;+ for current in outline {+ if (previous.y > at.y) != (current.y > at.y) {+ let x = (current.x - previous.x) * (at.y - previous.y) / (current.y - previous.y) + previous.x;+ if at.x < x {+ inside = !inside;+ }+ }+ previous = current;+ }+ inside+}++fn paint_sector(p: &egui::Painter, center: Pos2, k: usize, fill: Color32, stroke: Stroke) {+ let (outer, inner) = boundaries(k);+ let mut mesh = egui::Mesh::default();+ for (o, i) in outer.iter().zip(&inner) {+ mesh.colored_vertex(*o + center.to_vec2(), fill);+ mesh.colored_vertex(*i + center.to_vec2(), fill);+ }+ for j in 0..outer.len().saturating_sub(1) {+ let a = (j * 2) as u32;+ mesh.add_triangle(a, a + 2, a + 1);+ mesh.add_triangle(a + 1, a + 2, a + 3);+ }+ p.add(egui::Shape::mesh(mesh));+ let outline = outer.iter().chain(inner.iter().rev()).map(|p| *p + center.to_vec2()).collect();+ p.add(egui::Shape::closed_line(outline, stroke));+}++pub(crate) fn radial_menu(ui: &mut Ui, center: Pos2, items: &[Item], hot: Option<usize>) -> Option<Item> {+ let t = Tokens::get();+ let mut picked = None;+ for (k, item) in items.iter().take(8).enumerate() {+ let enabled = item.enabled && ui.is_enabled();+ let lit = enabled && hot == Some(k);+ let mut painter = ui.painter().clone();+ if !enabled {+ painter.multiply_opacity(0.4);+ }+ paint_sector(+ &painter,+ center,+ k,+ if lit { t.accent_soft } else { t.dialog_body },+ Stroke::new(if lit { 1.6 } else { 1.0 }, if lit { t.form_primary } else { t.dialog_border }),+ );+ let a = -FRAC_PI_2 + k as f32 * FRAC_PI_4;+ let at = center + unit(a) * 104.0;+ let target = Rect::from_center_size(at, vec2(t.space_24 * 2.0 + t.space_12, t.space_24 + t.space_16 + t.space_2));+ let response = ui.interact(target, ui.id().with(("radial", k)), Sense::hover());+ crate::scenario::publish_target(&format!("radial:{}", item.id), target);+ let ink = if lit { t.form_primary } else { t.form_ink };+ crate::icons::paint_ink(&painter, Rect::from_center_size(at - vec2(0.0, t.space_6), vec2(t.space_24, t.space_24)), &item.icon, ink);+ let label = crate::i18n::tr_label(&item.label);+ let mut job = egui::text::LayoutJob::simple_singleline(label.to_string(), FontId::proportional(t.font_small), ink);+ job.wrap.max_width = 74.0;+ job.wrap.max_rows = 1;+ let galley = painter.layout_job(job);+ painter.galley(at + vec2(-galley.size().x / 2.0, t.space_10), galley, ink);+ response.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, enabled, label));+ if lit && ui.input(|i| i.pointer.primary_clicked() && i.pointer.interact_pos().is_some_and(|p| contains(k, p - center))) {+ picked = Some(item.clone());+ }+ }+ let p = ui.painter();+ p.circle(center, INNER - t.space_6, t.dialog_body, Stroke::new(1.0, t.dialog_border));+ if let Some(item) = hot.and_then(|k| items.get(k)) {+ p.text(+ center - vec2(0.0, t.space_6),+ Align2::CENTER_CENTER,+ crate::i18n::tr_label(&item.label),+ FontId::proportional(t.font_label),+ t.form_ink,+ );+ p.text(+ center + vec2(0.0, t.space_14),+ Align2::CENTER_CENTER,+ crate::i18n::tr_label(&item.shortcut),+ FontId::monospace(t.font_small),+ t.form_dim,+ );+ }+ picked+}++#[cfg(test)]+mod tests {+ use super::*;++ #[test]+ fn radial_clicks_ignore_the_disc_gaps_outside_and_nonfinite_positions() {+ for k in 0..8 {+ let a = -FRAC_PI_2 + k as f32 * FRAC_PI_4;+ assert!(contains(k, unit(a) * 104.0));+ for at in [Vec2::ZERO, unit(a) * 200.0, vec2(f32::NAN, 0.0), vec2(f32::INFINITY, 0.0), unit(a + FRAC_PI_4 / 2.0) * 104.0] {+ assert!(!contains(k, at), "sector {k}: {at:?}");+ }+ }+ }++ #[test]+ fn neighbouring_sectors_have_parallel_four_point_gaps_and_four_round_corners() {+ for k in 0..8 {+ let (outer, inner) = boundaries(k);+ let (next_outer, next_inner) = boundaries(k + 1);+ // These are the actual ends of the straight sides, at both ends of the ring.+ let outer_gap = outer.last().unwrap().distance(next_outer.first().copied().unwrap());+ let inner_gap = inner.last().unwrap().distance(next_inner.first().copied().unwrap());+ assert!((outer_gap - GAP).abs() < 0.01, "{k}: {outer_gap}");+ assert!((inner_gap - GAP).abs() < 0.01, "{k}: {inner_gap}");+ assert!((outer_gap - inner_gap).abs() < 0.5);+ for boundary in [&outer, &inner] {+ for corner in [0, 2 * (STEPS + 1)] {+ let points = &boundary[corner..corner + STEPS + 1];+ // Rounded joins contain an arc, with no concentrated sharp turn.+ let mut turning = 0.0;+ for triple in points.windows(3) {+ let a = (triple[1] - triple[0]).normalized();+ let b = (triple[2] - triple[1]).normalized();+ let angle = a.dot(b).clamp(-1.0, 1.0).acos();+ assert!(angle < 0.12, "sharp corner: {angle}");+ turning += angle;+ }+ assert!(turning > 1.0, "corner must be a curved arc");+ }+ }+ }+ }+}diff --git a/crates/ui-egui/src/ui_kit_guard_tests.rs b/crates/ui-egui/src/ui_kit_guard_tests.rsindex 67cf61481b..e28d7afdf1 100644--- a/crates/ui-egui/src/ui_kit_guard_tests.rs+++ b/crates/ui-egui/src/ui_kit_guard_tests.rs@@ -789,6 +789,10 @@ fn disclosure_guard_distinguishes_overflow_and_playback_from_conditional_folds()/// System windows and confirms may compose content, but never define another card frame.fn window_frame_violations(source: &str) -> Vec<String> {+ parsed_frame_violations(&syn::parse_file(source).unwrap())+}++fn parsed_frame_violations(ast: &syn::File) -> Vec<String> {#[derive(Default)]struct Frames {found: Vec<String>,@@ -826,7 +830,6 @@ fn window_frame_violations(source: &str) -> Vec<String> {visit::visit_expr_path(self, expr);}}- let ast = syn::parse_file(source).unwrap();let mut frames = Frames::default();// Collect aliases first, including imports below a caller.for item in &ast.items {@@ -834,7 +837,7 @@ fn window_frame_violations(source: &str) -> Vec<String> {frames.visit_use_tree(&u.tree);}}- frames.visit_file(&ast);+ frames.visit_file(ast);frames.found}@@ -884,3 +887,48 @@ fn window_guard_rejects_frames_aliases_and_native_windows_but_accepts_kit_compos);assert_eq!(found.len(), 6, "{found:?}");}++#[test]+fn context_and_history_menus_only_use_kit_surfaces_without_allowances() {+ for file in ["context_menu.rs", "timeline.rs", "timeline_left.rs", "toolbar.rs"] {+ let source = std::fs::read_to_string(Path::new(env!("CARGO_MANIFEST_DIR")).join("src").join(file)).unwrap();+ let mut ast = syn::parse_file(&source).unwrap();+ ast.items.retain(|item| match item {+ syn::Item::Use(_) => true,+ syn::Item::Fn(function) => {+ let name = function.sig.ident.to_string();+ file == "context_menu.rs" || name.contains("menu") || name == "dropdown_row" || name == "section_frame"+ }+ _ => false,+ });+ let found = parsed_frame_violations(&ast);+ assert!(found.is_empty(), "{file}: caller-defined menu frame: {found:?}");+ #[derive(Default)]+ struct NativeMenus(Vec<String>);+ impl<'ast> Visit<'ast> for NativeMenus {+ fn visit_item_mod(&mut self, item: &'ast syn::ItemMod) {+ if !item.attrs.iter().any(|a| a.path().is_ident("cfg") && a.parse_args::<syn::Path>().is_ok_and(|p| p.is_ident("test"))) {+ visit::visit_item_mod(self, item);+ }+ }+ fn visit_expr_method_call(&mut self, call: &'ast syn::ExprMethodCall) {+ if matches!(call.method.to_string().as_str(), "context_menu" | "menu_button") {+ self.0.push(call.method.to_string());+ }+ visit::visit_expr_method_call(self, call);+ }+ fn visit_expr_path(&mut self, expr: &'ast syn::ExprPath) {+ if expr.path.segments.iter().any(|s| s.ident == "Frame")+ && expr.path.segments.last().is_some_and(|s| s.ident == "popup" || s.ident == "menu")+ {+ self.0.push("raw popup frame".into());+ }+ visit::visit_expr_path(self, expr);+ }+ }+ let mut guard = NativeMenus::default();+ guard.visit_file(&syn::parse_file(&source).unwrap());+ assert!(guard.0.is_empty(), "{file}: native menu bypasses: {:?}", guard.0);+ }+ assert!(ALLOWED.is_empty());+}diff --git a/crates/ui-egui/tests/icon_audit.rs b/crates/ui-egui/tests/icon_audit.rsindex aff59880e0..79359e4093 100644--- a/crates/ui-egui/tests/icon_audit.rs+++ b/crates/ui-egui/tests/icon_audit.rs@@ -62,6 +62,18 @@ fn menu(h: &mut Harness, target: Value, surface: &str, requested: &mut BTreeMap<let intentional = id == "-" || id.starts_with('#') || (id == "ui.workspace" && item["shortcut"] == "coming later");assert!(!blank || intentional, "{surface}: icon-less menu item {item}");assert_eq!(item["placeholder"], false, "{surface}: {item}");+ if let Some(children) = item["children"].as_array() {+ for child in children {+ let id = child["id"].as_str().unwrap();+ assert!(!id.is_empty(), "{surface}: child has no identity");+ if id == "-" || id.starts_with('#') {+ continue;+ }+ let icon = child["icon"].as_str().unwrap();+ assert!(!icon.is_empty(), "{surface}: submenu row has no icon: {child}");+ assert!(!solidcraft_ui_egui::icon_svg::resolve(icon).placeholder, "{surface}: submenu placeholder {icon}");+ }+ }}collect(h, surface, requested);escape(h);@@ -157,6 +169,7 @@ fn requested_menu_icons_have_artwork_and_match_manifest() {json!({"type":"viewport"}),json!({"type":"body","name":body}),json!({"type":"sketch","id":sketch}),+ json!({"type":"feature","id":sketch}),json!({"type":"component","id":0}),json!({"type":"origin"}),json!({"type":"origin_plane","name":"XY"}),diff --git a/docs/manage-ui-kit-audit.md b/docs/manage-ui-kit-audit.mdindex 7efdc385e7..bb5c6244bc 100644--- a/docs/manage-ui-kit-audit.md+++ b/docs/manage-ui-kit-audit.md@@ -13,8 +13,8 @@ These specialised surfaces remain in their owners:| Start page: `home.rs` | Painted start tiles, thumbnails and links rather than form cards || Assistant transcript/composer containers, gallery and docking: `agent_chat/panel.rs` | Conversation/media layout, rich selectable content, drag/docking behavior; matching controls use the kit || Native file/program pickers: `file_picker.rs`, host services | Host-native sheets have no egui control surface; load/progress cards use the kit |-| Help menu and command-result ranking/list/pins: `help.rs`, `shortcut_box.rs` | Menu/search layout; search editor uses the kit |-| Ribbon, browser/timeline rows, context menus: `toolbar.rs`, `browser.rs`, `context_menu.rs`, `timeline_left.rs` | Specialised navigation, painting, menus and inline rename interactions |+| Command-result ranking/list/pins: `shortcut_box.rs` | Search layout and ranking; popup shell and matching controls use the kit |+| Ribbon and browser/timeline rows: `toolbar.rs`, `browser.rs`, `timeline_left.rs` | Specialised navigation, canvas painting, drag/drop and inline rename placement; context/overflow menus, their rows and floating rename now use the kit || Motion transport, key strips and chart: `dialogs_motion.rs`, `dialogs_motion_plot.rs` | Playback/chart interaction; matching form controls use the kit || Generated part thumbnails: `dialogs_parts.rs` | Cached images rather than controls || Joint-browser glyphs and flat-pattern canvas: `dialogs_assembly.rs`, `dialogs_sheet.rs` | Model navigation and geometry; dialog/export actions use the kit |@@ -29,3 +29,12 @@ Immediate commands such as `parameters.graph`, `parameters.move`, `config.rules`related controls live in Parameters, Configurations and Appearance; the kit createsno extra command dialogs. Command IDs, model operations and scenario handles areunchanged by cleanup.++Context menus are covered by `Menu`/`MenuItem`, including browser and history targets,+workspace popup chrome, Appearance submenus, section headings, separators, checks,+disabled/danger rows and ribbon pin rows. The optional marking menu uses the kit's+rounded-sector renderer; its command choices and hold/flick behavior remain owned+by `context_menu.rs`. Floating rename uses kit fields and actions; Properties already+uses the shared Window. No menu-frame or raw-control allowances were added.+The light/dark gallery and CPU evidence cover representative row states and radial+geometry; desktop captures of the live menus remain part of reviewer acceptance.diff --git a/docs/ui-kit.md b/docs/ui-kit.mdindex b31cd4b011..a7311cd7e2 100644--- a/docs/ui-kit.md+++ b/docs/ui-kit.md@@ -1,7 +1,7 @@# SolidCraft UI kit`crates/ui-egui/src/ui_kit/` contains the tokenised controls used by feature dialogs,-preferences, manager cards, prompts and the sketch palette. Import through+preferences, manager cards, prompts, context menus and the sketch palette. Import through`crate::ui_kit::{...}`. The API is crate-visible; implementation modules are private.## Composition and rules@@ -55,6 +55,8 @@ table. Panel/Window/Confirm compositions also have dedicated geometry and intera| Module / element | Use and options | Main tokens || --- | --- | --- |+| menu: `Menu`, `MenuItem` | Shared popup, 30 pt rows, 28 pt icon column, clipped labels, right-aligned mono shortcuts, submenu chevrons, checked/unchecked and document swatches, inert 40% disabled rows and danger ink; headings and separators; ribbon drag/pin targets retained | `dialog_body/border/rule`, `radius_xl`, `control_height/radius`, `form_ink/dim/primary/error`, `accent_soft`, typography and spacing |+| radial: `radial_menu` | Eight rounded annular sectors, parallel 4 pt gaps, 9 pt circular corner joins, accent hover, centre label/key; existing hold/flick/release dispatch | `dialog_body/border`, `form_ink/dim/primary`, `accent_soft`, font/spacing tokens || panel: `Window`, `WindowPage` | Shared card frame, header, optional page list, bounded content and footer with a left action | `form_header/footer_height`, `form_card_width`, `form_label_width`, `control_height`, `dialog_footer/rule`, `selected_bg/ink`, spacing || confirm: `Confirm`, `Tone` | Modal warning/danger/info, title/message, mono detail and ghost/cancel/primary actions | `warning`, `form_error/fill`, `accent_soft`, `form_primary`, `on_accent`, `tab_on_fill_dark`, `font_subtitle`, spacing || metrics: `row_height`, `table_row_height`, `header_height` | Shared control/header heights | `control_height`, `space_8`, `form_header_height` |@@ -307,3 +309,21 @@ of the approved fills. It only styles tab pills; global primary actions still us`on_accent`. Built-in palette tests require WCAG contrast of at least 4.5:1 forink on the card and panel, ink on soft, and pill text on fill in both themes.Only Mesh separates ink from fill in the light theme.++Context menu adapters retain item IDs, enabled logic and command parameters. `Menu`+owns popup elevation (10 pt corners, 1 pt border), headings, separators, adjacent+submenus and bounded arrow navigation. Enter opens a submenu or chooses its row;+Right opens, Left returns, and Esc dismisses the menu. Appearance includes document+swatches and Remove override through `appearance.assign`; its original action still+opens the full editor. Workspace retains its descriptive cards and scenario handles+on the shared surface. Ribbon rows reuse `MenuItem::paint` while owning drag, focus+and pin interactions. History context menus and ribbon overflow use kit popup chrome.+Rename uses the shared caption, field policy and Cancel/OK actions with its stable+editor ID. No additional translation keys or colour roles are needed.++The menu gallery includes normal, hovered, open, disabled, checked/unchecked,+swatch and danger rows, a submenu and rename. Radial geometry tests measure the+actual side endpoints at both radii and sample all four rounded corners. Optional+CPU-rendered menu evidence can be produced without a window with+`SOLIDCRAFT_MENU_EVIDENCE=/tmp/menus cargo test -p solidcraft-ui-egui --lib menu_board_in_both_themes`.+Desktop interaction and visual acceptance still require a reviewer capture.