look-7a: a container's least width holds in the measure its parent places it by, as in its own extent; a row gave a File page's side menu only its widest name (about 123 pt for 200); trial

This commit is contained in:
Martin Ball
2026-11-19 19:50:43 +00:00
parent 37b862c663
commit d928a407cf
2 changed files with 47 additions and 1 deletions
@@ -434,6 +434,10 @@ impl<C: Container> ShapeHooks<C> for BodyHooks<'_> {
// A layer hung from an opener or a rect is at least as wide as its overlay asks for, in the measuring run too,
// so the rows of a content-sized list inside it are placed at that width.
let took = Vec2::new(overlay_of(&props).map_or(took.x, |overlay| took.x.max(crate::contract::overlay::anchor_floor(overlay))), took.y);
// The least width holds in the measure a parent places it by, as in its own extent (`wanted_width`): a row
// measuring a side menu among its children gave it only its content's width, so the menu shrank to its widest
// row's name.
let took = Vec2::new(took.x.max(self.least_width + pad.x), took.y);
self.overflow = (took.x - self.room.x).max(0.0);
// A body wider than the room overflows it, or scrolls along it; either way the container keeps to the room.
Vec2::new(took.x.min(self.room.x), if vertical { took.y.min(self.room.y) } else { took.y })
@@ -4,7 +4,7 @@
//! row there too.
use craft_ui::buttons::Button;
use craft_ui::contract::{LeastWidth, Props as _, Show as _, ShowContainer as _, WrapWidth};
use craft_ui::contract::{Gap, LeastWidth, Props as _, Scroll, Show as _, ShowContainer as _, Sizing, WrapWidth};
use craft_ui::display::Text;
use craft_ui::layout_components::{Row, Stack};
use craft_ui::testing::{Fixture, trial};
@@ -43,6 +43,48 @@ fn a_stacks_least_width_holds_it_wider_than_narrow_content() {
assert!(menu.width() > plain.width() + 60.0, "the side menu's least width holds it wider: {menu:?} against {plain:?}");
}
/// In a row beside a page that fills, a full-height side menu keeps its least width: the row places its children by
/// their measure, and that measure held only the menu's content (a File page's rail came out at its widest name).
#[trial]
fn a_side_menu_in_a_row_keeps_its_least_width() {
let shown = |least: bool| {
let seen = Rc::new(Cell::new((Rect::NOTHING, Rect::NOTHING)));
let out = Rc::clone(&seen);
let mut fixture = Fixture::new(move |ui| {
let (menu, page) = (Cell::new(Rect::NOTHING), Cell::new(Rect::NOTHING));
let _ = Row::new().fill().show(ui, |ui, _| {
let mut stack = Stack::new().sizing(Sizing::FillHeight).gap(Gap::None).scroll(Scroll::vertical()).footer(|ui, _| {
let _ = Button::new("About").sizing(Sizing::FillWidth).show(ui);
});
if least {
stack = stack.least_width(LeastWidth::SideMenu);
}
menu.set(stack.show(ui, |ui, _| {
let _ = Button::new("Home").sizing(Sizing::FillWidth).show(ui);
})
.output
.rect);
page.set(Stack::new().fill().show(ui, |ui, _| {
let _ = Text::new("Page").show(ui);
})
.output
.rect);
});
if !ui.is_sizing_pass() {
out.set((menu.get(), page.get()));
}
});
fixture.room(Vec2::new(1440.0, 900.0)).settle();
seen.get()
};
let (plain, _) = shown(false);
let (menu, page) = shown(true);
assert!(plain != Rect::NOTHING && menu != Rect::NOTHING && page != Rect::NOTHING, "the menu and the page showed");
assert!(menu.width() > plain.width() + 60.0, "the side menu's least width holds in the row: {menu:?} against {plain:?}");
assert!(page.left() >= menu.right() - 0.5, "the page starts after the menu: {page:?} after {menu:?}");
assert!(menu.height() > 800.0, "the menu is as tall as the row: {menu:?}");
}
#[trial]
fn a_stacks_wrap_width_breaks_a_long_paragraph_at_the_column() {
let (plain, one_line) = shown(Stack::new, true);