diff --git a/crates/ui-widgets/src/buttons/button.rs b/crates/ui-widgets/src/buttons/button.rs index 4f543a1939..95d86e43b3 100644 --- a/crates/ui-widgets/src/buttons/button.rs +++ b/crates/ui-widgets/src/buttons/button.rs @@ -25,6 +25,13 @@ const SPINNER: PartKey = PartKey::new("spinner"); /// The part a button with a picture shows it in, in the leading icon's place. const PICTURE: PartKey = PartKey::new("picture"); +/// A side menu row's band under the pointer: its ink at about a tenth over the brand surface. +const SIDE_MENU_HOVER_ALPHA: u8 = 26; +/// The band of the page shown and of a press: its ink at about a sixth, a step above the hover's. +const SIDE_MENU_SHOWN_ALPHA: u8 = 46; +/// A disabled page's name and icon: the ink at a little under half. +const SIDE_MENU_DISABLED_ALPHA: u8 = 110; + /// The style of a push button. #[derive(Clone, Debug, PartialEq, ComponentStyle)] #[style(variants = [Variant::SECONDARY, Variant::PRIMARY, Variant::GHOST, Variant::DANGER, Variant::look(Emphasis::Outline, Tone::Accent)])] @@ -256,9 +263,20 @@ 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); - // The row of the page shown (`selected`) keeps the band its hover shows, so the menu marks where the page is. - let off = style.surface.fill.off; - style.surface.fill = style.surface.fill.clone().on(craft_theme::States::new(off.hover, off.hover, off.pressed, off.disabled)); + // 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)); + style.text.color = text.clone(); + style.icon = IconLook::new(style.icon.side, text); + 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 } diff --git a/crates/ui-widgets/tests/it/buttons.rs b/crates/ui-widgets/tests/it/buttons.rs index 84a3cbc443..8116b184b0 100644 --- a/crates/ui-widgets/tests/it/buttons.rs +++ b/crates/ui-widgets/tests/it/buttons.rs @@ -515,10 +515,11 @@ fn a_side_menus_buttons_are_taller_rows_with_the_large_body_label() { assert_eq!(menu.size(), plain.size(), "a stacked button keeps its own look in a side menu"); } -/// The row of the page shown in a side menu (`selected`) keeps the band its hover shows, as WordCraft's File menu -/// marks its current page; a selected ghost button elsewhere keeps its own look. +/// The row of the page shown in a side menu (`selected`) keeps a band, as WordCraft's File menu marks its current page: +/// the brand surface's ink laid thinly over it, a step stronger than the hover's, never the panel's opaque state fill +/// (which drew a light band with dark text over the brand rail). A selected ghost button elsewhere keeps its own look. #[trial] -fn a_side_menus_selected_row_shows_its_hover_band() { +fn a_side_menus_selected_row_shows_a_band_over_the_brand() { let button = std::any::type_name::>(); let (menu, _) = seen(button, "Info", |ui| { with_env( @@ -536,8 +537,11 @@ fn a_side_menus_selected_row_shows_its_hover_band() { }); let fill = menu.expect("a side menu's row has a surface").fill; let on = fill.on.expect("a side menu's row has an on look"); - assert_eq!(on.rest, fill.off.hover, "the shown page's row rests in the hover band"); - assert_ne!(on.rest, fill.off.rest, "the shown page's row is marked"); + let (rest, hover, shown) = (fill.off.rest.egui(), fill.off.hover.egui(), on.rest.egui()); + assert_eq!(rest.a(), 0, "a row at rest shows the brand surface"); + assert!(hover.a() > 0 && hover.a() < 64, "the hover band is the ink laid thinly over the brand: {hover:?}"); + assert!(shown.a() > hover.a() && shown.a() < 96, "the shown page's band is a step above the hover's: {shown:?}"); + assert_eq!(on.hover, on.rest, "the shown page's row keeps its band under the pointer"); assert!(plain.expect("a ghost button has a surface").fill.on.is_none(), "a selected ghost button elsewhere keeps its look"); }