diff --git a/crates/ui-contract/src/contract/body.rs b/crates/ui-contract/src/contract/body.rs index 5febe548f..2af4947a4 100644 --- a/crates/ui-contract/src/contract/body.rs +++ b/crates/ui-contract/src/contract/body.rs @@ -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, diff --git a/crates/ui-contract/src/contract/body/hooks.rs b/crates/ui-contract/src/contract/body/hooks.rs index 5df881b38..06f078386 100644 --- a/crates/ui-contract/src/contract/body/hooks.rs +++ b/crates/ui-contract/src/contract/body/hooks.rs @@ -138,6 +138,7 @@ impl ShapeHooks 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 ShapeHooks 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 { diff --git a/crates/ui-contract/src/contract/body/regions.rs b/crates/ui-contract/src/contract/body/regions.rs index 6888d9d24..3b04f3a6c 100644 --- a/crates/ui-contract/src/contract/body/regions.rs +++ b/crates/ui-contract/src/contract/body/regions.rs @@ -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 { diff --git a/crates/ui-contract/src/contract/body/size.rs b/crates/ui-contract/src/contract/body/size.rs index 51805f6aa..e0ff4844d 100644 --- a/crates/ui-contract/src/contract/body/size.rs +++ b/crates/ui-contract/src/contract/body/size.rs @@ -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)) } } diff --git a/crates/ui-contract/src/contract/container.rs b/crates/ui-contract/src/contract/container.rs index 5f6a26d4f..9874b2b66 100644 --- a/crates/ui-contract/src/contract/container.rs +++ b/crates/ui-contract/src/contract/container.rs @@ -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. diff --git a/crates/ui-widgets/src/bars/bar.rs b/crates/ui-widgets/src/bars/bar.rs index fcadc7295..4ba745797 100644 --- a/crates/ui-widgets/src/bars/bar.rs +++ b/crates/ui-widgets/src/bars/bar.rs @@ -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