From e433ef83eb5c6b98407b32197947b512b0b90562 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Mon, 23 Nov 2026 17:28:13 +0700 Subject: [PATCH] ui-widgets: trial: a grid row holds a field whose label stacks above its control for want of room --- .../ui-widgets/tests/it/layout/grid_labels.rs | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/crates/ui-widgets/tests/it/layout/grid_labels.rs b/crates/ui-widgets/tests/it/layout/grid_labels.rs index c16f2e3315..1e1c1712d4 100644 --- a/crates/ui-widgets/tests/it/layout/grid_labels.rs +++ b/crates/ui-widgets/tests/it/layout/grid_labels.rs @@ -40,3 +40,34 @@ fn the_fields_of_a_grid_column_share_a_left_edge() { assert!((second.left() - fourth.left()).abs() <= 0.5, "the filling column's fields share a left edge: {second:?}, {fourth:?}"); assert!(first.right() <= second.left() && third.right() <= fourth.left(), "the sized column holds its fields: {rects:?}"); } + +/// A filling column, then one sized by its cells. +static FILL_FIRST: [ColumnWidth; 2] = [ColumnWidth::fill(1.0), ColumnWidth::Content]; + +/// A grid row is as tall as a field in it whose label stacks above its control for want of room: the next row's label +/// starts below the control. Guards against a grid that spaced its rows as if the label sat beside the control, so the +/// next row's label overlapped it. +#[trial] +fn a_grid_row_holds_a_field_whose_label_stacks() { + let rects: Rc>> = Rc::default(); + let seen = rects.clone(); + let mut fixture = Fixture::new(move |ui| { + let mut seen = seen.borrow_mut(); + seen.clear(); + Grid::new(&FILL_FIRST).show(ui, |ui, _| { + for i in 0..2 { + Field::new(format!("Top Left Corner {i}")).show(ui, |ui, _| { + seen.push(NumberField::new(format!("Radius {i}"), Bind::given(Some(10.0))).show(ui).response.rect); + }); + craft_ui::display::Text::new("Round").show(ui); + } + }); + }); + fixture.room(egui::vec2(150.0, 400.0)).record_paint(); + fixture.settle(); + let rects = rects.borrow(); + let [first, _] = rects[..] else { panic!("two fields show: {rects:?}") }; + let label = fixture.texts().iter().find(|text| text.text == "Top Left Corner 1").map(|text| text.rect).expect("the second label shows"); + assert!(label.bottom() <= rects[1].top() + 0.5, "the label stacks above its control: {label:?}, {:?}", rects[1]); + assert!(label.top() >= first.bottom() - 0.5, "the second row starts below the first row's control: {label:?}, {first:?}"); +}