look-rest-4: a side menu's selected row (the page shown) rests in the band its hover shows, as WordCraft's File menu marks its current page; a push Button drew no on look, so selected changed nothing; trial; the side menu story's current row shows it

This commit is contained in:
Martin Ball
2026-11-19 14:45:12 +00:00
parent ca51f08b14
commit 171eea0cd1
2 changed files with 29 additions and 0 deletions
+3
View File
@@ -256,6 +256,9 @@ 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));
}
style
}
+26
View File
@@ -507,3 +507,29 @@ fn a_side_menus_buttons_are_taller_rows_with_the_large_body_label() {
let (menu, plain) = (rect(true, Arrangement::Stacked), rect(false, Arrangement::Stacked));
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.
#[trial]
fn a_side_menus_selected_row_shows_its_hover_band() {
let button = std::any::type_name::<Button<'static>>();
let (menu, _) = seen(button, "Info", |ui| {
with_env(
ui,
|overrides| {
overrides.values.set(ControlPlace::SideMenu);
},
|ui| {
let _ = Button::new("Info").variant(Variant::GHOST).selected(true).show(ui);
},
);
});
let (plain, _) = seen(button, "Info", |ui| {
let _ = Button::new("Info").variant(Variant::GHOST).selected(true).show(ui);
});
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");
assert!(plain.expect("a ghost button has a surface").fill.on.is_none(), "a selected ghost button elsewhere keeps its look");
}