From 2b68a30906bd1cb06fd316bca03e021f9eae31c5 Mon Sep 17 00:00:00 2001 From: aiongg Date: Sat, 21 Nov 2026 06:11:11 +0000 Subject: [PATCH] craft-ui: a container that fills its height on a content-height row's line runs its body in the line Such a container took the line's height as its rect, but its body still ran at its content height, so the children in it that fill (a spacer, a separator, a footer) never reached the line. Once the row's measuring run settled the line, the container is given its height and its body runs in it, as a fill-width row on the line of a row given its height already is. In the row's own measuring run there is no line yet and the container measures its content. --- crates/ui-contract/src/contract/body/size.rs | 21 +++++++++++++++++-- .../ui-contract/tests/it/layout/line_fill.rs | 21 ++++++++++++++++++- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/crates/ui-contract/src/contract/body/size.rs b/crates/ui-contract/src/contract/body/size.rs index 1c0392f891..835952520f 100644 --- a/crates/ui-contract/src/contract/body/size.rs +++ b/crates/ui-contract/src/contract/body/size.rs @@ -118,7 +118,9 @@ impl<'b> BodyHooks<'b> { /// /// A container that fits its content in a bar (`ContainerProps::content_in_bar`) is not given the width there. /// A fill-width container whose body is a row, shown on the line of a row given its height, is given that height - /// too: the line is a fixed cross extent, and the container fills it (a bar in a shell slot). + /// too: the line is a fixed cross extent, and the container fills it (a bar in a shell slot). A container that + /// fills its height on the line of a row that takes its height from its content is given the line's height once + /// the row's measuring run settled it (`line_height`). pub(super) fn given_axes(&self, props: &ContainerProps, env: &Env, at: ShowAt) -> (bool, bool) { let sizing = self.sizing(props); let fills_line = sizing == Sizing::FillWidth && unwrapped_row(props) && env.row_line.is_some(); @@ -126,11 +128,24 @@ impl<'b> BodyHooks<'b> { let (x, y) = (!sizing.content_width() && !fits_bar, sizing.fills_height() || fills_line); match (at, &props.mount) { (ShowAt::Rect(_), _) => (true, true), - (ShowAt::Flow, Mount::Inline) => (x && env.gives_width(), y && !env.content.1), + (ShowAt::Flow, Mount::Inline) => (x && env.gives_width(), y && (!env.content.1 || self.line_height(props, env, at).is_some())), (ShowAt::Flow, _) => (x, y), } } + /// The height of the line an inline container that fills its height stands on, where `env` is its parent's: the + /// line of an unwrapped row that takes its height from its content, once this pass's measuring run of the row + /// settled it. The container takes that height (`layout::fill_size`) and its body runs in it, so the children in + /// it that fill share it: a ribbon group as tall as the tallest group, its title at its foot. In the row's + /// measuring run there is no line yet, and the container measures its content. + pub(super) fn line_height(&self, props: &ContainerProps, env: &Env, at: ShowAt) -> Option { + let inline = matches!((at, &props.mount), (ShowAt::Flow, Mount::Inline)); + if !(inline && self.sizing(props).fills_height() && env.content.1) { + return None; + } + env.row_line.and_then(|line| line.height).filter(|height| height.is_finite() && *height > 0.0) + } + /// Whether a content-sized inline container passes the width its column gives it on to its own body, where `env` /// is its parent's: in a `Stack` body given its width, a child of its body that fills takes that width, and the /// container takes what its content took. A content-sized mount, a row or a grid stops it. @@ -322,6 +337,8 @@ impl<'b> BodyHooks<'b> { // shows (`layout::view_room`): it runs in that room, bounded like a body in a room that does not scroll. let shares_view = !room.y.is_finite() && self.sizing(props).fills_height() && crate::layout::shares_y(ui); let y = shares_view.then(|| crate::layout::view_room(ui, craft_behavior::Axis::Y)).flatten().unwrap_or(room.y); + // A body that fills the height of the row line it stands on runs in that line. + let y = self.line_height(props, &Env::of(ui), at).unwrap_or(y); Vec2::new(cap.map_or(room.x, |cap| room.x.min(cap)), props.room_height.unwrap_or(y)) } }, diff --git a/crates/ui-contract/tests/it/layout/line_fill.rs b/crates/ui-contract/tests/it/layout/line_fill.rs index 88a9f49a82..3417f0f97d 100644 --- a/crates/ui-contract/tests/it/layout/line_fill.rs +++ b/crates/ui-contract/tests/it/layout/line_fill.rs @@ -1,4 +1,5 @@ -//! Filling the line of a row that takes its height from its content: a levelled unit stands on the row's line. +//! Filling the line of a row that takes its height from its content: a levelled unit stands on the row's line, and a +//! container that fills its height there runs its body in the line's height from the first frame. use craft_ui::contract::{Props as _, Show as _, ShowContainer as _, Sizing}; use craft_ui::layout::{BodyLayout, levelled_unit}; @@ -45,3 +46,21 @@ fn a_levelled_unit_stands_on_its_rows_line() { ); } } + +#[trial] +fn a_fill_height_container_on_a_content_height_row_runs_its_body_in_the_line() { + let seen = line_and_fill(|ui, fill| { + let top = RefCell::new(Seen::default()); + Panel::new().layout(BodyLayout::stack()).sizing(Sizing::FillHeight).id_salt("column").show(ui, |ui, _| { + Probe::new(&top).id_salt("top").show(ui); + Probe::new(fill).sizing(Sizing::Fill).id_salt("fill").show(ui); + }); + }); + for ((row, fill), when) in seen.into_iter().zip(["in the first frame", "once settled"]) { + assert!((row.height() - TALL).abs() <= SNAP, "{when}: the row {row:?} is as tall as its tall member"); + assert!( + (fill.bottom() - row.bottom()).abs() <= SNAP && fill.height() > TALL / 2.0, + "{when}: the column's filling child {fill:?} takes what its column leaves of the row's line {row:?}" + ); + } +}