A child that fills a content-height row's height spans its line

A leaf that fills its height in an unwrapped row whose height comes from its
content is held at its measured height in the row's measuring run and shown
across the line the row settles on (`row_line`), as a fill-width child of a
content column is held at its measured width and shown across the column. It
never sets the line, so a vertical divider spans the row beside its tallest
child. A row given its height already gives it; a wrapped row has no line, and
a container that fills keeps its capped content height.

The cross_fill trial shows the divider spanning the row, the row as tall as
its tallest child, a button keeping its height, and a settled frame measuring
nothing.
This commit is contained in:
aiongg
2026-11-12 14:32:48 +00:00
parent 927c00eba2
commit 2cd84ca3d1
3 changed files with 76 additions and 4 deletions
+12 -4
View File
@@ -288,11 +288,19 @@ impl<C: Component> ShapeHooks<C> for LeafHooks {
fn sized(&self, comp: &C, ui: &Ui, id: Id, size: Vec2) -> Vec2 {
let room = crate::layout::flow_fill_room(ui);
// The line height of a content-height row is not known inside `sized` (the other children have not run), so a
// child that fills across it keeps its measured size there.
let content = Env::of(ui).content;
// Along an axis the enclosing body sizes from its content, a child that fills keeps its measured size, so it
// never sets that size. Across an unwrapped row's line it is shown across the line the row settled on in its
// measuring run, where the child measured at its own size.
let env = Env::of(ui);
let (content, line) = (env.content, env.row_line);
let fill = |measured: f32, offered: f32, content: bool, along: craft_behavior::Axis| {
if !offered.is_finite() || content {
if content {
return match (along, line) {
(craft_behavior::Axis::Y, Some(line)) => measured.max(line),
_ => measured,
};
}
if !offered.is_finite() {
return measured;
}
match crate::layout::main_fill(ui, id, along) {
@@ -0,0 +1,63 @@
//! Cross fill in a row: a row that takes its height from its content holds a child that fills its height at the
//! child's measured height, and shows it across the line the row settles on, so the child never sets the line.
use craft_ui::buttons::Button;
use craft_ui::contract::{Show as _, ShowContainer as _};
use craft_ui::display::Divider;
use craft_ui::layout_components::{Row, Stack};
use craft_ui::testing::{Frames, last_pass_measuring_runs, trial};
use egui::Rect;
use std::cell::Cell;
const SNAP: f32 = 1.0;
/// The rects of a content-height row, its stack of buttons, its vertical divider and its lone button.
#[derive(Clone, Copy)]
struct Rects {
row: Rect,
stack: Rect,
divider: Rect,
button: Rect,
}
/// Shows the row for `n` frames in a column given the screen.
fn shown(frames: &mut Frames, n: usize, seen: &Cell<Option<Rects>>) {
frames.idle(n, |ui| {
Stack::new().fill().show_at(ui, ui.available_rect_before_wrap(), |ui, _| {
let parts = Cell::new((Rect::NOTHING, Rect::NOTHING, Rect::NOTHING));
let row = Row::new().show(ui, |ui, _| {
let stack = Stack::new().show(ui, |ui, _| {
for label in ["Bevel", "Stroke", "Inner Shadow", "Drop Shadow"] {
Button::new(label).show(ui);
}
});
let divider = Divider::vertical().show(ui).rect;
let button = Button::new("Preview").show(ui).rect;
parts.set((stack.output.rect, divider, button));
});
let (stack, divider, button) = parts.get();
seen.set(Some(Rects { row: row.output.rect, stack, divider, button }));
});
});
}
#[trial]
fn a_vertical_divider_spans_the_line_of_a_content_height_row_without_setting_it() {
let mut frames = Frames::new();
let seen = Cell::new(None);
let check = |seen: &Cell<Option<Rects>>, when: &str| {
let Rects { row, stack, divider, button } = seen.get().expect("the row shows");
assert!(
(divider.top() - row.top()).abs() <= SNAP && (divider.bottom() - row.bottom()).abs() <= SNAP,
"{when}: the divider {divider:?} spans the row {row:?}"
);
assert!((row.height() - stack.height()).abs() <= SNAP, "{when}: the row {row:?} is as tall as its tallest child {stack:?}");
assert!(button.height() < row.height() - SNAP, "{when}: a button keeps its own height {button:?} in the row {row:?}");
assert!(button.top() >= row.top() - SNAP && button.bottom() <= row.bottom() + SNAP, "{when}: the button {button:?} sits in the line");
};
shown(&mut frames, 4, &seen);
check(&seen, "after four frames");
shown(&mut frames, 4, &seen);
check(&seen, "once settled");
assert!(last_pass_measuring_runs(&frames.ctx).is_empty(), "a settled frame measures nothing");
}
+1
View File
@@ -1,3 +1,4 @@
mod cross_fill;
mod fill_column;
mod fill_share;
mod fonts;