rr-app-ribbon2: a content slot measures what its content allocated, not the stack's clipped response

The stack's response rect is clipped to the pane (sense_root intersects a root's rect with its clip), so a slot laid
out one bar high measured its content as one bar high and never grew: the group row under the strip was cut off. The
slot now reads the stack body's min_rect after its content ran, plus what the pane keeps around its body (its rule).
The trial reads the lines from the slot's Ui, not from clipped responses, with a scrolling group row in a child Ui.
DIAG line kept until the screenshot confirms it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Martin Ball
2026-11-19 00:51:53 +00:00
co-authored by Claude Opus 5.5
parent 23fa55c53d
commit a39debb431
2 changed files with 43 additions and 13 deletions
+19 -6
View File
@@ -702,7 +702,8 @@ impl<'a, S> AppShell<'a, S> {
let by_content = placed.sized_by_content();
let along_x = placed.along_x();
let Placed { slot, edge, named, add, .. } = placed;
let pane = ShellPane::new(slot.key()).edge(*edge).extent(extent).at(rect_of(slot.key()));
let at = rect_of(slot.key());
let pane = ShellPane::new(slot.key()).edge(*edge).extent(extent).at(at);
// Every slot is a chrome pane: it paints the surface under its bar or rail and the rule toward
// the body.
let mut region = ShellRegion::chrome(pane).id_salt(("slot", slot.key()));
@@ -726,15 +727,27 @@ impl<'a, S> AppShell<'a, S> {
region.show(ui, |ui, bcx| fill(ui, bcx));
continue;
}
// The content's extent along the slot's edge: a top or bottom slot's content fills its width
// and is as tall as it is; a rail's is as wide as it is.
// The slot's extent along its edge: what its content allocated, plus what the pane keeps
// around its body (its rule). A top or bottom slot's content fills its width and is as tall
// as it is; a rail's is as wide as it is. The content is read from the `Ui` it allocated in,
// never from the stack's response: a response rect is clipped to the pane (`sense_root`), so
// it can never report more than the extent the slot was laid out at.
let took = region
.show(ui, |ui, bcx| {
let room = ui.max_rect();
let inset = (if along_x { at.width() - room.width() } else { at.height() - room.height() }).max(0.0);
let stack = if along_x { Stack::new() } else { Stack::new().fill_width() };
let rect = stack.show(ui, |ui, _| fill(ui, bcx)).output.rect;
if along_x { rect.width() } else { rect.height() }
stack
.show(ui, |ui, _| {
fill(ui, bcx);
let content = ui.min_rect();
if along_x { content.width() } else { content.height() }
})
.inner
.map(|content| content + if inset.is_finite() { inset } else { 0.0 })
})
.inner;
.inner
.flatten();
eprintln!(
"DIAG ribbon: slot {key:?} laid out at extent {extent} in {:?}, content took {took:?}, sizing {}",
rect_of(key),
+24 -7
View File
@@ -5,7 +5,7 @@
use craft_host::target::ShellInfo;
use craft_ui::bars::{Bar, BarKind};
use craft_ui::buttons::Button;
use craft_ui::contract::{Bind, CommandSet, Props as _, Show as _, ShowContainer as _};
use craft_ui::contract::{Bind, CommandSet, Props as _, Scroll, Show as _, ShowContainer as _};
use craft_ui::dialog::Dialog;
use craft_ui::display::Text;
use craft_ui::layout_components::{Row, Stack};
@@ -76,6 +76,11 @@ fn a_bar_in_a_top_slot_fills_it_and_centres_its_members_on_one_line() {
/// A top slot sized by its content (a ribbon: a strip over a taller group row) stacks its content, is as tall as both
/// lines, gives the lower line the slot's width, and the body starts under it.
///
/// The lower line is a ribbon's group row: a child `Ui` (a fill-width row that scrolls along x) holding a column far
/// taller than one bar. The trial reads where the lines lie from what they allocated in the slot's `Ui`, not from their
/// responses: a response rect is clipped to the pane, so a slot left one bar high would clip the row's response to fit
/// it and hide the fault.
#[trial]
fn a_top_slot_sized_by_its_content_stacks_it_and_takes_its_height() {
let seen = Rc::new(Cell::new(None::<(Rect, Rect, Rect, Rect)>));
@@ -84,24 +89,33 @@ fn a_top_slot_sized_by_its_content_stacks_it_and_takes_its_height() {
let (mut strip, mut row) = (Rect::NOTHING, Rect::NOTHING);
let shown = AppShell::new(WindowKey::main())
.top(Slot::new("ribbon").size(SlotSize::Content), |ui, _, _: &mut ()| {
strip = Row::new()
let top = ui.cursor().min.y;
let strip_x = Row::new()
.show(ui, |ui, _| {
Button::new("Home").show(ui);
Button::new("Insert").show(ui);
})
.output
.rect;
row = Row::new()
.rect
.x_range();
let strip_bottom = ui.min_rect().max.y;
let row_top = ui.cursor().min.y;
let row_x = Row::new()
.scroll(Scroll::horizontal())
.fill_width()
.show(ui, |ui, _| {
Stack::new().show(ui, |ui, _| {
for line in ["Paste", "Cut", "Copy", "Format Painter"] {
for line in ["Paste", "Cut", "Copy", "Format Painter", "Clipboard"] {
Button::new(line).show(ui);
}
});
})
.output
.rect;
.rect
.x_range();
let bottom = ui.min_rect().max.y;
strip = Rect::from_x_y_ranges(strip_x, top..=strip_bottom);
row = Rect::from_x_y_ranges(row_x, row_top..=bottom);
})
.body(|_, _, _| {})
.show(ui, &mut ());
@@ -112,9 +126,12 @@ fn a_top_slot_sized_by_its_content_stacks_it_and_takes_its_height() {
fixture.room(Vec2::new(600.0, 400.0)).settle();
let (slot, strip, row, body) = seen.get().expect("the ribbon slot shows");
const SLACK: f32 = 1.0;
// The rule toward the body, and rounding: a content-sized slot is no taller than its content and that.
const RULE: f32 = 4.0;
assert!(row.height() > 2.0 * strip.height(), "the row {row:?} is far taller than the strip {strip:?}, as a ribbon's group row is");
assert!(row.min.y >= strip.max.y - SLACK, "the row {row:?} lies under the strip {strip:?}, not beside it");
assert!(slot.min.y <= strip.min.y + SLACK && row.max.y <= slot.max.y + SLACK, "the slot {slot:?} holds the strip {strip:?} and the row {row:?}");
assert!(slot.height() >= strip.height() + row.height() - SLACK, "the slot {slot:?} is as tall as both lines, not one bar");
assert!(slot.height() <= row.max.y - strip.min.y + RULE, "the slot {slot:?} is as tall as its content, from {strip:?} to {row:?}");
assert!((row.width() - slot.width()).abs() <= SLACK, "the row {row:?} takes the slot's width {slot:?}");
assert!(body.min.y >= row.max.y - SLACK, "the body {body:?} starts under the row {row:?}");
}