diff --git a/crates/ui-contract/src/contract/body/hooks.rs b/crates/ui-contract/src/contract/body/hooks.rs index 0f9f076413..8dfa74c621 100644 --- a/crates/ui-contract/src/contract/body/hooks.rs +++ b/crates/ui-contract/src/contract/body/hooks.rs @@ -974,7 +974,7 @@ struct BodyRun<'r> { room_x: f32, scroll: Option, layout: &'r layout::BodyLayout, - line: Option, + line: layout::BodyLine, columns: LabelColumns, env: &'r Env, /// While the body opens or closes, it shows only the part of its last height that the presence reaches. @@ -1345,7 +1345,7 @@ impl BodyHooks<'_> { room_x: plan.room.x, scroll: plan.scroll, layout: &props.layout, - line: plan.line, + line: layout::BodyLine { shared: plan.line, least: props.least_height.unwrap_or(0.0) }, columns: LabelColumns::of(props, !self.wide() && !self.held(props, env)), env: body_env, reveal_clip, diff --git a/crates/ui-contract/src/contract/container.rs b/crates/ui-contract/src/contract/container.rs index 142677f22f..9a89d45c26 100644 --- a/crates/ui-contract/src/contract/container.rs +++ b/crates/ui-contract/src/contract/container.rs @@ -777,6 +777,10 @@ pub struct ContainerProps { pub body_gap: Gap, /// The least width of the content, from a size role; the content may be wider. pub least_width: Option, + /// The least height of an unwrapped `Row` body's line, in points: the line is at least this high, as if a child of + /// more than one line this high stood in it, so the children that fill the line's height take at least it. Other + /// layouts ignore it. + pub least_height: Option, /// The line length of the body's paragraphs while the container takes its width from its content, from a size role. pub wrap_width: Option, /// A divider along the inner edge of a container mounted as an edge pane (`Mount::Pane` at an edge): the edge that @@ -851,6 +855,7 @@ impl ContainerProps { && self.collapse == other.collapse && self.body_gap == other.body_gap && self.least_width == other.least_width + && self.least_height == other.least_height && self.wrap_width == other.wrap_width && self.child_size == other.child_size && self.child_glyphs == other.child_glyphs @@ -883,6 +888,7 @@ impl ContainerProps { collapse: None, body_gap: Gap::Row, least_width: None, + least_height: None, wrap_width: None, edge_rule: false, child_size: None, @@ -1023,6 +1029,12 @@ impl ContainerProps { self } + /// The least height of an unwrapped `Row` body's line ([`least_height`](Self::least_height)). + pub const fn least_height(mut self, points: f32) -> Self { + self.least_height = Some(points); + self + } + /// The line length of the body's paragraphs while the container takes its width from its content, from a size role. pub const fn wrap_width(mut self, wrap: WrapWidth) -> Self { self.wrap_width = Some(wrap); diff --git a/crates/ui-contract/src/layout/body.rs b/crates/ui-contract/src/layout/body.rs index 39177e01b1..8198b215f7 100644 --- a/crates/ui-contract/src/layout/body.rs +++ b/crates/ui-contract/src/layout/body.rs @@ -1554,13 +1554,16 @@ fn on_line(body: Id, own: Option<(f32, f32)>, shared: Option) -> RowLine { } /// Starts a sweep of a body's children in a measuring run: the body's first-line `target` and, for the unwrapped -/// `Row` body `row`, its line start afresh. -fn open_sweep(ctx: &egui::Context, target: Option, row: Option) { +/// `Row` body `row`, its line start afresh, `least` high at least (`ContainerProps::least_height`). +fn open_sweep(ctx: &egui::Context, target: Option, row: Option, least: f32) { if let Some(target) = target { open_first_lines(ctx, &[target]); } if let Some(row) = row { - pass_state::with::(ctx, |rows| rows.0.insert(row, LineTook::default())); + // The least height counts as a child of more than one line that high. + let mut took = LineTook::default(); + took.add(None, least.max(0.0)); + pass_state::with::(ctx, |rows| rows.0.insert(row, took)); } } @@ -1607,21 +1610,32 @@ fn found(ctx: &egui::Context, sizing: bool, id: Id, room: Vec2, took: Vec2) { /// the gap and size columns from the cells as they come. #[cfg(feature = "testing")] pub(crate) fn run_body(ui: &mut Ui, env: &Env, id: Id, layout: &BodyLayout, gap: Vec2, body: impl FnMut(&mut Ui) -> R) -> R { - run_body_measured(ui, env, id, layout, gap, None, body).0 + run_body_measured(ui, env, id, layout, gap, BodyLine::default(), body).0 +} + +/// What an unwrapped `Row` body's line starts from besides its children: the line `shared` with its container's inline +/// header or end region, which the children are centred on, and the `least` height of the line +/// (`ContainerProps::least_height`), which counts as a child of more than one line that high. +#[derive(Clone, Copy, Debug, Default)] +pub(crate) struct BodyLine { + pub(crate) shared: Option, + pub(crate) least: f32, } /// `run_body`, with the width the children take at the gap alone for a `Row` that places its block itself (`End`, -/// `Center`, `SpaceBetween`): the width the body asks for, where the room it is placed in spans wider. `shared` is the -/// line the body shares with its container's inline header or end region: an unwrapped `Row` sets its children on it. +/// `Center`, `SpaceBetween`): the width the body asks for, where the room it is placed in spans wider. `line` is what +/// an unwrapped `Row` body's line starts from: the line it shares with its container's inline header or end region, +/// which it sets its children on, and its least height. pub(crate) fn run_body_measured( ui: &mut Ui, env: &Env, id: Id, layout: &BodyLayout, gap: Vec2, - shared: Option, + line: BodyLine, mut body: impl FnMut(&mut Ui) -> R, ) -> (R, Option) { + let BodyLine { shared, least } = line; let rtl = env.direction.is_rtl(); let ctx = ui.ctx().clone(); let sizing = measure::active(&ctx); @@ -1629,7 +1643,7 @@ pub(crate) fn run_body_measured( let target = env.first_line.filter(|_| sizing); let row = (sizing && matches!(layout, BodyLayout::Row { wrap: false, .. })).then_some(id); let body = |ui: &mut Ui| { - open_sweep(&ctx, target, row); + open_sweep(&ctx, target, row, least); body(ui) }; // Each layout runs in its own function, so a body nested in bodies keeps only its own layout's frame on the stack. diff --git a/crates/ui-contract/src/layout/mod.rs b/crates/ui-contract/src/layout/mod.rs index 4f2654e978..54fdb32d17 100644 --- a/crates/ui-contract/src/layout/mod.rs +++ b/crates/ui-contract/src/layout/mod.rs @@ -24,7 +24,7 @@ pub use body::place_in_flow; #[cfg(feature = "testing")] pub(crate) use body::run_body; pub(crate) use body::{ - InFlow, close_first_line, counting_fills, fill_share, fill_size, flow_fill_room, flow_region, flow_room, grid_cell, in_grid_content_column, - leaf_fill_room, members_line, open_first_lines, place_in_cell, report_held, report_least, report_shrink, row_alone_room, run_body_measured, - shares_y, shrink_cap, take_cell, take_in_flow, view_room, + BodyLine, InFlow, close_first_line, counting_fills, fill_share, fill_size, flow_fill_room, flow_region, flow_room, grid_cell, + in_grid_content_column, leaf_fill_room, members_line, open_first_lines, place_in_cell, report_held, report_least, report_shrink, row_alone_room, + run_body_measured, shares_y, shrink_cap, take_cell, take_in_flow, view_room, }; diff --git a/crates/ui-widgets/src/layout_components/mod.rs b/crates/ui-widgets/src/layout_components/mod.rs index e5c1c8e735..49048d3f23 100644 --- a/crates/ui-widgets/src/layout_components/mod.rs +++ b/crates/ui-widgets/src/layout_components/mod.rs @@ -325,6 +325,15 @@ impl Row { self.props.layout = std::mem::replace(&mut self.props.layout, BodyLayout::Stack).align(align); self } + + /// The row's line is at least `points` high, as a child of more than one line that high would make it: the + /// children that fill the line's height take at least it. A row of command groups keeps the height of its + /// rows of controls while its groups are shorter. Ignored by a row that wraps. + // design: allow[props/point-size](the least line of a row is the caller's measured extent (three control rows of a look and a title line), not a chosen size) + pub fn least_height(mut self, points: f32) -> Self { + self.props = self.props.least_height(points); + self + } } impl Default for Row {