From fd2d34156fb75664ac357f2b4c3a5c9799cb066b Mon Sep 17 00:00:00 2001 From: aiongg Date: Thu, 12 Nov 2026 00:16:20 +0000 Subject: [PATCH] A selected list row shows its selection whether or not it is highlighted --- crates/ui-widgets/src/list/row/style.rs | 11 ++++--- .../tests/it/contract/state_looks.rs | 32 +++++++++++++++++++ 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/crates/ui-widgets/src/list/row/style.rs b/crates/ui-widgets/src/list/row/style.rs index 65f014937..62349b48d 100644 --- a/crates/ui-widgets/src/list/row/style.rs +++ b/crates/ui-widgets/src/list/row/style.rs @@ -66,7 +66,8 @@ pub(super) struct FillKey { } /// The fill of a row: a stripe at rest, the hover and pressed tints over it, the selection's -/// fills, and the lead row's hover tint (selected hover on a selected row). An emphasized row keeps its hover tint. +/// fills, and the lead row's hover tint (selected hover on a selected row). An emphasized row that is not selected +/// keeps its hover tint. pub(super) fn fill_of(cx: &StyleCx<'_>, key: FillKey) -> Stateful { let state = &cx.tokens.color.state; let clear = Rgba::TRANSPARENT; @@ -144,8 +145,9 @@ struct FlagRule { } /// The flag rules of a row in priority order. Fill and ink both derive from this list, so an ink always pairs with -/// the fill under it: an emphasized row keeps its hover-like fill and base ink, the lead row on a selected row -/// paints the selected hover fill with `text.on_selected`, and the lead row alone keeps the hover tint. The command +/// the fill under it: the lead row on a selected row paints the selected hover fill with `text.on_selected`, a +/// selected row shows its selection whether or not it is emphasized, an emphasized row that is not selected keeps its +/// hover-like fill and base ink, and the lead row alone keeps the hover tint. The command /// form of a menu paints the lead row with `accent.solid` and `text.on_accent`. The option form paints the chosen row /// with `state.selected` and `text.on_selected`, lead or not, and the lead row alone with `state.hover`. fn flag_rules(form: RowForm) -> Vec { @@ -164,8 +166,9 @@ fn flag_rules(form: RowForm) -> Vec { RowForm::List => {} } vec![ - emphasized, FlagRule { flags: Flags::LEAD | Flags::SELECTED, fill: RuleFill::SelectedHover, ink: RuleInk::OnSelected }, + FlagRule { flags: Flags::EMPHASIZED | Flags::SELECTED, fill: RuleFill::Selected, ink: RuleInk::OnSelected }, + emphasized, FlagRule { flags: Flags::LEAD, fill: RuleFill::Tinted, ink: RuleInk::Base }, ] } diff --git a/crates/ui-widgets/tests/it/contract/state_looks.rs b/crates/ui-widgets/tests/it/contract/state_looks.rs index 3c1c48a98..9b010feb8 100644 --- a/crates/ui-widgets/tests/it/contract/state_looks.rs +++ b/crates/ui-widgets/tests/it/contract/state_looks.rs @@ -111,3 +111,35 @@ fn a_row_press_shows_on_the_check_cell_that_follows_it_and_a_cell_press_on_its_o assert_eq!(held(|[_, _, lock]| lock.center()), (false, true), "a press on the lock shows on the lock only"); assert_eq!(held(|[check, _, _]| check.center()), (true, false), "a press on the check cell shows on it"); } + +/// A highlighted row that is selected shows the selection, as a selected row does; highlighted alone it takes the tint. +#[trial] +fn a_selected_row_shows_its_selection_over_the_highlight() { + use craft_behavior::{Selection, keyed}; + use craft_ui::contract::{SelectMode, ShowCollection as _}; + use craft_ui::list::{List, ListRow}; + let rows = Cell::new([Rect::NOTHING; 4]); + let mut show = |ui: &mut egui::Ui| { + let region = Rect::from_min_size(pos2(0.0, 0.0), vec2(240.0, 200.0)); + in_region(ui, region, |ui| { + let order = [0usize, 1, 2, 3]; + let source = keyed(&order, |&row| row); + let selection = Selection::new(vec![0, 1], None, None); + let _ = + List::::new("Styles").select(SelectMode::Multi).selection(Bind::given(selection)).show_items(ui, &source, &mut |key, icx| { + let mut found = rows.get(); + found[*key] = icx.rect; + rows.set(found); + // Rows 0 and 1 are selected; rows 0 and 2 are highlighted. + ListRow::new("Style").highlight(*key % 2 == 0) + }); + }); + }; + let mut frames = Frames::new(); + frames.idle(2, &mut show); + let shapes = frames.frame_shapes(&mut show); + let [both, selected, highlighted, plain] = rows.get().map(|rect| fills(&shapes, rect)); + assert_eq!(both, selected, "a selected row shows its selection whether highlighted or not"); + assert_ne!(highlighted, plain, "a highlighted row that is not selected takes the tint"); + assert_ne!(highlighted, both, "the tint is not the selection"); +}