From 3a4cf8a8ba9febee5c1eb9949dbe9cc3a13ceb2e Mon Sep 17 00:00:00 2001 From: aiongg Date: Wed, 11 Nov 2026 20:08:09 +0000 Subject: [PATCH] Muted ink for secondary glyphs and the menu bar's no-match line VariantLook::muted: text.muted on a neutral outline or ghost button, the variant's text otherwise. SplitButton's chevron reads it. The menu bar's "No matching commands" line is muted text. --- crates/theme/src/variant.rs | 17 ++++++++++++++--- crates/ui-contract/src/style/cx.rs | 10 +++++++++- crates/ui-widgets/src/buttons/split_button.rs | 6 +++++- crates/ui-widgets/src/menu/bar.rs | 4 ++-- 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/crates/theme/src/variant.rs b/crates/theme/src/variant.rs index e833eb6b7..c78afe84b 100644 --- a/crates/theme/src/variant.rs +++ b/crates/theme/src/variant.rs @@ -62,6 +62,9 @@ pub struct VariantLook { pub fill: States, /// Label and icon per state. pub text: States, + /// Secondary glyphs (a split button's chevron) per state: muted on a neutral button without fill, the text + /// colour where muted ink would not read. + pub muted: States, /// Edge per state; `None` draws no edge. pub edge: Option>, /// The corner radius step. @@ -140,7 +143,7 @@ pub(crate) fn variant_pairs() -> Vec<(ColorToken, ColorToken)> { impl VariantLook { /// A look with no edge and control corners. pub const fn new(fill: States, text: States) -> Self { - VariantLook { fill, text, edge: None, radius: RadiusStep::Control } + VariantLook { fill, text, muted: text, edge: None, radius: RadiusStep::Control } } /// Sets the edge colours. @@ -149,6 +152,12 @@ impl VariantLook { self } + /// Sets the colours of secondary glyphs. + pub const fn muted(mut self, muted: States) -> Self { + self.muted = muted; + self + } + /// Sets the corner radius step. pub const fn radius(mut self, radius: RadiusStep) -> Self { self.radius = radius; @@ -166,6 +175,8 @@ impl VariantLook { let (soft_fill, fg, edge, solid, solid_hover, solid_pressed, on_solid) = (c.get(t.soft_fill), c.get(t.fg), c.get(t.edge), c.get(t.solid), c.get(t.solid_hover), c.get(t.solid_pressed), c.get(t.on_solid)); let button = RadiusStep::Button; + // A neutral button without fill shows its secondary glyphs muted; a toned one keeps its tone. + let muted = if tone == Tone::Neutral { text(c.text.muted) } else { text(fg) }; match emphasis { Emphasis::Solid => VariantLook::new(States::new(solid, solid_hover, solid_pressed, c.state.disabled_fill), text(on_solid)).radius(button), Emphasis::Soft => VariantLook::new(States::new(soft_fill, soft_fill, soft_fill, c.state.disabled_fill), text(fg)) @@ -174,9 +185,9 @@ impl VariantLook { // A neutral outline darkens to the strongest ink under the pointer and the press; a toned one keeps its edge. Emphasis::Outline => { let lit = if tone == Tone::Neutral { c.text.normal } else { edge }; - VariantLook::new(state_fill, text(fg)).edge(States::new(edge, lit, lit, c.line.divider)).radius(button) + VariantLook::new(state_fill, text(fg)).muted(muted).edge(States::new(edge, lit, lit, c.line.divider)).radius(button) } - Emphasis::Ghost => VariantLook::new(state_fill, text(fg)).radius(button).edge(flat(clear)), + Emphasis::Ghost => VariantLook::new(state_fill, text(fg)).muted(muted).radius(button).edge(flat(clear)), } } } diff --git a/crates/ui-contract/src/style/cx.rs b/crates/ui-contract/src/style/cx.rs index ebae161cd..0d91134ec 100644 --- a/crates/ui-contract/src/style/cx.rs +++ b/crates/ui-contract/src/style/cx.rs @@ -55,6 +55,8 @@ pub struct VariantParts { pub fill: Stateful, /// The text and icon colour per state. pub text: Stateful, + /// The colour of secondary glyphs per state. + pub muted: Stateful, /// The edge per state. pub edge: Option>, /// The corner radius. @@ -366,7 +368,13 @@ impl<'a> StyleCx<'a> { RadiusStep::Pill => radius.pill, _ => radius.control, }; - VariantParts { fill: states(look.fill), text: states(look.text), edge: look.edge.map(states), radius: UiTokens::corner(px) } + VariantParts { + fill: states(look.fill), + text: states(look.text), + muted: states(look.muted), + edge: look.edge.map(states), + radius: UiTokens::corner(px), + } } /// The token group `G` for this token set: derived from the tokens with the theme's values under `G::PATH` laid diff --git a/crates/ui-widgets/src/buttons/split_button.rs b/crates/ui-widgets/src/buttons/split_button.rs index a4fa9e94a..7a73fde11 100644 --- a/crates/ui-widgets/src/buttons/split_button.rs +++ b/crates/ui-widgets/src/buttons/split_button.rs @@ -39,6 +39,8 @@ pub struct SplitButtonStyle { face: FaceLook, /// What each part adds over the surface: clear at rest, the variant's hover and pressed fills. part_fill: Stateful, + /// The chevron: the variant's secondary-glyph ink, muted on a neutral button without fill. + chevron: Stateful, /// The line between the parts, in the variant's edge colour. divider: Stateful, /// The divider's gap from the top and bottom edges. @@ -107,6 +109,7 @@ impl Component for SplitButton<'_, T> { let (fill, clear) = (parts.fill.off, cx.color(craft_theme::Rgba::TRANSPARENT)); surface.fill = Stateful::new(fill.rest).off(States::new(fill.rest, fill.rest, fill.rest, fill.disabled)); let divider = parts.edge.unwrap_or_else(|| Stateful::new(clear)); + let chevron = parts.muted; let (text, icon) = face::ink(cx); SplitButtonStyle { surface, @@ -116,6 +119,7 @@ impl Component for SplitButton<'_, T> { icon, face: FaceLook::of(cx), part_fill: Stateful::new(clear).off(States::new(clear, fill.hover, fill.pressed, clear)), + chevron, divider, divider_inset: cx.tokens.space.gap.inline, radius: parts.radius, @@ -195,7 +199,7 @@ impl Component for SplitButton<'_, T> { let draw = ui.draw(); let side = cx.style.icon.side; let chevron = Rect::from_center_size(arrow.center(), Vec2::splat(side)); - draw.icon(chevron, &crate::controls::disclosure::DisclosureGlyph::menu_button().color(cx.resolve(&cx.style.icon.color))); + draw.icon(chevron, &crate::controls::disclosure::DisclosureGlyph::menu_button().color(cx.resolve(&cx.style.chevron))); let x = if rtl { arrow.right() } else { arrow.left() }; let x = draw.pixel_centre(x); let inset = cx.style.divider_inset; diff --git a/crates/ui-widgets/src/menu/bar.rs b/crates/ui-widgets/src/menu/bar.rs index 065bbb9e3..03c6308a7 100644 --- a/crates/ui-widgets/src/menu/bar.rs +++ b/crates/ui-widgets/src/menu/bar.rs @@ -26,7 +26,7 @@ use crate::contract::{ Access, Bind, Common, Component, Cx, Focus as _, MeasureCx, MenuKey, Name, NoValue, Outcome, OverlayUi, Overlays as _, Pad, PaintUi, PartsCx, Pointer as _, PopupHandle, PopupKind, Props as _, Role, SetPosition, Show as _, ShowContainer as _, Styled as _, }; -use crate::display::{Divider, Text}; +use crate::display::{Divider, Shade, Text}; use crate::layout_components::Stack; use crate::list::RowStyleCx as _; use crate::primitives::{PaintShape, StrokeWidth, TextRun}; @@ -568,7 +568,7 @@ impl Component for MenuBar<'_> { }; } if listed.is_empty() && !query.0.trim().is_empty() { - Text::new(words.bar_no_matches.as_str().to_owned()).show(ui); + Text::new(words.bar_no_matches.as_str().to_owned()).shade(Shade::Muted).show(ui); } Divider::horizontal().show(ui); }