SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Ribbon: pressed state for commands that stay on (#8546) (#8555)
Nathan Daned95f40ac884e
diff --git a/assets/locales/pending/persistent-ribbon-pressed.json b/assets/locales/pending/persistent-ribbon-pressed.jsonnew file mode 100644index 0000000000..03e38be901--- /dev/null+++ b/assets/locales/pending/persistent-ribbon-pressed.json@@ -0,0 +1,34 @@+{+ "en": {+ "prefs.persistent_ribbon_pressed": "Highlight active ribbon commands",+ "prefs.persistent_ribbon_pressed_help": "Highlight ribbon commands while their effects are on. Turn off to keep the previous neutral appearance and command help."+ },+ "ar": {+ "prefs.persistent_ribbon_pressed": "تمييز أوامر الشريط النشطة",+ "prefs.persistent_ribbon_pressed_help": "تمييز أوامر الشريط أثناء تفعيل تأثيراتها. أوقف هذا الخيار للاحتفاظ بالمظهر المحايد السابق ومساعدة الأوامر."+ },+ "de": {+ "prefs.persistent_ribbon_pressed": "Aktive Menübandbefehle hervorheben",+ "prefs.persistent_ribbon_pressed_help": "Hebt Befehle im Menüband hervor, solange ihre Effekte eingeschaltet sind. Deaktivieren Sie diese Option, um die bisherige neutrale Darstellung und Befehlshilfe beizubehalten."+ },+ "he": {+ "prefs.persistent_ribbon_pressed": "הדגשת פקודות פעילות ברצועת הכלים",+ "prefs.persistent_ribbon_pressed_help": "הדגשת פקודות ברצועת הכלים כל עוד ההשפעות שלהן פעילות. כבו אפשרות זו כדי לשמור על המראה הניטרלי הקודם ועל עזרת הפקודות."+ },+ "ja": {+ "prefs.persistent_ribbon_pressed": "有効なリボンコマンドを強調表示",+ "prefs.persistent_ribbon_pressed_help": "効果が有効な間、リボンのコマンドを強調表示します。無効にすると、従来の中立的な表示とコマンドのヘルプを保持します。"+ },+ "ko": {+ "prefs.persistent_ribbon_pressed": "활성 리본 명령 강조 표시",+ "prefs.persistent_ribbon_pressed_help": "효과가 켜져 있는 동안 리본 명령을 강조 표시합니다. 끄면 이전의 중립적인 모양과 명령 도움말을 유지합니다."+ },+ "vi": {+ "prefs.persistent_ribbon_pressed": "Tô sáng lệnh đang bật trên dải băng",+ "prefs.persistent_ribbon_pressed_help": "Tô sáng các lệnh trên dải băng khi hiệu ứng của chúng đang bật. Tắt tùy chọn này để giữ giao diện trung tính và trợ giúp lệnh như trước."+ },+ "zh": {+ "prefs.persistent_ribbon_pressed": "突出显示已启用的功能区命令",+ "prefs.persistent_ribbon_pressed_help": "在效果启用时突出显示相应的功能区命令。关闭此选项可保留原来的中性外观和命令帮助。"+ }+}diff --git a/crates/ui-egui/src/prefs.rs b/crates/ui-egui/src/prefs.rsindex 1c597511e3..91846a3d53 100644--- a/crates/ui-egui/src/prefs.rs+++ b/crates/ui-egui/src/prefs.rs@@ -1060,6 +1060,8 @@ preference_settings! {navigation_bar: crate::navigation_bar::NavigationBar = Default::default(), PAGE_INTERFACE;/// Show command names beneath ribbon icons, independently of workspace layout.ribbon_labels: bool = true, PAGE_INTERFACE;+ /// Show engine-derived persistent selection in the ribbon; off retains neutral buttons.+ persistent_ribbon_pressed: bool = true, PAGE_INTERFACE => check_id("prefs.persistent_ribbon_pressed");/// Keep the SKETCH tab in the ribbon, right after MODEL, while no sketch is open; its drawing/// tools then start a sketch first (#7904).sketch_tab_always: bool = false, PAGE_INTERFACE => check_id("prefs.sketch_tab_always");@@ -4954,6 +4956,7 @@ mod tests {("ui_font", json!("test font"), PAGE_INTERFACE),("layout", json!("compact"), PAGE_INTERFACE),("ribbon_labels", json!(false), PAGE_INTERFACE),+ ("persistent_ribbon_pressed", json!(false), PAGE_INTERFACE),("sketch_tab_always", json!(true), PAGE_INTERFACE),("ribbon_reveal", json!(true), PAGE_INTERFACE),("dialog_buttons", json!("top"), PAGE_INTERFACE),@@ -6117,6 +6120,42 @@ mod tests {}}+ #[test]+ fn history_preferences_widget_click_reveals_scrolled_content_and_keeps_folds_closed() {+ let steps: serde_json::Value = serde_json::from_str(include_str!("../tests/scenarios/history_sketches_under_feature.json")).unwrap();+ let steps = steps.as_array().unwrap();+ let transition = steps.iter().position(|step| step["params"]["history_sketches"] == "under_feature").unwrap();+ let mut h = crate::scenario::Harness::new();+ for step in steps.iter().take(transition) {+ h.step(step).unwrap();+ }+ h.call("ui.prefs", json!({"open":"Interface"}));+ let at = h.widget("Under their feature").unwrap();+ let page = crate::scenario::rect_of("prefs:page_body").unwrap();+ assert!(!page.contains(egui::pos2(at[0] as f32, at[1] as f32)), "the real control begins scrolled out of view");+ assert_eq!(h.app.preferences.history_sketches, HistorySketches::InOrder);+ h.step(&json!({"widget":"Under their feature", "near":"Sketches"})).unwrap();+ assert_eq!(h.app.preferences.history_sketches, HistorySketches::UnderFeature);+ let at = h.widget("Under their feature").unwrap();+ assert!(crate::scenario::rect_of("prefs:page_body").unwrap().contains(egui::pos2(at[0] as f32, at[1] as f32)));+ assert!(h.app.tree.expanded.is_empty(), "revealing a preference does not open history folds");+ let page_before = crate::scenario::rect_of("prefs:page_body");+ h.step(&json!({"widget":"Apply"})).unwrap();+ assert!(h.app.prefs_window.open);+ assert_eq!(crate::scenario::rect_of("prefs:page_body"), page_before);+ h.step(&json!({"widget":"OK"})).unwrap();+ h.step(&steps[transition + 1]).unwrap();+ assert!(!h.app.prefs_window.open);+ for step in steps.iter().skip(transition + 2) {+ h.step(step).unwrap();+ }+ h.call("ui.prefs", json!({"open":"Interface"}));+ h.step(&json!({"widget":"Navigation"})).unwrap();+ assert_eq!(h.app.prefs_window.section, PAGE_NAVIGATION, "sidebar navigation remains a real click");+ h.step(&json!({"widget":"Cancel"})).unwrap();+ assert!(!h.app.prefs_window.open);+ }+#[test]fn history_sketches_defaults_in_order_and_follows_preferences_transactions() {let old: Prefs = serde_json::from_value(json!({"timeline_left": true})).unwrap();@@ -6265,6 +6304,38 @@ mod tests {assert_eq!(app.session.undo.len(), undo);}+ #[test]+ fn persistent_ribbon_pressed_preference_checkbox_control_persists_cancels_and_resets() {+ assert!(Prefs::default().persistent_ribbon_pressed);+ assert!(lenient(&json!({"theme":"light"})).persistent_ribbon_pressed);+ assert!(lenient(&json!({"persistent_ribbon_pressed":"no"})).persistent_ribbon_pressed);+ let mut h = crate::scenario::Harness::new();+ let design = h.app.session.doc.to_json();+ let revision = h.app.session.revision;+ h.call("ui.prefs", json!({"open":"Interface"}));+ super::reveal_preference(&mut h, "prefs:persistent_ribbon_pressed");+ let checkbox = crate::scenario::handle_at("prefs:persistent_ribbon_pressed").unwrap();+ h.call("ui.click", json!({"x":checkbox.x,"y":checkbox.y}));+ assert!(!h.app.preferences.persistent_ribbon_pressed);+ assert_eq!(h.call("ui.prefs", json!({}))["result"]["persistent_ribbon_pressed"], false);+ let mut restored = SolveApp::new(Default::default(), Default::default());+ restored.load_prefs(&h.app.prefs());+ assert!(!restored.preferences.persistent_ribbon_pressed);+ h.call("ui.prefs", json!({"button":"cancel"}));+ assert!(h.app.preferences.persistent_ribbon_pressed);+ h.call("ui.prefs", json!({"open":"Interface","persistent_ribbon_pressed":false,"button":"apply"}));+ h.call("ui.prefs", json!({"button":"defaults"}));+ assert!(h.app.preferences.persistent_ribbon_pressed);+ h.call("ui.prefs", json!({"button":"cancel"}));+ assert!(!h.app.preferences.persistent_ribbon_pressed);+ for malformed in [json!("false"), json!(null), json!(0), json!([])] {+ assert!(super::set(&mut h.app, &json!({"persistent_ribbon_pressed":malformed})).is_err());+ assert!(!h.app.preferences.persistent_ribbon_pressed);+ }+ assert_eq!(h.app.session.revision, revision);+ assert_eq!(h.app.session.doc.to_json(), design);+ }+#[test]fn single_surface_analysis_preference_checkbox_persists_cancels_and_resets() {assert!(Prefs::default().single_surface_analysis);diff --git a/crates/ui-egui/src/prefs/interface.rs b/crates/ui-egui/src/prefs/interface.rsindex 6a98c12f39..c46a48c256 100644--- a/crates/ui-egui/src/prefs/interface.rs+++ b/crates/ui-egui/src/prefs/interface.rs@@ -94,6 +94,10 @@ pub(super) fn interface(app: &mut SolveApp, ui: &mut egui::Ui, t: &Tokens) {app.preferences.ribbon_labels = selected == 0;}});+ ui_kit::row(ui, "", |ui| {+ let check = setting::persistent_ribbon_pressed(app, ui).on_hover_text(app.tr("prefs.persistent_ribbon_pressed_help"));+ crate::scenario::publish_target("prefs:persistent_ribbon_pressed", check.rect);+ });// The SKETCH tab outside a sketch too (#7904).ui_kit::row(ui, "", |ui| {let check = setting::sketch_tab_always(app, ui).on_hover_text(app.tr("prefs.sketch_tab_always_note"));diff --git a/crates/ui-egui/src/scenario.rs b/crates/ui-egui/src/scenario.rsindex 16f9897a96..ada0605f4e 100644--- a/crates/ui-egui/src/scenario.rs+++ b/crates/ui-egui/src/scenario.rs@@ -355,6 +355,34 @@ impl Harness {})}+ /// Accessibility bounds include scrolled-out page content. Reveal that content with+ /// wheel input before using its coordinates; window actions and navigation stay put.+ fn reveal_widget(&mut self, text: &str, near: Option<&str>) -> Result<[f64; 2], String> {+ let find = |h: &Self| match near {+ Some(label) => h.widget_near(text, label),+ None => h.widget(text),+ };+ for _ in 0..32 {+ let point = find(self).ok_or_else(|| format!("no widget `{text}` on screen"))?;+ let at = egui::pos2(point[0] as f32, point[1] as f32);+ let page = self.app.prefs_window.open.then(|| rect_of("prefs:page_body")).flatten();+ let chrome = ["prefs:ok", "prefs:apply", "prefs:cancel", "prefs:search"].iter().any(|key| handle_at(key) == Some(at));+ let Some(page) = page.filter(|page| !chrome && page.x_range().contains(at.x)) else { return Ok(point) };+ if page.contains(at) {+ return Ok(point);+ }+ self.call("ui.scroll", json!({"x":page.center().x,"y":page.center().y,"delta":if at.y < page.top() {100} else {-100}}));+ // Follow the wheel's actual smoothing, rather than clicking its moving content.+ for _ in 0..120 {+ if self.ctx.input(|input| !input.is_scrolling()) {+ break;+ }+ self.frame();+ }+ }+ Err(format!("widget `{text}` could not be revealed in its page"))+ }+/// Centres of the visible widgets whose label or value is `text`, last drawn first.fn widgets(&self, text: &str) -> Vec<[f64; 2]> {let Some(tree) = self.output.accesskit_update.as_ref() else { return Vec::new() };@@ -457,12 +485,10 @@ impl Harness {self.call("ui.click", p)} else if let Some(text) = s.get("widget").and_then(Value::as_str) {// A dialog field, choice or button, found by its text.- let found = match s.get("near").and_then(Value::as_str) {- Some(near) => self.widget_near(text, near),- None => self.widget(text),- };- let [x, y] = found.ok_or_else(|| format!("no widget `{text}` on screen"))?;+ let near = s.get("near").and_then(Value::as_str);+ let [x, y] = self.reveal_widget(text, near)?;self.call("ui.move", json!({"x": x, "y": y}));+ let [x, y] = self.reveal_widget(text, near)?;self.call("ui.click", json!({"x": x, "y": y}))} else if let Some(at) = s.get("hold") {// Press and hold still (Select Other): `frames` with the button down (default 40,diff --git a/crates/ui-egui/src/toolbar.rs b/crates/ui-egui/src/toolbar.rsindex e39d502e79..eadcd07be4 100644--- a/crates/ui-egui/src/toolbar.rs+++ b/crates/ui-egui/src/toolbar.rs@@ -986,11 +986,117 @@ fn ribbon_label_lines(painter: &egui::Painter, label: &str, width: f32) -> Vec<Slines}+/// Commands opt into persistent presentation; the engine status list remains the only truth.+const PERSISTENT_COMMANDS: &[&str] =+ &["inspect.accessibility", "inspect.continuity", "inspect.curvature_map", "inspect.draft", "inspect.environment_map", "inspect.zebra"];++fn persistent_command(id: &str) -> bool {+ PERSISTENT_COMMANDS.contains(&id)+}++fn persistent_pressed(app: &SolveApp, id: &str) -> bool {+ app.preferences.persistent_ribbon_pressed && persistent_command(id) && app.session.status_items().iter().any(|item| item.command == id)+}++fn persistent_button_name(app: &SolveApp, command: &solidcraft_engine::CommandSpec) -> String {+ let info = crate::render_workspace::interactive_command_info(app, command);+ let label = crate::workspace::ribbon_button_label(command);+ app.tr_label(if label == command.label { info.label } else { label }).to_string()+}++fn persistent_hint(app: &SolveApp, command: &solidcraft_engine::CommandSpec, enabled: bool) -> Option<String> {+ (enabled && persistent_pressed(app, command.id)).then(|| {+ let name = persistent_button_name(app, command);+ crate::i18n::Locale::for_language(&app.preferences.language).format("ui.viewport_status_clear_hint", &[("name", &name)])+ })+}++/// Paint slots retain original z-order, while their presentation is resolved after every+/// command interaction in this ribbon pass. These records never survive the current frame.+struct PersistentRibbonPaint {+ command: &'static solidcraft_engine::CommandSpec,+ response: egui::Response,+ rect: Rect,+ background: egui::layers::ShapeIdx,+ label_slot: egui::layers::ShapeIdx,+ neutral: egui::Shape,+ label: Option<String>,+ enabled: bool,+ disabled: Option<String>,+}++fn paint_persistent_ribbon(app: &SolveApp, ui: &egui::Ui, paints: Vec<PersistentRibbonPaint>, tab: &str) {+ let t = Tokens::get();+ let items = app.session.status_items();+ let mut count = 0;+ for paint in paints {+ let selected = app.preferences.persistent_ribbon_pressed && items.iter().any(|item| item.command == paint.command.id);+ let ink = if !paint.enabled {+ t.text_dim+ } else if selected {+ t.selected_ink+ } else {+ t.text+ };+ // Resolve the genuine live tool after dispatch too: a click may have ended it.+ // The compatibility presentation keeps its original transient recipe.+ let neutral = if app.preferences.persistent_ribbon_pressed && app.tool.as_ref().is_some_and(|tool| tool.cmd == paint.command.id) {+ let accent = crate::theme::TabAccent::for_tab(&t, tab);+ egui::Shape::Rect(egui::epaint::RectShape::new(+ paint.rect,+ t.radius_sm,+ accent.soft,+ Stroke::new(1.0, accent.color),+ egui::StrokeKind::Inside,+ ))+ } else {+ paint.neutral+ };+ let background = if selected {+ count += 1;+ crate::scenario::publish_target(&format!("ribbon:pressed:{}", paint.command.id), paint.rect);+ ui_kit::persistent_button_shape(ui, &paint.response, paint.rect)+ } else if paint.response.has_focus() && app.preferences.persistent_ribbon_pressed {+ egui::Shape::Vec(vec![neutral, ui_kit::native_button_focus(ui, &paint.response, paint.rect)])+ } else {+ neutral+ };+ ui.painter().set(paint.background, background);+ if paint.response.has_focus() {+ crate::scenario::publish_target(&format!("ribbon:focus:{}", paint.command.id), paint.rect);+ }+ if let Some(label) = paint.label {+ let galley = ribbon_button_galley_weight(ui.painter(), &label, paint.rect.width() - BUTTON_LABEL_PADDING, ink, selected);+ ui.painter()+ .set(paint.label_slot, egui::Shape::galley(pos2(paint.rect.center().x, ribbon_label_top(paint.rect, galley.size().y)), galley, ink));+ }+ paint.response.widget_info(|| {+ if app.preferences.persistent_ribbon_pressed {+ egui::WidgetInfo::selected(egui::WidgetType::Button, paint.enabled, selected, persistent_button_name(app, paint.command))+ } else {+ let info = crate::render_workspace::interactive_command_info(app, paint.command);+ egui::WidgetInfo::labeled(egui::WidgetType::Button, paint.enabled, app.tr_label(info.label))+ }+ });+ let _ = ribbon_tooltip(app, paint.response, paint.command, paint.disabled.as_deref());+ }+ crate::scenario::publish_count("ribbon:pressed", count as f64);+}+fn ribbon_button_galley(painter: &egui::Painter, label: &str, width: f32, color: Color32) -> std::sync::Arc<egui::Galley> {+ ribbon_button_galley_weight(painter, label, width, color, false)+}++fn ribbon_button_galley_weight(painter: &egui::Painter, label: &str, width: f32, color: Color32, selected: bool) -> std::sync::Arc<egui::Galley> {let lines = ribbon_button_lines(painter, label, width);// Explicit newlines only: egui must never split an oversized word.let size = crate::theme::Tokens::get().font_body;- let mut job = egui::text::LayoutJob::simple(lines.join("\n"), FontId::proportional(size), color, f32::INFINITY);+ let mut job = egui::text::LayoutJob::simple(+ lines.join("\n"),+ if selected { crate::fonts::semibold(size) } else { FontId::proportional(size) },+ color,+ f32::INFINITY,+ );job.halign = egui::Align::Center;// Two lines sit closer than the font's own spacing, so they fit in the button under its// icon (#8391).@@ -1347,6 +1453,7 @@ pub fn toolbar(app: &mut SolveApp, ui: &mut egui::Ui) {if reveal.is_some() {ui.ctx().request_repaint();}+ let mut persistent_paints = Vec::new();let mut px = ribbon_left;let top = r.top() + TAB_ROW_HEIGHT;let mut drop: Option<(&'static str, &'static str, Option<&'static str>)> = None;@@ -1533,17 +1640,30 @@ pub fn toolbar(app: &mut SolveApp, ui: &mut egui::Ui) {if resp.secondary_clicked() {menu = Some((resp.interact_pointer_pos().unwrap_or(br.left_bottom()), c.id));}+ let persistent = persistent_command(selected.id);+ let background_slot = painter.add(egui::Shape::Noop);let accent = crate::theme::TabAccent::for_tab(&t, &tab);let family_open = family.is_some_and(|f| egui::Popup::is_id_open(ui.ctx(), ui.id().with(("family", f.label)).with("popup")));- if !finish+ let neutral = if !finish&& (resp.is_pointer_button_down_on()- || running.as_deref() == Some(selected.id)+ || (running.as_deref() == Some(selected.id) && !(persistent && app.preferences.persistent_ribbon_pressed))|| family_open|| (selected.id == "view.shots_strip" && app.preferences.render_shots_strip)){- painter.rect(whole, t.radius_sm, accent.soft, Stroke::new(1.0, accent.color), egui::StrokeKind::Inside);+ egui::Shape::Rect(egui::epaint::RectShape::new(+ whole,+ t.radius_sm,+ accent.soft,+ Stroke::new(1.0, accent.color),+ egui::StrokeKind::Inside,+ ))} else if resp.hovered() && info.enabled {- painter.rect_filled(whole, t.radius_sm, t.hover);+ egui::Shape::rect_filled(whole, t.radius_sm, t.hover)+ } else {+ egui::Shape::Noop+ };+ if !persistent {+ painter.set(background_slot, neutral.clone());}let revealed = reveal.as_ref().filter(|r| r.id == c.id || r.id == selected.id || family.is_some_and(|f| f.commands.contains(&r.id)));if revealed.is_some() {@@ -1561,12 +1681,34 @@ pub fn toolbar(app: &mut SolveApp, ui: &mut egui::Ui) {Rect::from_center_size(pos2(br.center().x, whole.top() + if labels { 16.0 } else { button_height / 2.0 }), vec2(side, side));icons::paint_icon(&painter, icon_rect, icon, if info.enabled { 1.0 } else { 0.35 });let tr_label = app.tr_label(info.label).to_string();- resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, ui.is_enabled() && info.enabled, &tr_label));- if ribbon_tooltip(app, resp, selected, info.disabled_reason.as_deref()).clicked() && info.enabled {+ if !persistent {+ resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, ui.is_enabled() && info.enabled, &tr_label));+ }+ let clicked = resp.clicked();+ if !persistent {+ let _ = ribbon_tooltip(app, resp.clone(), selected, info.disabled_reason.as_deref());+ }+ if clicked && info.enabled {+ if persistent && app.preferences.persistent_ribbon_pressed {+ resp.request_focus();+ }let id = selected.id;app.start_pinned(id, Some(whole));}- if let Some(f) = family {+ if persistent {+ let label = persistent_button_name(app, selected);+ persistent_paints.push(PersistentRibbonPaint {+ command: selected,+ response: resp,+ rect: whole,+ background: background_slot,+ label_slot: painter.add(egui::Shape::Noop),+ neutral,+ label: labels.then_some(label),+ enabled: ui.is_enabled() && info.enabled,+ disabled: info.disabled_reason.clone(),+ });+ } else if let Some(f) = family {let ar = if labels {Rect::from_min_max(pos2(whole.left(), whole.top() + 30.0), pos2(whole.right(), whole.top() + 48.0))} else {@@ -1854,14 +1996,18 @@ pub fn toolbar(app: &mut SolveApp, ui: &mut egui::Ui) {}for c in cmds {let info = crate::render_workspace::interactive_command_info(app, c);- let response = crate::ui_kit::command_menu_button(- ui,- c.id,- info.label,- info.icon,- &crate::keymap::display_for(app, c.id).unwrap_or_default(),- info.enabled,- );+ let shortcut = crate::keymap::display_for(app, c.id).unwrap_or_default();+ let response = if persistent_command(c.id) && app.preferences.persistent_ribbon_pressed {+ let mut item = ui_kit::MenuItem::new(c.id, info.label, info.icon);+ item.shortcut = &shortcut;+ item.enabled = info.enabled;+ item.checked = Some(persistent_pressed(app, c.id));+ item.show(ui)+ } else {+ ui_kit::command_menu_button(ui, c.id, info.label, info.icon, &shortcut, info.enabled)+ };+ let response =+ if let Some(hint) = persistent_hint(app, c, info.enabled) { response.on_hover_text(hint) } else { response };crate::scenario::publish_handle(&format!("toolbar:{}", c.id), response.rect.center());if response.clicked() {app.start_at(c.id, Some(response.rect));@@ -1876,6 +2022,10 @@ pub fn toolbar(app: &mut SolveApp, ui: &mut egui::Ui) {});}+ // Resolve persistent paint only after large buttons, dropdowns and overflow have+ // dispatched their actions. No already-painted old analysis can survive replacement.+ paint_persistent_ribbon(app, ui, persistent_paints, &tab);+// Dragging a command: its icon follows the pointer; a toolbar button dragged off the// toolbar (or into the open drop-down) shows it will be removed.let pointer = ui.input(|i| i.pointer.latest_pos());@@ -1959,6 +2109,9 @@ const CONSTRAINT_GRID_WIDTH: f32 = 82.0;/// Registry parameter syntax is not a user-facing description. Reuse existing catalog prose/// where present; other commands intentionally show only their name and registered shortcut.fn ribbon_tooltip(app: &SolveApp, response: egui::Response, command: &solidcraft_engine::CommandSpec, disabled: Option<&str>) -> egui::Response {+ if let Some(hint) = persistent_hint(app, command, disabled.is_none() && response.enabled() && command.info(&app.session).enabled) {+ return response.on_hover_text(hint);+ }response.on_hover_ui(|ui| {let t = Tokens::get();let name = app.tr_label(crate::render_workspace::interactive_command_info(app, command).label);@@ -2133,6 +2286,9 @@ fn dropdown_row(let hot = info.enabled && (pointer_on || resp.has_focus());let mut row = crate::ui_kit::MenuItem::new(c.id, &label, info.icon);row.enabled = info.enabled;+ if persistent_command(c.id) && app.preferences.persistent_ribbon_pressed {+ row.checked = Some(persistent_pressed(app, c.id));+ }if c.id == "view.shots_strip" {row.checked = Some(app.preferences.render_shots_strip);}@@ -2165,9 +2321,13 @@ fn dropdown_row(}// A disabled row says why; a documented command also shows its help (#2758).let reason = info.disabled_reason.as_deref().filter(|_| !info.enabled).map(|reason| app.tr_label(reason));- let resp = match crate::command_help::row_tip(c.id, &label, Some(shortcut.as_str()).filter(|k| !k.is_empty()), reason) {- Some(tip) => crate::command_help::tooltip(resp, c.id, tip),- None => resp,+ let resp = if let Some(hint) = persistent_hint(app, c, info.enabled) {+ resp.on_hover_text(hint)+ } else {+ match crate::command_help::row_tip(c.id, &label, Some(shortcut.as_str()).filter(|k| !k.is_empty()), reason) {+ Some(tip) => crate::command_help::tooltip(resp, c.id, tip),+ None => resp,+ }};if resp.secondary_clicked() {return RowAction::Menu(resp.interact_pointer_pos().unwrap_or(rect.left_bottom()));@@ -4167,3 +4327,375 @@ mod sketch_return_tab_tests {assert_eq!(h.app.ui.tab, "MODEL", "{start}: falls back to MODEL");}}++#[cfg(test)]+mod persistent_ribbon_tests {+ use super::*;+ use crate::scenario::{self, Harness};++ fn harness() -> Harness {+ let mut h = Harness::new();+ h.app.home.open = false;+ h.call("ui.resize", json!({"width":2400,"height":1000}));+ h.app.session.execute("solid.box", &json!({"length":10,"width":10,"height":10})).unwrap();+ h.app.ui.tab = "INSPECT".into();+ for id in PERSISTENT_COMMANDS {+ crate::toolbar_custom::pin(&mut h.app, "INSPECT", id).unwrap();+ }+ h.frames(3);+ h+ }++ fn shapes(shape: &egui::Shape, out: &mut Vec<egui::Shape>) {+ match shape {+ egui::Shape::Vec(v) => {+ for s in v {+ shapes(s, out);+ }+ }+ s => out.push(s.clone()),+ }+ }++ fn button_shapes(h: &Harness, id: &str) -> Vec<egui::Shape> {+ let r = scenario::rect_of(&format!("button:{id}")).unwrap();+ let mut all = Vec::new();+ for s in &h.shapes {+ shapes(&s.shape, &mut all);+ }+ all.into_iter().filter(|s| r.intersects(s.visual_bounding_rect())).collect()+ }++ fn assert_paint(h: &Harness, id: &str, selected: bool) {+ assert_presentation(h, id, selected, true);+ }++ fn assert_presentation(h: &Harness, id: &str, selected: bool, check_fill: bool) {+ let r = scenario::rect_of(&format!("button:{id}")).unwrap();+ let t = Tokens::get();+ let shapes = button_shapes(h, id);+ if check_fill {+ assert_eq!(+ shapes.iter().any(|s| matches!(s, egui::Shape::Rect(s) if s.rect == r && s.fill == t.selected_bg)),+ selected,+ "{id} selected fill"+ );+ }+ assert_eq!(shapes.iter().any(|s| matches!(s, egui::Shape::LineSegment { points, stroke } if stroke.width == 2.0 && stroke.color == t.accent && points[0].y == r.bottom() - t.space_4)), selected, "{id} underline");+ if h.app.preferences.ribbon_labels {+ let text = shapes+ .iter()+ .find_map(|s| match s {+ egui::Shape::Text(s) if r.contains(s.pos) => Some(s),+ _ => None,+ })+ .unwrap_or_else(|| panic!("missing {id} label"));+ let font = &text.galley.job.sections[0].format.font_id;+ assert_eq!(*font, if selected { crate::fonts::semibold(t.font_body) } else { FontId::proportional(t.font_body) });+ assert_eq!(text.galley.job.sections[0].format.color, if selected { t.selected_ink } else { t.text });+ }+ }++ fn tap(h: &mut Harness, id: &str) {+ let at = scenario::handle_at(&format!("button:{id}")).unwrap();+ let before = h.app.session.status_items();+ h.frame_with(crate::test_support::pointer(at, true));+ assert_eq!(h.app.session.status_items(), before, "pointer-down is not a persistent activation");+ for command in PERSISTENT_COMMANDS {+ // Existing pointer-down paint is transient and may use the same palette fill.+ // The underline, actual weight and published identities distinguish persistence.+ assert_presentation(h, command, before.iter().any(|item| item.command == *command), *command != id);+ assert_eq!(scenario::handle_at(&format!("ribbon:pressed:{command}")).is_some(), before.iter().any(|item| item.command == *command));+ }+ h.frame_with(crate::test_support::pointer(at, false));+ }++ #[test]+ fn persistent_pressed_and_search_pulse_keep_independent_effect_and_paint_authority() {+ let mut h = harness();+ for enabled in [true, false] {+ h.call("ui.prefs", json!({"persistent_ribbon_pressed":enabled,"ribbon_reveal":true}));+ h.app.sbox.reveal = Some(crate::shortcut_box::Reveal {+ id: "inspect.zebra",+ since: h.ctx.input(|input| input.time) - crate::shortcut_box::REVEAL_PULSE / 4.0,+ preview: false,+ back: "INSPECT".into(),+ });+ h.frame();+ let zebra = scenario::rect_of("button:inspect.zebra").unwrap();+ assert_eq!(scenario::rect_of("ribbon:reveal"), Some(zebra));+ assert!(h.app.session.status_items().is_empty(), "a search pulse does not activate an effect");+ assert_presentation(&h, "inspect.zebra", false, false);+ h.app.session.execute("inspect.zebra", &json!({})).unwrap();+ h.frame();+ assert_presentation(&h, "inspect.zebra", enabled, enabled);+ let accent = crate::theme::TabAccent::for_tab(&Tokens::get(), "INSPECT");+ assert!(button_shapes(&h, "inspect.zebra").iter().any(|shape| matches!(shape, egui::Shape::Rect(rect) if rect.rect == zebra && rect.stroke.width == 2.0 && rect.stroke.color == accent.color.gamma_multiply(h.app.sbox.reveal.as_ref().unwrap().strength(h.ctx.input(|input| input.time), h.ctx.global_style().animation_time > 0.0)))), "the upstream pulse remains painted above the selected background");+ for (id, active) in [("inspect.draft", true), ("inspect.draft", false)] {+ let at = scenario::handle_at(&format!("button:{id}")).unwrap();+ h.frame_with(crate::test_support::pointer(at, true));+ h.frame_with(crate::test_support::pointer(at, false));+ assert_presentation(&h, "inspect.zebra", false, false);+ assert_eq!(h.app.session.status_items().iter().any(|item| item.command == id), active);+ assert_paint(&h, id, active && enabled);+ assert_eq!(scenario::rect_of("ribbon:reveal"), Some(zebra));+ }+ assert!(h.app.session.status_items().is_empty());+ h.app.sbox.reveal = None;+ h.frame();+ assert!(scenario::rect_of("ribbon:reveal").is_none());+ }+ }++ #[test]+ fn persistent_commands_derive_all_six_programmatic_effects_and_clear_without_residue() {+ let mut h = harness();+ for id in PERSISTENT_COMMANDS {+ assert!(!persistent_pressed(&h.app, id));+ h.app.session.execute(id, &json!({})).unwrap();+ h.frame(); // Exactly the first output following the engine mutation.+ assert_eq!(h.app.session.status_items().iter().map(|s| s.command.as_str()).collect::<Vec<_>>(), [*id]);+ for c in PERSISTENT_COMMANDS {+ assert_paint(&h, c, c == id);+ }+ let before = h.app.session.status_items();+ let revision = h.app.session.revision;+ h.frame();+ assert_eq!(h.app.session.status_items(), before);+ assert_eq!(h.app.session.revision, revision);+ h.app.session.execute(id, &json!({"clear":true})).unwrap();+ h.frame();+ assert_paint(&h, id, false);+ }+ for id in ["inspect.minimum_radius", "solid.extrude", "inspect.section"] {+ assert!(!persistent_command(id));+ }+ h.app.session.execute("inspect.zebra", &json!({})).unwrap();+ let before = h.app.session.status_items();+ assert!(h.app.session.execute("inspect.draft", &json!({"pull":[0,0,0]})).is_err());+ h.frame();+ assert_eq!(h.app.session.status_items(), before);+ assert_paint(&h, "inspect.zebra", true);+ }++ #[test]+ fn persistent_replacement_and_toggle_are_correct_in_the_click_release_frame_both_directions() {+ for labels in [true, false] {+ let mut h = harness();+ h.app.preferences.ribbon_labels = labels;+ crate::toolbar_custom::reorder(&mut h.app, "INSPECT", "inspect.draft", "SURFACE QUALITY", Some("inspect.zebra"));+ h.frames(2);+ for id in ["inspect.zebra", "inspect.draft", "inspect.zebra", "inspect.continuity", "inspect.environment_map"] {+ tap(&mut h, id); // No settling frame after release.+ assert_eq!(h.app.session.status_items().iter().map(|s| s.command.as_str()).collect::<Vec<_>>(), [id]);+ for c in PERSISTENT_COMMANDS {+ assert_paint(&h, c, *c == id);+ }+ let c = solidcraft_engine::find_command(id).unwrap();+ assert_eq!(+ persistent_hint(&h.app, c, true),+ Some(format!("Turn off {} · Esc", h.app.tr_label(crate::workspace::ribbon_button_label(c))))+ );+ }+ tap(&mut h, "inspect.environment_map");+ assert!(h.app.session.status_items().is_empty());+ assert_paint(&h, "inspect.environment_map", false);+ tap(&mut h, "inspect.continuity");+ tap(&mut h, "inspect.continuity");+ assert!(h.app.session.status_items().is_empty());+ assert_paint(&h, "inspect.continuity", false);+ }+ }++ #[test]+ fn persistent_presentation_preference_preserves_old_help_and_legacy_two_effects() {+ let mut h = harness();+ h.call("ui.prefs", json!({"single_surface_analysis":false}));+ h.app.session.execute("inspect.zebra", &json!({})).unwrap();+ h.app.session.execute("inspect.continuity", &json!({})).unwrap();+ h.frame();+ assert_eq!(h.app.session.status_items().len(), 2);+ assert_paint(&h, "inspect.zebra", true);+ assert_paint(&h, "inspect.continuity", true);+ let before = h.app.session.status_items();+ h.app.preferences.persistent_ribbon_pressed = false;+ h.frame();+ for id in PERSISTENT_COMMANDS {+ assert_paint(&h, id, false);+ }+ assert_eq!(h.app.session.status_items(), before);+ let label = h.app.tr_label(solidcraft_engine::find_command("inspect.zebra").unwrap().info(&h.app.session).label);+ let old_node = h+ .output+ .accesskit_update+ .as_ref()+ .and_then(|tree| tree.nodes.iter().find(|(_, n)| n.label() == Some(label)))+ .map(|(_, n)| n)+ .expect("old neutral accessible button label");+ assert_eq!(old_node.toggled(), None, "the old presentation makes no false inactive-effect announcement");+ assert!(persistent_hint(&h.app, solidcraft_engine::find_command("inspect.zebra").unwrap(), true).is_none());+ h.app.preferences.persistent_ribbon_pressed = true;+ h.frame();+ assert_paint(&h, "inspect.zebra", true);+ assert_paint(&h, "inspect.continuity", true);+ h.app.last_command = Some(("inspect.draft".into(), "Draft".into()));+ h.frame();+ assert_paint(&h, "inspect.draft", false);+ assert!(persistent_hint(&h.app, solidcraft_engine::find_command("inspect.zebra").unwrap(), false).is_none());+ }++ #[test]+ fn persistent_selected_shapes_and_real_semibold_survive_every_colour_vision_mode() {+ let mut h = harness();+ h.app.session.execute("inspect.zebra", &json!({})).unwrap();+ for dark in [false, true] {+ for vision in ["off", "protan", "deutan", "tritan"] {+ h.call("ui.prefs", json!({"theme":if dark { "dark" } else { "light" },"color_vision":vision}));+ h.frame();+ assert_paint(&h, "inspect.zebra", true);+ assert_paint(&h, "inspect.curvature_map", false);+ }+ }+ let painter = h.ctx.layer_painter(egui::LayerId::background());+ let plain = ribbon_button_galley_weight(&painter, "Zebra", 150.0, Tokens::get().text, false);+ let heavy = ribbon_button_galley_weight(&painter, "Zebra", 150.0, Tokens::get().text, true);+ assert!((plain.size().x - heavy.size().x).abs() > 0.1, "actual 600-weight face has different glyph metrics");+ }++ #[test]+ fn persistent_keyboard_focus_uses_native_response_and_clears_with_space() {+ let mut h = harness();+ h.app.session.execute("inspect.zebra", &json!({})).unwrap();+ h.frame();+ let at = scenario::handle_at("button:inspect.zebra").unwrap();+ // A pointer press establishes the real existing response's keyboard focus.+ h.frame_with(crate::test_support::pointer(at, true));+ h.frame_with(crate::test_support::pointer(at, false));+ let id = h.ctx.memory(|m| m.focused()).expect("native ribbon response is focusable");+ assert!(h.app.session.status_items().is_empty());+ h.ctx.memory_mut(|m| m.request_focus(id));+ h.frame_with(crate::test_support::key(egui::Key::Space));+ assert_eq!(h.app.session.status_items().len(), 1);+ assert_paint(&h, "inspect.zebra", true);+ assert!(scenario::rect_of("ribbon:focus:inspect.zebra").is_some());+ let node = h+ .output+ .accesskit_update+ .as_ref()+ .and_then(|tree| tree.nodes.iter().find(|(_, n)| n.label() == Some("Zebra")))+ .map(|(_, n)| n)+ .expect("accessible native Zebra button");+ assert_eq!(node.role(), egui::accesskit::Role::Button);+ assert_eq!(node.toggled(), Some(egui::accesskit::Toggled::True));+ }++ #[test]+ fn persistent_tooltip_is_the_exact_translated_visible_label_and_old_help_is_reachable() {+ let mut h = harness();+ h.app.session.execute("inspect.zebra", &json!({})).unwrap();+ for language in ["en", "de", "ja"] {+ h.call("ui.prefs", json!({"language":language}));+ let command = solidcraft_engine::find_command("inspect.zebra").unwrap();+ let name = h.app.tr_label(crate::workspace::ribbon_button_label(command));+ let expected = crate::i18n::Locale::for_language(language).format("ui.viewport_status_clear_hint", &[("name", name)]);+ assert_eq!(persistent_hint(&h.app, command, true), Some(expected.clone()));+ let at = scenario::handle_at("button:inspect.zebra").unwrap();+ h.frame_with(vec![egui::Event::PointerMoved(at)]);+ h.frames(100);+ let mut all = Vec::new();+ for shape in &h.shapes {+ shapes(&shape.shape, &mut all);+ }+ assert!(all.iter().any(|s| matches!(s, egui::Shape::Text(t) if t.galley.text() == expected)), "actual tooltip {expected}");+ }+ h.app.preferences.persistent_ribbon_pressed = false;+ h.frame_with(vec![egui::Event::PointerMoved(egui::Pos2::ZERO)]);+ h.frame_with(vec![egui::Event::PointerMoved(scenario::handle_at("button:inspect.zebra").unwrap())]);+ h.frames(100);+ assert!(persistent_hint(&h.app, solidcraft_engine::find_command("inspect.zebra").unwrap(), true).is_none());+ assert_paint(&h, "inspect.zebra", false);+ }++ #[test]+ fn persistent_dropdown_clear_keeps_native_pin_and_command_routes() {+ let mut h = harness();+ h.app.session.execute("inspect.environment_map", &json!({})).unwrap();+ h.frame();+ h.step(&json!({"click":{"handle":"panel:INSPECT:SURFACE QUALITY"}})).unwrap();+ assert!(scenario::handle_at("dropdown:inspect.environment_map").is_some());+ h.step(&json!({"click":{"handle":"dropdown:inspect.environment_map"}})).unwrap();+ assert!(h.app.session.status_items().is_empty());+ assert_paint(&h, "inspect.environment_map", false);+ }++ #[test]+ fn persistent_registration_preserves_live_continuity_tool_without_a_status_item() {+ let mut h = harness();+ h.app.start("inspect.continuity");+ assert_eq!(h.app.tool.as_ref().map(|tool| tool.cmd), Some("inspect.continuity"));+ h.app.session.execute("inspect.continuity", &json!({"clear":true})).unwrap();+ h.frame();+ assert!(h.app.session.status_items().is_empty());+ assert_eq!(scenario::count_of("ribbon:pressed"), Some(0.0));+ assert_presentation(&h, "inspect.continuity", false, false);+ let r = scenario::rect_of("button:inspect.continuity").unwrap();+ let accent = crate::theme::TabAccent::for_tab(&Tokens::get(), "INSPECT");+ assert!(+ button_shapes(&h, "inspect.continuity")+ .iter()+ .any(|s| matches!(s, egui::Shape::Rect(s) if s.rect == r && s.fill == accent.soft && s.stroke.color == accent.color)),+ "the real live tool retains its transient indication"+ );+ h.app.session.execute("inspect.continuity", &json!({})).unwrap();+ h.frame();+ assert_paint(&h, "inspect.continuity", true);+ // A dialog's last-command fallback must not invent an analysis tool.+ h.app.tool = None;+ h.app.start("solid.box");+ assert!(h.app.dialog.is_some());+ h.app.ui.tab = "INSPECT".into();+ h.app.last_command = Some(("inspect.zebra".into(), "Zebra".into()));+ h.frame();+ assert_paint(&h, "inspect.zebra", false);+ let r = scenario::rect_of("button:inspect.zebra").unwrap();+ assert!(+ !button_shapes(&h, "inspect.zebra")+ .iter()+ .any(|s| matches!(s, egui::Shape::Rect(s) if s.rect == r && s.fill == accent.soft && s.stroke.color == accent.color)),+ "last_command is not a live analysis tool"+ );+ }++ #[test]+ fn persistent_click_clear_and_replacement_remove_old_tool_paint_in_the_release_frame() {+ fn no_tool_paint(h: &Harness) {+ let r = scenario::rect_of("button:inspect.continuity").unwrap();+ let accent = crate::theme::TabAccent::for_tab(&Tokens::get(), "INSPECT");+ assert!(+ !button_shapes(h, "inspect.continuity")+ .iter()+ .any(|s| matches!(s, egui::Shape::Rect(s) if s.rect == r && s.fill == accent.soft && s.stroke.color == accent.color)),+ "no captured old live-tool fill/border after dispatch"+ );+ assert!(scenario::handle_at("ribbon:pressed:inspect.continuity").is_none());+ assert_paint(h, "inspect.continuity", false);+ }+ for labels in [true, false] {+ let mut h = harness();+ h.app.preferences.ribbon_labels = labels;+ crate::toolbar_custom::reorder(&mut h.app, "INSPECT", "inspect.continuity", "SURFACE QUALITY", Some("inspect.environment_map"));+ h.frames(2);+ tap(&mut h, "inspect.continuity");+ assert!(h.app.tool.is_some());+ tap(&mut h, "inspect.continuity");+ assert!(h.app.tool.is_none() && h.app.session.status_items().is_empty());+ no_tool_paint(&h);+ tap(&mut h, "inspect.continuity");+ tap(&mut h, "inspect.environment_map");+ assert!(h.app.tool.is_none());+ assert_eq!(h.app.session.status_items()[0].command, "inspect.environment_map");+ no_tool_paint(&h);+ assert_paint(&h, "inspect.environment_map", true);+ }+ }+}diff --git a/crates/ui-egui/src/ui_kit/actions.rs b/crates/ui-egui/src/ui_kit/actions.rsindex df3a4bf4fb..898d94c1f2 100644--- a/crates/ui-egui/src/ui_kit/actions.rs+++ b/crates/ui-egui/src/ui_kit/actions.rs@@ -443,6 +443,37 @@ pub enum Button {SmallSelected,}+/// Selected palette shared by SmallSelected and opt-in persistent native buttons.+fn selected_button_palette(t: &Tokens) -> (egui::Color32, egui::Color32) {+ (t.selected_bg, t.selected_ink)+}++/// Persistent counterpart of SmallSelected at a caller's native rectangle. This opt-in recipe+/// leaves existing SmallSelected controls unchanged. Tokens: selected_bg/ink, form_primary,+/// accent, radius_sm, space_8. The underline is two logical pixels; focus uses native visuals.+pub(crate) fn persistent_button_shape(ui: &Ui, response: &Response, rect: egui::Rect) -> egui::Shape {+ let t = Tokens::get();+ let (fill, _) = selected_button_palette(&t);+ let mut shapes = vec![+ egui::Shape::rect_filled(rect, t.radius_sm, fill),+ egui::Shape::rect_stroke(rect, t.radius_sm, egui::Stroke::new(1.0, t.form_primary), egui::StrokeKind::Inside),+ ];+ let inset = t.space_8.min(rect.width() / 4.0);+ let y = rect.bottom() - t.space_4;+ shapes+ .push(egui::Shape::line_segment([egui::pos2(rect.left() + inset, y), egui::pos2(rect.right() - inset, y)], egui::Stroke::new(2.0, t.accent)));+ if response.has_focus() {+ shapes.push(native_button_focus(ui, response, rect));+ }+ egui::Shape::Vec(shapes)+}++/// The same standard focused-button outline used by native egui buttons, without resizing.+pub(crate) fn native_button_focus(ui: &Ui, response: &Response, rect: egui::Rect) -> egui::Shape {+ let visuals = ui.style().interact(response);+ egui::Shape::rect_stroke(rect, Tokens::get().radius_sm, visuals.bg_stroke, egui::StrokeKind::Inside)+}+fn button_widget(label: egui::WidgetText, options: Button) -> egui::Button<'static> {let t = Tokens::get();if t.borders.bevel.is_some() && !matches!(options, Button::Ghost) {@@ -457,7 +488,8 @@ fn button_widget(label: egui::WidgetText, options: Button) -> egui::Button<'stat}Button::Ghost => egui::Button::new(label).frame(false),Button::SmallSelected => {- egui::Button::new(label.color(t.selected_ink)).small().fill(t.selected_bg).stroke(egui::Stroke::new(1.0, t.form_primary))+ let (fill, ink) = selected_button_palette(&t);+ egui::Button::new(label.color(ink)).small().fill(fill).stroke(egui::Stroke::new(1.0, t.form_primary))}_ => egui::Button::new(label),}diff --git a/crates/ui-egui/src/ui_kit/actions_tests.rs b/crates/ui-egui/src/ui_kit/actions_tests.rsindex 9fb9f2bb19..e3c60a8a7d 100644--- a/crates/ui-egui/src/ui_kit/actions_tests.rs+++ b/crates/ui-egui/src/ui_kit/actions_tests.rs@@ -263,3 +263,57 @@ fn one_bit_primary_actions_keep_inverted_labels_and_legacy_fills() {}}}++#[test]+fn persistent_native_selected_recipe_is_opt_in_and_preserves_small_selected_controls() {+ fn flatten(shape: &egui::Shape, out: &mut Vec<egui::Shape>) {+ match shape {+ egui::Shape::Vec(shapes) => {+ for s in shapes {+ flatten(s, out);+ }+ }+ s => out.push(s.clone()),+ }+ }+ let mut themes: Vec<_> = [false, true]+ .into_iter()+ .flat_map(|dark| crate::theme::ColorVision::ALL.into_iter().map(move |vision| crate::theme::Tokens::themed(dark, vision)))+ .collect();+ themes.extend(crate::theme_files::builtin().iter().map(crate::theme_files::resolve).filter(|t| t.borders.bevel.is_some()));+ assert!(themes.iter().any(|t| t.borders.bevel.is_some()), "include a real bevel theme");+ for t in themes {+ let _theme = crate::theme::scoped_tokens(t);+ let ctx = crate::fonts::test_context();+ let mut selected = egui::Shape::Noop;+ let mut native = egui::Rect::NOTHING;+ let mut output = ctx.run_ui(egui::RawInput::default(), |ui| {+ let response = button(ui, "Existing selected", Button::SmallSelected);+ native = response.rect;+ selected = persistent_button_shape(ui, &response, response.rect);+ });+ output.textures_delta.clear();+ let mut shapes = Vec::new();+ flatten(&selected, &mut shapes);+ assert!(shapes.iter().any(|s| matches!(s, egui::Shape::Rect(r) if r.rect == native && r.fill == t.selected_bg)));+ assert!(shapes.iter().any(|s| matches!(s, egui::Shape::LineSegment { stroke, .. } if stroke.width == 2.0 && stroke.color == t.accent)));+ // Existing SmallSelected keeps its old fill (including the bevel policy), regular+ // label family and no persistent underline. Merely asking for the opt-in shape+ // cannot alter that widget or its native geometry.+ let mut old = Vec::new();+ for shape in output.shapes {+ flatten(&shape.shape, &mut old);+ }+ let fill = if t.borders.bevel.is_some() { t.control_fill } else { t.selected_bg };+ assert!(old.iter().any(|s| matches!(s, egui::Shape::Rect(r) if r.rect == native && r.fill == fill)));+ assert!(!old.iter().any(|s| matches!(s, egui::Shape::LineSegment { stroke, .. } if stroke.width == 2.0 && stroke.color == t.accent)));+ let text = old+ .iter()+ .find_map(|s| match s {+ egui::Shape::Text(s) if s.galley.text() == "Existing selected" => Some(s),+ _ => None,+ })+ .unwrap();+ assert_eq!(text.galley.job.sections[0].format.font_id.family, egui::FontFamily::Proportional);+ }+}diff --git a/crates/ui-egui/src/ui_kit/gallery.rs b/crates/ui-egui/src/ui_kit/gallery.rsindex cec9f2f07b..9d29ec8d2f 100644--- a/crates/ui-egui/src/ui_kit/gallery.rs+++ b/crates/ui-egui/src/ui_kit/gallery.rs@@ -1415,6 +1415,21 @@ const ELEMENTS: &[Element] = &[element!("wide_primary_button", |ui, _| {wide_primary_button(ui, "Finish Sketch");}),+ element!("persistent_button_shape", "gallery:persistent_button", Some("gallery:persistent_button"), |ui, _| {+ let t = Tokens::get();+ let (rect, response) = ui.allocate_exact_size(vec2(t.form_button_height * 3.0, t.form_button_height * 2.0), egui::Sense::click());+ ui.painter().add(persistent_button_shape(ui, &response, rect));+ ui.painter().text(rect.center(), egui::Align2::CENTER_CENTER, "Selected", crate::fonts::semibold(t.font_label), t.selected_ink);+ scenario::publish_target("gallery:persistent_button", rect);+ }),+ element!("native_button_focus", "gallery:native_button_focus", Some("gallery:native_button_focus"), |ui, _| {+ let t = Tokens::get();+ let (rect, response) = ui.allocate_exact_size(vec2(t.form_button_height * 3.0, t.form_button_height), egui::Sense::click());+ response.request_focus();+ ui.painter().rect_filled(rect, t.radius_sm, t.control_fill);+ ui.painter().add(native_button_focus(ui, &response, rect));+ scenario::publish_target("gallery:native_button_focus", rect);+ }),element!("button", "dialog:row:Gallery", Some("dialog:button:Gallery:Add"), |ui, _| {row(ui, "Gallery", |ui| {button(ui, "Add", Button::Normal);