mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-19 10:47:08 +00:00
A selected list row shows its selection whether or not it is highlighted
This commit is contained in:
@@ -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<StyleColor> {
|
||||
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<FlagRule> {
|
||||
@@ -164,8 +166,9 @@ fn flag_rules(form: RowForm) -> Vec<FlagRule> {
|
||||
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 },
|
||||
]
|
||||
}
|
||||
|
||||
@@ -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::<usize>::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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user