mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-16 23:24:24 +00:00
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.
This commit is contained in:
@@ -62,6 +62,9 @@ pub struct VariantLook {
|
||||
pub fill: States<Rgba>,
|
||||
/// Label and icon per state.
|
||||
pub text: States<Rgba>,
|
||||
/// 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<Rgba>,
|
||||
/// Edge per state; `None` draws no edge.
|
||||
pub edge: Option<States<Rgba>>,
|
||||
/// 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<Rgba>, text: States<Rgba>) -> 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<Rgba>) -> 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)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,6 +55,8 @@ pub struct VariantParts {
|
||||
pub fill: Stateful<StyleColor>,
|
||||
/// The text and icon colour per state.
|
||||
pub text: Stateful<StyleColor>,
|
||||
/// The colour of secondary glyphs per state.
|
||||
pub muted: Stateful<StyleColor>,
|
||||
/// The edge per state.
|
||||
pub edge: Option<Stateful<StyleColor>>,
|
||||
/// 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
|
||||
|
||||
@@ -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<StyleColor>,
|
||||
/// The chevron: the variant's secondary-glyph ink, muted on a neutral button without fill.
|
||||
chevron: Stateful<StyleColor>,
|
||||
/// The line between the parts, in the variant's edge colour.
|
||||
divider: Stateful<StyleColor>,
|
||||
/// The divider's gap from the top and bottom edges.
|
||||
@@ -107,6 +109,7 @@ impl<T: Value + 'static> 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<T: Value + 'static> 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<T: Value + 'static> 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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user