From 3562f506fea5ea4e53bf76142481983b0f76541d Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 29 Nov 2026 15:18:56 +0000 Subject: [PATCH] Side-menu ink trial: the menu stands on Brand; a Chrome rail reads in text contrast The port's side-menu ink follows the surface it stands on. The trial now stands its menu on SurfaceKind::Brand, as upstream's side menus do, with both assertions kept, and adds the port's case: on a chrome rail, in light and dark, the icon button takes the rows' ink and that ink reaches text contrast on the chrome. Co-Authored-By: Claude Opus 5.5 --- crates/ui-widgets/tests/it/buttons.rs | 37 ++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/crates/ui-widgets/tests/it/buttons.rs b/crates/ui-widgets/tests/it/buttons.rs index 7c7520ce93..4dab115cd8 100644 --- a/crates/ui-widgets/tests/it/buttons.rs +++ b/crates/ui-widgets/tests/it/buttons.rs @@ -963,10 +963,18 @@ fn a_side_menus_row_shows_the_standard_icon() { } /// 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. +/// row's icon does, not in the dark ghost ink that vanished on the brand surface; elsewhere it keeps its own ink. A side +/// menu reads in the ink of the surface it stands on: on a chrome rail (DeckCraft's File rail) that ink still reads +/// as text on the chrome. #[trial] fn a_side_menus_icon_button_reads_in_the_menus_ink() { - let rest = |side: bool, icon_only: bool| { + use craft_theme::{Contrast, Mode, Rgba, contrast_ratio, text_contrast_min}; + use craft_ui::layout_components::Stack; + use craft_ui::style::SurfaceKind; + use craft_ui::testing::style::tokens; + + // The button's rest icon ink in `mode`, inside a side menu when `side`, the menu standing on `surface` when given. + let rest = |surface: Option, side: bool, icon_only: bool, mode: Mode| { let mut fixture = Fixture::new(move |ui| { let show = |ui: &mut Ui| { if icon_only { @@ -975,25 +983,40 @@ fn a_side_menus_icon_button_reads_in_the_menus_ink() { let _ = Button::new("Print").icon(IconId::new("print")).variant(Variant::GHOST).show(ui); } }; + let stand = |ui: &mut Ui| match surface { + Some(kind) => { + let _ = Stack::new().surface(kind).show(ui, |ui, _| show(ui)); + } + None => show(ui), + }; if side { with_env( ui, |overrides| { overrides.values.set(ControlPlace::SideMenu); }, - show, + stand, ); } else { - show(ui); + stand(ui); } }); - fixture.settle(); + fixture.theme(mode, Contrast::Standard).settle(); let kind = if icon_only { std::any::type_name::>() } else { std::any::type_name::>() }; 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"); + let brand = Some(SurfaceKind::Brand); + assert_eq!(rest(brand, true, true, Mode::Light), rest(brand, true, false, Mode::Light), "the icon button takes the ink of the menu's rows"); + assert_ne!(rest(brand, true, true, Mode::Light), rest(None, false, true, Mode::Light), "outside a side menu it keeps its own ink"); + + let chrome = Some(SurfaceKind::Chrome); + for mode in [Mode::Light, Mode::Dark] { + let ink = rest(chrome, true, true, mode); + assert_eq!(ink, rest(chrome, true, false, mode), "on a chrome rail the icon button takes the ink of the menu's rows in {mode:?}"); + let ratio = contrast_ratio(Rgba(ink.to_array()), tokens(mode, Contrast::Standard).color.surface.chrome); + assert!(ratio >= text_contrast_min(Contrast::Standard), "a side menu on chrome reads at {ratio:.2} in {mode:?}"); + } } /// The command the arrow trial's split button is bound to.