From 8f6558607658ac9dcfea427268de06859ab52fd0 Mon Sep 17 00:00:00 2001 From: aiongg Date: Fri, 27 Nov 2026 01:09:30 +0000 Subject: [PATCH] ui-contract: an unwrapped row reports its line in every alignment A row that places its block at its end, centred or spread recorded its line but reported it to no first-line target: it read the target from its block's Ui after restoring that Ui's entry, which found none. It reports to its body's target as a row placed from its start does, so it sits on an outer row's line by its own line and a container takes it as its first line. --- crates/ui-contract/src/layout/body.rs | 6 +++--- crates/ui-contract/tests/it/layout/body.rs | 23 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/crates/ui-contract/src/layout/body.rs b/crates/ui-contract/src/layout/body.rs index 01dcf2d469..dd6e424734 100644 --- a/crates/ui-contract/src/layout/body.rs +++ b/crates/ui-contract/src/layout/body.rs @@ -2039,7 +2039,7 @@ fn run_spread_row(ui: &mut Ui, env: &Env, at: &RowIn, mut body: impl FnMut(&m let installed = Env::install_for(ui, row.clone()); let inner = run_spread(ui, &row, id, gap.x, rtl, &mut body); Env::restore(&ctx, installed); - record_line(ui, sizing, id, shared, None); + record_line(ui, sizing, id, shared, env.first_line); inner }); inner @@ -2061,7 +2061,7 @@ fn run_start_row(ui: &mut Ui, env: &Env, at: &RowIn, mut body: impl FnMut(&mu let installed = Env::install_for(ui, row.clone()); let inner = run_shrinking(ui, &row, id, &mut body); Env::restore(&ctx, installed); - record_line(ui, sizing, id, shared, sweep.first_line); + record_line(ui, sizing, id, shared, env.first_line); inner }) } @@ -2124,7 +2124,7 @@ fn run_row(ui: &mut Ui, env: &Env, at: &RowIn, (wrap, align): (bool, RowAlign } Env::restore(&ctx, installed); if !wrap { - record_line(ui, sizing, id, shared, None); + record_line(ui, sizing, id, shared, env.first_line); } inner }); diff --git a/crates/ui-contract/tests/it/layout/body.rs b/crates/ui-contract/tests/it/layout/body.rs index c9ef1431c2..71cb25390d 100644 --- a/crates/ui-contract/tests/it/layout/body.rs +++ b/crates/ui-contract/tests/it/layout/body.rs @@ -567,6 +567,29 @@ fn a_memoized_view_sits_on_the_rows_line() { } } +/// An unwrapped row in a row sits on the outer row's line by its own line, whatever its alignment: a row that places +/// its block from its start, at its end, centred or spread reports its line as its first line alike. +#[trial] +fn an_unwrapped_row_sits_on_the_outer_line_by_its_line_in_every_alignment() { + for align in [RowAlign::Start, RowAlign::SpaceBetween, RowAlign::Center, RowAlign::End] { + let seen = Rc::new(Cell::new((Rect::NOTHING, Rect::NOTHING))); + let shown = Rc::clone(&seen); + let mut fixture = Fixture::new(move |ui| { + Panel::new().layout(BodyLayout::row()).id_salt("outer").show(ui, |ui, _| { + let tall = Block::new(Vec2::new(20.0, 30.0)).show(ui).rect; + let short = Panel::new().layout(BodyLayout::row().align(align)).id_salt("inner").show(ui, |ui, _| Block::new(ITEM).show(ui).rect); + if !is_measuring(ui.ctx()) { + shown.set((tall, short.inner.unwrap_or(Rect::NOTHING))); + } + }); + }); + fixture.room(Vec2::splat(400.0)).settle(); + let (tall, short) = seen.get(); + assert!(short.height() > 0.0, "{align:?}: the inner row showed its block: {short:?}"); + assert!((short.center().y - tall.center().y).abs() < SLACK, "{align:?}: the inner row's block {short:?} is off the line of {tall:?}"); + } +} + /// A Row in right-to-left holding a vertically scrolling container (content-sized, then filling its height) beside a /// probe: the container, the probe inside it and the probe beside it are finite, and the container lies in the row. #[trial]