A bar's end region sits space.gap.stack from its body

EndRegion carries the gap role between the body and the region (Tight by default); Bar sets Stack, the old
status and options bars' gap before their trailing group.
This commit is contained in:
aiongg
2026-11-12 14:32:44 +00:00
parent 8d42eac038
commit da5cdafa6e
6 changed files with 26 additions and 13 deletions
+3
View File
@@ -64,6 +64,8 @@ pub(super) struct BodyHooks<'b> {
open_given: bool,
/// The gap between an inline header and the body, and between a header and its trailing region.
region_gap: f32,
/// The gap between the body and the end region (`EndRegion::gap`).
end_gap: f32,
/// The space between a stacked header and the body (`HeaderRegion::gap`), zero without one.
header_gap: f32,
/// The least width of the content, from `ContainerProps::least_width`.
@@ -143,6 +145,7 @@ impl<'b> BodyHooks<'b> {
reuse: false,
open_given: false,
region_gap: 0.0,
end_gap: 0.0,
header_gap: 0.0,
least_width: 0.0,
overflow: 0.0,
@@ -138,6 +138,7 @@ impl<C: Container> ShapeHooks<C> for BodyHooks<'_> {
// The overlay host decides a layer's Escape; so does a full-window mount's.
self.layer = matches!(props.mount, Mount::Layer(_) | Mount::Viewport { .. } | Mount::FullWindow);
self.region_gap = gap_of(&env.tokens, Gap::Tight);
self.end_gap = gap_of(&env.tokens, props.end.map_or(Gap::Tight, |end| end.gap));
self.header_gap = header_gap_of(props, &env.tokens);
self.least_width = least_of(&env.tokens, props.least_width);
let quiet = stage.is_peek() || crate::runtime::measure::active(&ctx);
@@ -317,6 +318,7 @@ impl<C: Container> ShapeHooks<C> for BodyHooks<'_> {
self.last = BodyView::default();
self.offset = ScrollPos::default();
self.region_gap = gap_of(&at.env.tokens, Gap::Tight);
self.end_gap = gap_of(&at.env.tokens, props.end.map_or(Gap::Tight, |end| end.gap));
self.header_gap = header_gap_of(&props, &at.env.tokens);
self.least_width = least_of(&at.env.tokens, props.least_width);
self.room = match at.width {
@@ -380,7 +380,7 @@ impl<'b> BodyHooks<'b> {
end.x.max(footer_w).min(width)
});
let taken = measured.unwrap_or(0.0);
let cut = if taken > 0.0 { taken + self.region_gap } else { 0.0 };
let cut = if taken > 0.0 { taken + self.end_gap } else { 0.0 };
let end_w = measured.unwrap_or(width);
let end_bottom = if full { footer_top + across_h } else { footer_top };
let mut end = if rtl {
+4 -4
View File
@@ -162,14 +162,14 @@ impl<'b> BodyHooks<'b> {
let in_end = footer_in_end(props);
let end = if in_end { Vec2::new(end.x.max(footer.x), end.y + footer.y) } else { end };
let across = if in_end { Vec2::ZERO } else { footer };
let gap = |width: f32| if width > 0.0 { width + self.region_gap } else { 0.0 };
let gap = |width: f32, gap: f32| if width > 0.0 { width + gap } else { 0.0 };
let inline = props.header.is_some_and(|header| header.inline);
// The line: the body with an inline header before it.
let line = if inline { Vec2::new(body.x + gap(header.x), body.y.max(header.y)) } else { body };
let line = if inline { Vec2::new(body.x + gap(header.x, self.region_gap), body.y.max(header.y)) } else { body };
let (width, height) = if end_full_height(props) {
(line.x.max(across.x) + gap(end.x), (line.y + across.y).max(end.y))
(line.x.max(across.x) + gap(end.x, self.end_gap), (line.y + across.y).max(end.y))
} else {
((line.x + gap(end.x)).max(across.x), line.y.max(end.y) + across.y)
((line.x + gap(end.x, self.end_gap)).max(across.x), line.y.max(end.y) + across.y)
};
if inline { Vec2::new(width, height) } else { Vec2::new(width.max(header.x), height + header.y + self.header_space(header.y)) }
}
+10 -2
View File
@@ -384,12 +384,14 @@ pub struct EndRegion {
/// Whether the region takes the full height under the header, down to the container's bottom, beside the body and
/// the footer, instead of the line's height. Its content then starts at the top, else it is centred on the line.
pub full_height: bool,
/// The gap between the body and the region.
pub gap: Gap,
}
impl EndRegion {
/// An end region as high as the line.
/// An end region as high as the line, `space.gap.tight` from the body.
pub const fn new() -> Self {
EndRegion { full_height: false }
EndRegion { full_height: false, gap: Gap::Tight }
}
/// Whether the region takes the full height under the header.
@@ -397,6 +399,12 @@ impl EndRegion {
self.full_height = on;
self
}
/// Sets the gap between the body and the region.
pub const fn gap(mut self, gap: Gap) -> Self {
self.gap = gap;
self
}
}
/// Which end of the content a scroll region stays at when the content grows.
+6 -6
View File
@@ -77,10 +77,10 @@ impl Outcome for BarOutput {
/// size, an options or status bar's at the small one. They are one roving group unless the bar is made of
/// [`tab_stops`](Bar::tab_stops). The bar is as tall as its tallest member plus the control padding, and takes the
/// width it is offered. A bar of one row lays its body out as a row; a bar of several rows as a stack whose rows the
/// caller makes with `Row`. A row too long for the bar first narrows its selects and elidable text, then scrolls, so a
/// member past the edge is reached by Tab and revealed. A rule between groups of members is a `Divider::vertical()`. A
/// bar with `commit_cancel` ends with a cancel and a commit button in its end region, outside the scroll; they run
/// `BarCommands`.
/// caller makes with `Row`. A row too long for the bar first narrows its selects and elidable text, the last first,
/// then scrolls, so a member past the edge is reached by Tab and revealed. A rule between groups of members is a
/// `Divider::vertical()`. A bar with `commit_cancel` ends with a cancel and a commit button in its end region, outside
/// the scroll and `space.gap.stack` from the body; they run `BarCommands`.
#[derive(crate::contract::Component)]
#[component(container)]
pub struct Bar<'a> {
@@ -142,7 +142,7 @@ impl<'a> Bar<'a> {
#[must_use]
pub fn commit_cancel(mut self, commit: impl Into<Label>, cancel: impl Into<Label>) -> Self {
self.commit_cancel = Some((commit.into(), cancel.into()));
self.props = self.props.end(EndRegion::new()).command_scope(BarCommands::SCOPE);
self.props = self.props.end(EndRegion::new().gap(Gap::Stack)).command_scope(BarCommands::SCOPE);
self
}
@@ -151,7 +151,7 @@ impl<'a> Bar<'a> {
#[must_use]
pub fn trailing(mut self, group: impl FnMut(&mut Ui) + 'a) -> Self {
self.trailing = Some(Box::new(group));
self.props = self.props.end(EndRegion::new());
self.props = self.props.end(EndRegion::new().gap(Gap::Stack));
self
}
}