From 1d08ef8bf60d2f3f588f6a5cfbcb43a5dd0dd952 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Sun, 22 Nov 2026 09:22:33 +0700 Subject: [PATCH] ui-contract tests: the detail-body trial's list takes its rows' heights from the source's size hints (kit List::sized) --- crates/ui-contract/tests/it/collection/kit.rs | 12 ++++++++++-- crates/ui-contract/tests/it/collection/list.rs | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/crates/ui-contract/tests/it/collection/kit.rs b/crates/ui-contract/tests/it/collection/kit.rs index d9a680830..be0431990 100644 --- a/crates/ui-contract/tests/it/collection/kit.rs +++ b/crates/ui-contract/tests/it/collection/kit.rs @@ -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>>, tree: bool, + sized: bool, on_empty: Option<&'a Cell>, drops: Vec>, } @@ -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, 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 } } diff --git a/crates/ui-contract/tests/it/collection/list.rs b/crates/ui-contract/tests/it/collection/list.rs index dd257ee00..1a76a2389 100644 --- a/crates/ui-contract/tests/it/collection/list.rs +++ b/crates/ui-contract/tests/it/collection/list.rs @@ -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 {