mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-27 04:38:49 +00:00
craft-ui: a row's least line height (ContainerProps::least_height, Row::least_height)
An unwrapped row's line is at least the least height, as if a child of more than one line that high stood in it, so the children that fill the line take at least it.
This commit is contained in:
@@ -974,7 +974,7 @@ struct BodyRun<'r> {
|
||||
room_x: f32,
|
||||
scroll: Option<Scroll>,
|
||||
layout: &'r layout::BodyLayout,
|
||||
line: Option<f32>,
|
||||
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,
|
||||
|
||||
@@ -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<LeastWidth>,
|
||||
/// 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<f32>,
|
||||
/// 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<WrapWidth>,
|
||||
/// 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);
|
||||
|
||||
@@ -1554,13 +1554,16 @@ fn on_line(body: Id, own: Option<(f32, f32)>, shared: Option<f32>) -> 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<Id>, row: Option<Id>) {
|
||||
/// `Row` body `row`, its line start afresh, `least` high at least (`ContainerProps::least_height`).
|
||||
fn open_sweep(ctx: &egui::Context, target: Option<Id>, row: Option<Id>, least: f32) {
|
||||
if let Some(target) = target {
|
||||
open_first_lines(ctx, &[target]);
|
||||
}
|
||||
if let Some(row) = row {
|
||||
pass_state::with::<RowLines, _>(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::<RowLines, _>(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<R>(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<f32>,
|
||||
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<R>(
|
||||
ui: &mut Ui,
|
||||
env: &Env,
|
||||
id: Id,
|
||||
layout: &BodyLayout,
|
||||
gap: Vec2,
|
||||
shared: Option<f32>,
|
||||
line: BodyLine,
|
||||
mut body: impl FnMut(&mut Ui) -> R,
|
||||
) -> (R, Option<f32>) {
|
||||
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<R>(
|
||||
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.
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user