diff --git a/assets/locales/cs.json b/assets/locales/cs.json index d575a17b7..0759e7757 100644 --- a/assets/locales/cs.json +++ b/assets/locales/cs.json @@ -335,6 +335,7 @@ "Show Agent Cursor": "Zobrazit kurzor agenta", "Show in folder": "Zobrazit ve složce", "Show the pointer an AI agent moves (#35)": "Zobrazit ukazatel, kterým pohybuje AI agent (#35)", + "Show tool at cursor": "Zobrazit nástroj u kurzoru", "Signed axes": "Osy se znaménkem", "Size": "Velikost", "Sketch constraints": "Vazby náčrtu", diff --git a/assets/locales/da.json b/assets/locales/da.json index 305b080e1..5f02b6362 100644 --- a/assets/locales/da.json +++ b/assets/locales/da.json @@ -335,6 +335,7 @@ "Show Agent Cursor": "Vis agentmarkør", "Show in folder": "Vis i mappe", "Show the pointer an AI agent moves (#35)": "Vis markøren, som en AI-agent bevæger (#35)", + "Show tool at cursor": "Vis værktøj ved markøren", "Signed axes": "Akser med fortegn", "Size": "Størrelse", "Sketch constraints": "Skitsebindinger", diff --git a/assets/locales/de.json b/assets/locales/de.json index 4d13b2b67..30f4108f7 100644 --- a/assets/locales/de.json +++ b/assets/locales/de.json @@ -421,6 +421,7 @@ "Show Agent Cursor": "Agenten-Cursor anzeigen", "Show in folder": "Im Ordner anzeigen", "Show the pointer an AI agent moves (#35)": "Den Zeiger anzeigen, den ein KI-Agent bewegt (#35)", + "Show tool at cursor": "Werkzeug am Cursor anzeigen", "Signed axes": "Vorzeichenbehaftete Achsen", "Size": "Größe", "Sketch constraints": "Skizzenbedingungen", diff --git a/assets/locales/en.json b/assets/locales/en.json index ad02bc243..c8dc9b70e 100644 --- a/assets/locales/en.json +++ b/assets/locales/en.json @@ -477,6 +477,7 @@ "Show ghost": "Show ghost", "Show in folder": "Show in folder", "Show the pointer an AI agent moves (#35)": "Show the pointer an AI agent moves (#35)", + "Show tool at cursor": "Show tool at cursor", "Signed axes": "Signed axes", "Size": "Size", "Sketch constraints": "Sketch constraints", diff --git a/assets/locales/es.json b/assets/locales/es.json index 222c66dc0..c7a894090 100644 --- a/assets/locales/es.json +++ b/assets/locales/es.json @@ -341,6 +341,7 @@ "Show Agent Cursor": "Mostrar cursor del agente", "Show in folder": "Mostrar en carpeta", "Show the pointer an AI agent moves (#35)": "Mostrar el puntero que mueve un agente de IA (#35)", + "Show tool at cursor": "Mostrar la herramienta junto al cursor", "Signed axes": "Ejes con signo", "Size": "Tamaño", "Sketch constraints": "Restricciones del boceto", diff --git a/assets/locales/fr.json b/assets/locales/fr.json index 997c364ed..3b8ca7183 100644 --- a/assets/locales/fr.json +++ b/assets/locales/fr.json @@ -335,6 +335,7 @@ "Show Agent Cursor": "Afficher le curseur de l'agent", "Show in folder": "Afficher dans le dossier", "Show the pointer an AI agent moves (#35)": "Afficher le pointeur déplacé par un agent IA (#35)", + "Show tool at cursor": "Afficher l'outil près du curseur", "Signed axes": "Axes signés", "Size": "Taille", "Sketch constraints": "Contraintes d'esquisse", diff --git a/assets/locales/gl.json b/assets/locales/gl.json index f2851bd5e..e233f2c2d 100644 --- a/assets/locales/gl.json +++ b/assets/locales/gl.json @@ -335,6 +335,7 @@ "Show Agent Cursor": "Mostrar o cursor do axente", "Show in folder": "Mostrar no cartafol", "Show the pointer an AI agent moves (#35)": "Mostrar o punteiro que move un axente de IA (#35)", + "Show tool at cursor": "Mostrar a ferramenta xunto ao cursor", "Signed axes": "Eixes con signo", "Size": "Tamaño", "Sketch constraints": "Restricións do bosquexo", diff --git a/assets/locales/hu.json b/assets/locales/hu.json index 5b3aa5d60..841abd131 100644 --- a/assets/locales/hu.json +++ b/assets/locales/hu.json @@ -334,6 +334,7 @@ "Show Agent Cursor": "Ügynök kurzorának megjelenítése", "Show in folder": "Megjelenítés a mappában", "Show the pointer an AI agent moves (#35)": "Az AI-ügynök által mozgatott mutató megjelenítése (#35)", + "Show tool at cursor": "Eszköz megjelenítése a kurzornál", "Signed axes": "Előjeles tengelyek", "Size": "Méret", "Sketch constraints": "Vázlatkényszerek", diff --git a/assets/locales/id.json b/assets/locales/id.json index 2622d3779..fe29b447a 100644 --- a/assets/locales/id.json +++ b/assets/locales/id.json @@ -334,6 +334,7 @@ "Show Agent Cursor": "Tampilkan Kursor Agen", "Show in folder": "Tampilkan di folder", "Show the pointer an AI agent moves (#35)": "Tampilkan penunjuk yang digerakkan agen AI (#35)", + "Show tool at cursor": "Tampilkan alat di dekat kursor", "Signed axes": "Sumbu bertanda", "Size": "Ukuran", "Sketch constraints": "Batasan sketsa", diff --git a/assets/locales/it.json b/assets/locales/it.json index fa8a593de..3cdb28e95 100644 --- a/assets/locales/it.json +++ b/assets/locales/it.json @@ -338,6 +338,7 @@ "Show Agent Cursor": "Mostra cursore dell'agente", "Show in folder": "Mostra nella cartella", "Show the pointer an AI agent moves (#35)": "Mostra il puntatore mosso da un agente IA (#35)", + "Show tool at cursor": "Mostra lo strumento accanto al cursore", "Signed axes": "Assi con segno", "Size": "Dimensioni", "Sketch constraints": "Vincoli dello schizzo", diff --git a/assets/locales/ja.json b/assets/locales/ja.json index ad53c6e82..7c362e9f1 100644 --- a/assets/locales/ja.json +++ b/assets/locales/ja.json @@ -477,6 +477,7 @@ "Show ghost": "ゴーストを表示", "Show in folder": "フォルダに表示", "Show the pointer an AI agent moves (#35)": "エージェントが操作するポインターを表示 (#35)", + "Show tool at cursor": "カーソルの横にツールを表示", "Signed axes": "符号付き座標軸", "Size": "サイズ", "Sketch constraints": "スケッチ拘束", diff --git a/assets/locales/ko.json b/assets/locales/ko.json index 1113f3675..f0c1456ed 100644 --- a/assets/locales/ko.json +++ b/assets/locales/ko.json @@ -436,6 +436,7 @@ "Show Agent Cursor": "에이전트 커서 표시", "Show in folder": "폴더에서 보기", "Show the pointer an AI agent moves (#35)": "AI 에이전트가 움직이는 포인터 표시 (#35)", + "Show tool at cursor": "커서 옆에 도구 표시", "Signed axes": "부호 있는 축", "Size": "크기", "Sketch constraints": "스케치 구속 조건", diff --git a/assets/locales/ms.json b/assets/locales/ms.json index b2619f1db..b4a4619a2 100644 --- a/assets/locales/ms.json +++ b/assets/locales/ms.json @@ -335,6 +335,7 @@ "Show Agent Cursor": "Papar Kursor Ejen", "Show in folder": "Papar dalam folder", "Show the pointer an AI agent moves (#35)": "Papar penuding yang digerakkan oleh ejen AI (#35)", + "Show tool at cursor": "Tunjukkan alat di sebelah kursor", "Signed axes": "Paksi bertanda", "Size": "Saiz", "Sketch constraints": "Kekangan lakaran", diff --git a/assets/locales/nl.json b/assets/locales/nl.json index 82ed25403..10d3aff31 100644 --- a/assets/locales/nl.json +++ b/assets/locales/nl.json @@ -334,6 +334,7 @@ "Show Agent Cursor": "Agentcursor tonen", "Show in folder": "Tonen in map", "Show the pointer an AI agent moves (#35)": "De aanwijzer tonen die een AI-agent verplaatst (#35)", + "Show tool at cursor": "Gereedschap bij de cursor tonen", "Signed axes": "Assen met teken", "Size": "Grootte", "Sketch constraints": "Schetsbeperkingen", diff --git a/assets/locales/pl.json b/assets/locales/pl.json index df1e89010..da3b85b6a 100644 --- a/assets/locales/pl.json +++ b/assets/locales/pl.json @@ -352,6 +352,7 @@ "Show Agent Cursor": "Pokaż kursor agenta", "Show in folder": "Pokaż w folderze", "Show the pointer an AI agent moves (#35)": "Pokaż wskaźnik poruszany przez agenta AI (#35)", + "Show tool at cursor": "Pokaż narzędzie przy kursorze", "Signed axes": "Osie ze znakiem", "Size": "Rozmiar", "Sketch constraints": "Wiązania szkicu", diff --git a/assets/locales/pt-BR.json b/assets/locales/pt-BR.json index be2ffc5c2..78f8ed94c 100644 --- a/assets/locales/pt-BR.json +++ b/assets/locales/pt-BR.json @@ -335,6 +335,7 @@ "Show Agent Cursor": "Mostrar cursor do agente", "Show in folder": "Mostrar na pasta", "Show the pointer an AI agent moves (#35)": "Mostrar o ponteiro que um agente de IA move (#35)", + "Show tool at cursor": "Mostrar a ferramenta junto ao cursor", "Signed axes": "Eixos com sinal", "Size": "Tamanho", "Sketch constraints": "Restrições do esboço", diff --git a/assets/locales/ro.json b/assets/locales/ro.json index e8fca690a..3bdaba4cb 100644 --- a/assets/locales/ro.json +++ b/assets/locales/ro.json @@ -334,6 +334,7 @@ "Show Agent Cursor": "Afișează cursorul agentului", "Show in folder": "Afișează în dosar", "Show the pointer an AI agent moves (#35)": "Afișează indicatorul pe care îl mută un agent AI (#35)", + "Show tool at cursor": "Afișează instrumentul lângă cursor", "Signed axes": "Axe cu semn", "Size": "Dimensiune", "Sketch constraints": "Constrângerile schiței", diff --git a/assets/locales/ru.json b/assets/locales/ru.json index 68f65b77a..8a9cc0dc5 100644 --- a/assets/locales/ru.json +++ b/assets/locales/ru.json @@ -334,6 +334,7 @@ "Show Agent Cursor": "Показывать курсор агента", "Show in folder": "Показать в папке", "Show the pointer an AI agent moves (#35)": "Показывать указатель, которым двигается ИИ-агент (#35)", + "Show tool at cursor": "Показывать инструмент у курсора", "Signed axes": "Знаковые оси", "Size": "Размер", "Sketch constraints": "Ограничения эскиза", diff --git a/assets/locales/sv.json b/assets/locales/sv.json index 9691d43d0..a84b7a2e1 100644 --- a/assets/locales/sv.json +++ b/assets/locales/sv.json @@ -334,6 +334,7 @@ "Show Agent Cursor": "Visa agentmarkör", "Show in folder": "Visa i mapp", "Show the pointer an AI agent moves (#35)": "Visa pekaren som en AI-agent flyttar (#35)", + "Show tool at cursor": "Visa verktyget vid markören", "Signed axes": "Axlar med tecken", "Size": "Storlek", "Sketch constraints": "Skissvillkor", diff --git a/assets/locales/tr.json b/assets/locales/tr.json index b6f8e4a66..6016b718d 100644 --- a/assets/locales/tr.json +++ b/assets/locales/tr.json @@ -334,6 +334,7 @@ "Show Agent Cursor": "Ajan imlecini göster", "Show in folder": "Klasörde göster", "Show the pointer an AI agent moves (#35)": "Bir AI ajanının hareket ettirdiği imleci göster (#35)", + "Show tool at cursor": "Aracı imlecin yanında göster", "Signed axes": "İşaretli eksenler", "Size": "Boyut", "Sketch constraints": "Eskiz kısıtlamaları", diff --git a/assets/locales/uk.json b/assets/locales/uk.json index 9d329e9f3..5b30c5cf8 100644 --- a/assets/locales/uk.json +++ b/assets/locales/uk.json @@ -335,6 +335,7 @@ "Show Agent Cursor": "Показати курсор агента", "Show in folder": "Показати в теці", "Show the pointer an AI agent moves (#35)": "Показувати вказівник, яким рухає ШІ-агент (#35)", + "Show tool at cursor": "Показувати інструмент біля курсора", "Signed axes": "Підписані осі", "Size": "Розмір", "Sketch constraints": "Обмеження ескізу", diff --git a/assets/locales/vi.json b/assets/locales/vi.json index b3422f115..5e13a7b3f 100644 --- a/assets/locales/vi.json +++ b/assets/locales/vi.json @@ -335,6 +335,7 @@ "Show Agent Cursor": "Hiển thị con trỏ của AI Agent", "Show in folder": "Hiển thị trong thư mục", "Show the pointer an AI agent moves (#35)": "Hiển thị con trỏ do AI Agent điều khiển (#35)", + "Show tool at cursor": "Hiển thị công cụ cạnh con trỏ", "Signed axes": "Các trục có dấu (+/-)", "Size": "Kích thước", "Sketch constraints": "Ràng buộc phác thảo", diff --git a/assets/locales/zh-TW.json b/assets/locales/zh-TW.json index ca66e22a1..521896d4c 100644 --- a/assets/locales/zh-TW.json +++ b/assets/locales/zh-TW.json @@ -334,6 +334,7 @@ "Show Agent Cursor": "顯示代理游標", "Show in folder": "在資料夾中顯示", "Show the pointer an AI agent moves (#35)": "顯示 AI 代理移動的指標(#35)", + "Show tool at cursor": "在游標旁顯示工具", "Signed axes": "帶符號軸", "Size": "大小", "Sketch constraints": "草圖拘束條件", diff --git a/assets/locales/zh.json b/assets/locales/zh.json index 9f6162a8e..2d910b75f 100644 --- a/assets/locales/zh.json +++ b/assets/locales/zh.json @@ -477,6 +477,7 @@ "Show ghost": "显示虚影", "Show in folder": "在文件夹中显示", "Show the pointer an AI agent moves (#35)": "显示 AI 代理移动的指针(#35)", + "Show tool at cursor": "在光标旁显示工具", "Signed axes": "带符号轴", "Size": "大小", "Sketch constraints": "草图约束", diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index b4d13987b..b11854bee 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -612,6 +612,11 @@ fn fits(a: Accept, s: &Sel) -> bool { } impl Dialog { + /// The command this dialog runs, whose icon and label its header shows. + pub(crate) fn command(&self) -> Option<&'static str> { + dense::command(&self.kind) + } + /// Show why OK (or starting the sketch) was refused, for as long as the inputs stay as they are. fn refuse(&mut self, app: &SolveApp, error: String) { self.refused = Some(Refused::now(app, self)); diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index a982a14a7..7c959bf79 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -250,6 +250,7 @@ mod thin_extrude_tests; pub mod timeline; pub mod timeline_left; pub mod titlebar; +pub mod tool_cursor; pub mod tool_modifiers; pub mod toolbar; pub mod toolbar_custom; @@ -306,6 +307,9 @@ pub struct UiState { pub up_axis: solidcraft_engine::render::UpAxis, /// The agent cursor: shown, speed, follow camera (#35). pub agent_cursor: agent_cursor::Settings, + /// The running tool's icon rides beside the pointer in the viewport (View settings; off by + /// default). + pub tool_cursor: bool, } impl Default for UiState { @@ -327,6 +331,7 @@ impl Default for UiState { ground_shadow: true, up_axis: Default::default(), agent_cursor: Default::default(), + tool_cursor: false, } } } diff --git a/crates/ui-egui/src/tool_cursor.rs b/crates/ui-egui/src/tool_cursor.rs new file mode 100644 index 000000000..dcd6d4d20 --- /dev/null +++ b/crates/ui-egui/src/tool_cursor.rs @@ -0,0 +1,172 @@ +//! The tool at the cursor: while an interactive tool or a command's dialog is running, its +//! toolbar icon rides above and right of the pointer in the viewport (clear of the sketch tools' +//! coordinate readout below it), so the user sees which command the +//! next click goes to without looking up at the ribbon. It shows only while the pointer is over +//! the model itself (not over a panel, a dialog or a menu) and hides while the camera moves. +//! Off by default; View settings ("Show tool at cursor") or `ui.set {"toolCursor": true}` turn +//! it on. +//! It is UI only: drawing it runs no command and changes nothing in the design. + +use egui::{Pos2, Rect, Stroke, Vec2, pos2, vec2}; + +use crate::SolveApp; +use crate::theme::Tokens; + +/// The badge's side and the icon inside it, in points. +const BADGE: f32 = 26.0; +const ICON: f32 = 20.0; +/// The badge sits above and right of the pointer's hot spot: the system arrow hangs below and +/// right of it, and so does the sketch tools' coordinate readout (`tools::preview`, drawn from +/// [`READOUT`] below right). From the hot spot to the badge's bottom-left corner: +const OFFSET: Vec2 = vec2(12.0, -8.0); +/// Where the sketch tools' coordinate readout starts, down and right of the hot spot. +const READOUT: f32 = 10.0; +/// The gap to the hot spot when the badge flips to the left of the pointer. +const FLIPPED_GAP: f32 = 6.0; + +/// The command whose tool or dialog is running: the one a click in the viewport goes to. +pub(crate) fn command(app: &SolveApp) -> Option<&'static str> { + match (&app.tool, &app.dialog) { + (Some(tool), _) => Some(tool.cmd), + (None, Some(dialog)) => dialog.command(), + _ => None, + } +} + +/// The icon the badge shows: None when it is turned off, nothing runs, or the command has no icon. +pub(crate) fn icon(app: &SolveApp) -> Option<&'static str> { + if !app.ui.tool_cursor { + return None; + } + command(app).and_then(solidcraft_engine::find_command).map(|spec| spec.icon).filter(|icon| !icon.is_empty()) +} + +/// The badge for a pointer at `at`: above and right of it, so it never covers the coordinate +/// readout below. Near the right edge of `bounds` it moves to the left of the pointer; with no +/// room above, it drops below the readout's line (`readout_height` high), never onto it. +fn badge_rect(at: Pos2, bounds: Rect, readout_height: f32) -> Rect { + let mut min = pos2(at.x + OFFSET.x, at.y + OFFSET.y - BADGE); + if min.x + BADGE > bounds.right() { + min.x = at.x - FLIPPED_GAP - BADGE; + } + if min.y < bounds.top() { + min.y = at.y + READOUT + readout_height + FLIPPED_GAP; + } + Rect::from_min_size(min, vec2(BADGE, BADGE)) +} + +/// Draw the badge for a pointer at `at` (None: the pointer is not over the model). +pub(crate) fn show(app: &SolveApp, painter: &egui::Painter, at: Option) { + let (Some(at), Some(icon)) = (at, icon(app)) else { return }; + let t = Tokens::get(); + // The readout's line height, as `tools::preview` lays it out. + let readout = painter.layout_no_wrap("0".into(), egui::FontId::proportional(t.font_small), t.text_dim).size().y; + let r = badge_rect(at, painter.clip_rect(), readout); + painter.rect(r, t.radius_sm, t.panel.gamma_multiply(0.92), Stroke::new(1.0, t.border), egui::StrokeKind::Inside); + crate::icons::paint_icon(painter, Rect::from_center_size(r.center(), vec2(ICON, ICON)), icon, 1.0); + crate::scenario::publish_rect("viewport:tool_cursor", r); +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::scenario::{Harness, rect_of}; + use serde_json::json; + + /// Rest the pointer on the middle of the viewport; the badge drawn there, if any. + fn hover_middle(h: &mut Harness) -> (Pos2, Option) { + let c = h.app.viewport.rect.map(|r| r.center()).unwrap(); + h.step(&json!({"move": [c.x, c.y]})).unwrap(); + h.frames(2); + (c, rect_of("viewport:tool_cursor")) + } + + fn icon_of(id: &str) -> &'static str { + solidcraft_engine::find_command(id).unwrap().icon + } + + #[test] + fn badge_shows_the_running_tool_beside_the_pointer() { + let mut h = Harness::new(); + h.settle(); + // Off by default: a running tool shows no badge until View settings turn it on. + assert!(!h.app.ui.tool_cursor, "the badge is on by default"); + h.step(&json!({"start": "sketch.create"})).unwrap(); + let (_, badge) = hover_middle(&mut h); + assert!(badge.is_none(), "off by default, yet a badge is drawn at {badge:?}"); + h.step(&json!({"key": "Escape"})).unwrap(); + h.settle(); + // Turned on with the checkbox in the navigation bar's View settings. + h.step(&json!({"click": {"handle": "nav:view"}})).unwrap(); + h.frames(2); + h.step(&json!({"click": {"handle": "view:tool_cursor"}})).unwrap(); + h.step(&json!({"click": {"handle": "nav:view"}})).unwrap(); + h.frames(2); + assert!(h.app.ui.tool_cursor, "the View settings checkbox did not turn the badge on"); + let (_, badge) = hover_middle(&mut h); + assert!(badge.is_none(), "no tool runs, yet a badge is drawn at {badge:?}"); + + // A dialog: Create Sketch waits for a plane. + h.step(&json!({"start": "sketch.create"})).unwrap(); + let (at, badge) = hover_middle(&mut h); + assert_eq!(icon(&h.app), Some(icon_of("sketch.create"))); + let badge = badge.unwrap(); + assert_eq!(badge.left_bottom(), at + OFFSET, "the badge sits above and right of the pointer"); + + // An interactive sketch tool. + h.step(&json!({"click": {"plane": "XY"}})).unwrap(); + h.settle(); + h.step(&json!({"start": "sketch.circle.center"})).unwrap(); + let (at, badge) = hover_middle(&mut h); + assert_eq!(icon(&h.app), Some(icon_of("sketch.circle.center"))); + let badge = badge.unwrap(); + // The coordinate readout starts READOUT below and right of the pointer: no overlap. + assert!(badge.bottom() < at.y + READOUT, "the badge {badge:?} covers the readout under {at:?}"); + + // Turned off in View settings. + h.app.ui.tool_cursor = false; + let (_, badge) = hover_middle(&mut h); + assert!(badge.is_none(), "turned off, yet a badge is drawn at {badge:?}"); + h.app.ui.tool_cursor = true; + + // Over the window's top edge, outside the viewport: nothing. + h.step(&json!({"move": [4.0, 4.0]})).unwrap(); + h.frames(2); + assert!(rect_of("viewport:tool_cursor").is_none(), "a badge is drawn outside the viewport"); + + // Escape ends the tool. + h.step(&json!({"key": "Escape"})).unwrap(); + h.settle(); + assert!(h.app.tool.is_none() && h.app.dialog.is_none(), "Escape left {:?} running", command(&h.app)); + let (_, badge) = hover_middle(&mut h); + assert!(badge.is_none(), "the tool ended, yet a badge is drawn at {badge:?}"); + } + + /// Wherever the pointer is, the badge stays inside the viewport and off the coordinate + /// readout (the rectangle from READOUT below right of the pointer, one line high). + #[test] + fn badge_stays_inside_the_viewport_and_off_the_readout() { + let bounds = Rect::from_min_size(Pos2::ZERO, vec2(800.0, 600.0)); + let line = 14.0; + let middle = Pos2::new(400.0, 300.0); + assert_eq!(badge_rect(middle, bounds, line).left_bottom(), middle + OFFSET); + for at in [middle, pos2(795.0, 300.0), pos2(400.0, 5.0), pos2(795.0, 5.0), pos2(5.0, 595.0), pos2(795.0, 595.0)] { + let badge = badge_rect(at, bounds, line); + assert!(bounds.contains_rect(badge), "at {at:?}: {badge:?} leaves {bounds:?}"); + let readout = Rect::from_min_size(at + vec2(READOUT, READOUT), vec2(120.0, line)); + assert!(!badge.intersects(readout), "at {at:?}: {badge:?} covers the readout {readout:?}"); + assert!(!badge.contains(at), "at {at:?}: {badge:?} covers the hot spot"); + } + } + + /// Every interactive tool's command has an icon to show. + #[test] + fn every_interactive_tool_has_a_badge_icon() { + let missing: Vec<&str> = solidcraft_engine::command_specs() + .iter() + .filter_map(|spec| crate::tools::Tool::for_command(spec.id).map(|tool| tool.cmd)) + .filter(|cmd| solidcraft_engine::find_command(cmd).is_none_or(|spec| spec.icon.is_empty())) + .collect(); + assert!(missing.is_empty(), "tools without a badge icon: {missing:?}"); + } +} diff --git a/crates/ui-egui/src/viewport.rs b/crates/ui-egui/src/viewport.rs index e7daaa345..688bf83e7 100644 --- a/crates/ui-egui/src/viewport.rs +++ b/crates/ui-egui/src/viewport.rs @@ -3665,6 +3665,15 @@ pub fn show(app: &mut SolveApp, ui: &mut egui::Ui) { let picture = crate::space_mouse_model::corner_rect(area, position, &obstacles); crate::space_mouse_model::corner(ui, picture, calibration, app.space_mouse.raw.into()); } + // Last, so it sits over the overlays; only where a click would reach the model. + let badge_at = hover.filter(|p| { + inside + && !navigating + && resp.hovered() + && ui.ctx().layer_id_at(*p).is_none_or(|layer| layer == ui.layer_id()) + && !crate::shell::covered(app, *p) + }); + crate::tool_cursor::show(app, &painter, badge_at); } fn paint_box_selection(painter: &egui::Painter, bx: BoxSel, sketch: bool) { @@ -4760,8 +4769,8 @@ fn nav_bar(app: &mut SolveApp, ui: &mut egui::Ui, rect: Rect) { ui.data_mut(|d| d.insert_temp(menu_id, menu_open)); } -/// The View settings above the navigation bar's last button: grid, ground shadow and the agent -/// cursor (#35). False once it should close (a click outside it). +/// The View settings above the navigation bar's last button: grid, ground shadow, the tool at +/// the cursor and the agent cursor (#35). False once it should close (a click outside it). fn view_menu(app: &mut SolveApp, ui: &mut egui::Ui, button: Rect) -> bool { let t = crate::theme::Tokens::get(); // A preset dropdown extends beyond this menu; let it consume its own clicks. @@ -4781,6 +4790,8 @@ fn view_menu(app: &mut SolveApp, ui: &mut egui::Ui, button: Rect) -> bool { crate::ui_kit::checkbox(ui, crate::i18n::tr_label("Grid"), &mut app.ui.show_grid); crate::ui_kit::checkbox(ui, crate::i18n::tr_label("Ground shadow"), &mut app.ui.ground_shadow); crate::prefs::ambient_occlusion_checkbox(app, ui, "Ambient occlusion"); + let tool = crate::ui_kit::checkbox(ui, crate::i18n::tr_label("Show tool at cursor"), &mut app.ui.tool_cursor); + crate::scenario::publish_handle("view:tool_cursor", tool.rect.center()); ui.separator(); let s = &mut app.ui.agent_cursor; let show = crate::ui_kit::checkbox(ui, crate::i18n::tr_label("Show Agent Cursor"), &mut s.show);