Merge pull request #3639 from aiongg/footer-clamp

craft-ui: a labelled container narrower than its padding places its footer without a panic
This commit is contained in:
aiongg authored and GitHub committed 2026-11-26 01:28:11 -05:00
commit dc2cb42b15
2 files changed
+27 -3

No files matched your search

@@ -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
@@ -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]);
}
}