From b9181a7b75fa943b8703aeb9dc56d5b33ccbe023 Mon Sep 17 00:00:00 2001 From: aiongg Date: Thu, 26 Nov 2026 04:50:33 +0000 Subject: [PATCH] craft-ui: a container given less width than its padding places its regions with no width --- .../ui-contract/src/contract/body/regions.rs | 9 +++++--- crates/ui-contract/tests/it/layout/body.rs | 21 +++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/crates/ui-contract/src/contract/body/regions.rs b/crates/ui-contract/src/contract/body/regions.rs index 5b4025a61e..de994c9ea4 100644 --- a/crates/ui-contract/src/contract/body/regions.rs +++ b/crates/ui-contract/src/contract/body/regions.rs @@ -283,11 +283,12 @@ impl BodyHooks<'_> { regions.footer.max.y = bottom + self.measured_footer.y; } let mut footer_rect = regions.footer; + // The footer's start edge moves to the control column's, never past its own end edge. if props.label.is_some() { if rtl { - footer_rect.max.x = body_rect.max.x.clamp(footer_rect.min.x, footer_rect.max.x); + footer_rect.max.x = body_rect.max.x.min(footer_rect.max.x).max(footer_rect.min.x); } else { - footer_rect.min.x = body_rect.min.x.clamp(footer_rect.min.x, footer_rect.max.x); + footer_rect.min.x = body_rect.min.x.max(footer_rect.min.x).min(footer_rect.max.x); } } let offset = if rtl { regions.footer.max.x - footer_rect.max.x } else { footer_rect.min.x - regions.footer.min.x }; @@ -473,7 +474,9 @@ impl<'b> BodyHooks<'b> { } else if !self.given.0 { self.shared_width(room.x, props).max(inner.width()) } else { - inner.width() + // A container given less width than its padding has an inverted inner rect: its regions take no width, + // at their start edge. + inner.width().max(0.0) }; // A measure with no room limit along x offers an unbounded width. Left to right the body runs from its start // edge to +inf as egui allows; right to left its start edge is the right one, and an unbounded width would put diff --git a/crates/ui-contract/tests/it/layout/body.rs b/crates/ui-contract/tests/it/layout/body.rs index 3cea18b400..4d3b5e9864 100644 --- a/crates/ui-contract/tests/it/layout/body.rs +++ b/crates/ui-contract/tests/it/layout/body.rs @@ -564,3 +564,24 @@ fn a_scrolling_container_in_a_right_to_left_row_measures_and_shows_finite() { assert!(panel.min.x > beside.max.x - SLACK, "under RTL the container is right of the probe after it: {dump}"); } } + +/// A labelled container with a footer, shown in a rect narrower than its padding, in either direction: its measuring +/// run places the footer under the control column of a line with no room, and the container shows. +#[trial] +fn a_labelled_container_narrower_than_its_padding_places_its_footer() { + use craft_ui::contract::{FooterRegion, Pad, SideLabel}; + use craft_ui_test_kit::body::Slab; + for direction in [Direction::Ltr, Direction::Rtl] { + let (_, rects) = lay_out(Some(direction), |ui| { + let at = Rect::from_min_size(ui.available_rect_before_wrap().min, Vec2::new(4.0, 60.0)); + let props = ContainerProps::new().label(SideLabel::new()).footer(FooterRegion::new()).pad(Pad::Regular).sizing(Sizing::FillWidth); + let narrow = ui.scope_builder(egui::UiBuilder::new().max_rect(at), |ui| { + Slab::new(props).label("Balance").id_salt("field").show(ui, |ui, _| { + Block::new(ITEM).show(ui); + }) + }); + vec![narrow.inner.output.rect] + }); + assert!(rects[0].min.is_finite() && rects[0].max.is_finite(), "{direction:?}: the container shows at {:?}", rects[0]); + } +}