ui-contract tests: the detail-body trial's list takes its rows' heights from the source's size hints (kit List::sized)

This commit is contained in:
bflatastic committed 2026-11-22 09:22:33 +07:00
1 parent 7395c5f1ec
commit 1d08ef8bf6
2 files changed
+11 -3

No files matched your search

+10 -2
View File
@@ -155,7 +155,7 @@ impl Component for Row {
}
}
/// A list of rows at the control height, with the collection props and selection the trial gives.
/// A list of rows at the control height, or as tall as the source's size hints say, with the collection props and selection the trial gives.
#[derive(craft_ui::contract::Component)]
#[component(collection)]
pub struct List<'a> {
@@ -166,6 +166,7 @@ pub struct List<'a> {
items: CollectionProps,
selection: Option<Bind<'a, Selection<usize>>>,
tree: bool,
sized: bool,
on_empty: Option<&'a Cell<Rect>>,
drops: Vec<DropKind<'a, usize>>,
}
@@ -178,6 +179,7 @@ impl<'a> List<'a> {
items: CollectionProps::new().select(select),
selection: None,
tree: false,
sized: false,
on_empty: None,
drops: Vec::new(),
}
@@ -255,6 +257,12 @@ impl<'a> List<'a> {
self.tree = true;
self
}
/// Rows take the heights the source's size hints give.
pub fn sized(mut self) -> Self {
self.sized = true;
self
}
}
impl Component for List<'_> {
@@ -287,7 +295,7 @@ impl Collection for List<'_> {
}
fn item_layout(&self, source: &dyn ItemSource<usize>, width: f32, _: &StyleCx<'_>) -> SpanLayout {
let layout = SpanLayout::new(source, width, ROW_H);
let layout = if self.sized { SpanLayout::sized(source, width, ROW_H) } else { SpanLayout::new(source, width, ROW_H) };
if self.tree { layout.tree() } else { layout }
}
@@ -455,7 +455,7 @@ fn a_detail_body_takes_room_under_its_row_and_keeps_its_presses() {
let mut frames = Frames::new();
let mut show = |ui: &mut Ui| {
in_region(ui, Rect::from_min_size(ORIGIN, VIEW), |ui| {
let list = List::new(SelectMode::Single).id_salt("list");
let list = List::new(SelectMode::Single).sized().id_salt("list");
seen.take(list.show_items(ui, &source, &mut |key, cx| {
rects.borrow_mut()[*key] = cx.rect;
if *key == WITH {