Merge pull request #3487 from storytold/fix/wordcraft-7707-iconbutton-side-menu-ink

ui-widgets: an IconButton in a side menu takes the menu's ink (storytold/wordcraft#7707)
This commit is contained in:
Martin Ball authored and GitHub committed 2026-11-26 01:00:27 +00:00
commit 0cb8ed3974
3 files changed
+63 -14

No files matched your search

+19 -12
View File
@@ -289,6 +289,23 @@ impl<'a> Button<'a> {
}
}
/// A side menu stands on the brand surface: its names and icons read in the ink of strong fills, a disabled page's
/// dimmed, and its bands are that ink laid thinly over the brand colour (hover lighter than the page shown), not the
/// panel's state fills, which painted a light band with dark text over the rail. The row of the page shown (`on`)
/// keeps its band, so the menu marks where the page is. Returns the ink and the band fill, for every control of the
/// place (`Button`, `IconButton`).
pub(super) fn side_menu_ink(cx: &StyleCx<'_>) -> (craft_theme::Stateful<StyleColor>, craft_theme::Stateful<StyleColor>) {
let ink = cx.tokens.color.text.on_strong;
let (rest, dim) = (cx.color(ink), cx.color(ink.with_alpha(SIDE_MENU_DISABLED_ALPHA)));
let text = craft_theme::Stateful::new(rest).off(craft_theme::States::new(rest, rest, rest, dim));
let (clear, hover, shown) =
(cx.color(Rgba::TRANSPARENT), cx.color(ink.with_alpha(SIDE_MENU_HOVER_ALPHA)), cx.color(ink.with_alpha(SIDE_MENU_SHOWN_ALPHA)));
let fill = craft_theme::Stateful::new(clear)
.off(craft_theme::States::new(clear, hover, shown, clear))
.on(craft_theme::States::new(shown, shown, shown, shown));
(text, fill)
}
impl Component for Button<'_> {
const ROLE: Role = Role::BUTTON;
const OVERLAYS: bool = false;
@@ -330,13 +347,7 @@ impl Component for Button<'_> {
let pad = &cx.tokens.space.pad;
style.text.role = TypeRole::BodyLarge;
style.metrics.padding = Insets::new(pad.roomy, pad.roomy, pad.segment, pad.segment);
// A side menu stands on the brand surface: its names and icons read in the ink of strong fills, a disabled
// page's dimmed, and its bands are that ink laid thinly over the brand colour (hover lighter than the page
// shown), not the panel's state fills, which painted a light band with dark text over the rail. The row of
// the page shown (`selected`) keeps its band, so the menu marks where the page is.
let ink = cx.tokens.color.text.on_strong;
let (rest, dim) = (cx.color(ink), cx.color(ink.with_alpha(SIDE_MENU_DISABLED_ALPHA)));
let text = craft_theme::Stateful::new(rest).off(craft_theme::States::new(rest, rest, rest, dim));
let (text, fill) = side_menu_ink(cx);
style.text.color = text.clone();
// A place's icon is the large icon, not a control's standard one, set off from its name by a section gap: a
// list of places reads by its icons (WordCraft's File rail: 18 pt icons, nearest token 20 pt, 12 pt before 14 pt names).
@@ -344,11 +355,7 @@ impl Component for Button<'_> {
// The face paints by its gap and the measure by the metrics', so the two stay one.
style.face.gap = style.face.gap.max(cx.tokens.space.gap.section);
style.metrics.gap = style.face.gap;
let (clear, hover, shown) =
(cx.color(Rgba::TRANSPARENT), cx.color(ink.with_alpha(SIDE_MENU_HOVER_ALPHA)), cx.color(ink.with_alpha(SIDE_MENU_SHOWN_ALPHA)));
style.surface.fill = craft_theme::Stateful::new(clear)
.off(craft_theme::States::new(clear, hover, shown, clear))
.on(craft_theme::States::new(shown, shown, shown, shown));
style.surface.fill = fill;
}
style
}
+10 -2
View File
@@ -172,11 +172,19 @@ impl Component for IconButton<'_> {
fn style(cx: &StyleCx<'_>, _: IconButtonStyleKey) -> IconButtonStyle {
let face = face::icon_face(cx);
let marker = MarkerStyle::of(cx);
let (mut surface, mut glyph) = (face.surface, face.glyph);
// On a side menu's brand surface the glyph reads in the menu's ink and its bands lie over the brand colour, as a
// `Button` row's do.
if cx.env::<super::ControlPlace>() == super::ControlPlace::SideMenu {
let (ink, fill) = super::button::side_menu_ink(cx);
glyph.color = ink;
surface.fill = fill;
}
IconButtonStyle {
surface: face.surface,
surface,
metrics: face.metrics,
focus: face::focus(cx),
glyph: face.glyph,
glyph,
marker: marker.side,
marker_color: marker.color,
marker_edge: marker.edge,
+34
View File
@@ -751,6 +751,40 @@ fn a_side_menus_row_shows_the_standard_icon() {
assert!(menu > plain, "a side menu's icon is the standard one: {menu} against {plain}");
}
/// An icon-only button in a side menu (WordCraft's Back arrow on the File rail) reads in the menu's ink, as a `Button`
/// row's icon does, not in the dark ghost ink that vanished on the brand surface; elsewhere it keeps its own ink.
#[trial]
fn a_side_menus_icon_button_reads_in_the_menus_ink() {
let rest = |side: bool, icon_only: bool| {
let mut fixture = Fixture::new(move |ui| {
let show = |ui: &mut Ui| {
if icon_only {
let _ = IconButton::new(IconId::new("print")).label("Back").show(ui);
} else {
let _ = Button::new("Print").icon(IconId::new("print")).variant(Variant::GHOST).show(ui);
}
};
if side {
with_env(
ui,
|overrides| {
overrides.values.set(ControlPlace::SideMenu);
},
show,
);
} else {
show(ui);
}
});
fixture.settle();
let kind = if icon_only { std::any::type_name::<IconButton<'static>>() } else { std::any::type_name::<Button<'static>>() };
let style = fixture.styles_of(kind).into_iter().next().expect("the button resolved its style");
style.looks.icons.first().expect("the button has an icon look").color.off.rest.egui()
};
assert_eq!(rest(true, true), rest(true, false), "the icon button takes the ink of the menu's rows");
assert_ne!(rest(true, true), rest(false, true), "outside a side menu it keeps its own ink");
}
/// The command the arrow trial's split button is bound to.
#[derive(Clone, Copy, Debug, PartialEq, Eq, CommandSet)]
#[command(prefix = "splitTrial", scope = "splitTrial")]