From e4d8cbda9fce8a05cd6cde56a9d845fbdc9c3705 Mon Sep 17 00:00:00 2001 From: aiongg Date: Fri, 20 Nov 2026 09:46:45 +0000 Subject: [PATCH] craft-ui: a scrolling body in unbounded room shows its measured content A content-sized scroll container nested in a body that scrolls is offered no bound along y: its view is the line this pass measured, never an unbounded band (whose bar parts had NaN geometry). The card trials of the replay audit show cards as the gallery does: raised surfaces in rows that run only in view, the scrolling card sized to its content. --- .../ui-contract/src/contract/body/regions.rs | 7 ++++++- crates/ui-widgets/tests/it/body/memo_audit.rs | 21 ++++++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/crates/ui-contract/src/contract/body/regions.rs b/crates/ui-contract/src/contract/body/regions.rs index 3d2776a3e5..8eaa13d3f4 100644 --- a/crates/ui-contract/src/contract/body/regions.rs +++ b/crates/ui-contract/src/contract/body/regions.rs @@ -1,6 +1,7 @@ //! Where the header, body, footer and end regions sit inside the container, and the rules between them. use super::BodyHooks; +use super::scroll::scroll_of; use crate::contract::cx::BodyCx; use crate::contract::{Container, ContainerProps, FooterPlace, Gap, HeaderParts, LeastWidth, Mount, Pad, PadEdges, Sizing}; use crate::layout::{ColumnGroup, Columns, Reached}; @@ -380,7 +381,11 @@ impl<'b> BodyHooks<'b> { let line_h = if inline { body_h.max(header_h) } else { body_h }; // A full-height end region stands beside the footer too, so only the part of it under the line counts. let end_line = if full { (end_h - across_h).max(0.0) } else { end_h }; - (top + body_room, top + line_h.max(end_line).min(body_room)) + let line_bottom = top + line_h.max(end_line).min(body_room); + // A scrolling body offered no bound (a content-sized container in a body that scrolls) shows all of its + // content: its view is the line this pass measured, never an unbounded band. + let bottom = if body_room.is_finite() || scroll_of(props).is_none() { top + body_room } else { line_bottom }; + (bottom, line_bottom) } else { // A fill-width body is offered the room the parent gives this pass, never the height its content took last // pass: a collection that scrolls takes its rows up to that room, and from zero it would stay at zero. diff --git a/crates/ui-widgets/tests/it/body/memo_audit.rs b/crates/ui-widgets/tests/it/body/memo_audit.rs index 35eaed5066..ea108d81eb 100644 --- a/crates/ui-widgets/tests/it/body/memo_audit.rs +++ b/crates/ui-widgets/tests/it/body/memo_audit.rs @@ -3,7 +3,8 @@ //! no count. use craft_ui::buttons::Button; -use craft_ui::contract::{ContainerProps, Lazy, MemoProps, MemoView, Props as _, Scroll, Show as _, ShowContainer as _, Sizing}; +use craft_ui::contract::{ContainerProps, Lazy, MemoProps, MemoView, Props as _, Scroll, Show as _, ShowContainer as _}; +use craft_ui::style::SurfaceKind; use craft_ui::testing::layout::{allocate, in_region}; use craft_ui::testing::pointer::{moved, wheel}; use craft_ui::testing::{ @@ -236,21 +237,24 @@ fn a_view_whose_body_measured_in_its_run_replays_as_a_run_in_a_pass_that_does_no assert!(ran.is_empty(), "the view settles: {ran:?}"); } -/// A card: one pressable member of the arena around it. +/// A card, as the gallery's: a raised surface (painted snapped to the pixel grid) holding one pressable member of the +/// arena around it. #[derive(MemoProps)] struct Card { at: usize, } fn card(props: &mut Card, ui: &mut Ui) { - Button::new(format!("Card {}", props.at)).show(ui); + Slab::new(ContainerProps::new().surface(SurfaceKind::Raised)).id_salt(("card", props.at)).show(ui, |ui, _| { + Button::new(format!("Card {}", props.at)).show(ui); + }); } -/// A card holding a scrolling body of its own, whose rows report their places to it. +/// A card holding a scrolling body of its own, sized to its content, whose rows report their places to it. fn scrolling_card(props: &mut Card, ui: &mut Ui) { let room = allocate(ui, Vec2::new(100.0, 80.0)); in_region(ui, room, |ui| { - Slab::new(ContainerProps::new().scroll(Scroll::vertical()).sizing(Sizing::Fill)).id_salt(("inner", props.at)).show(ui, |ui, _| { + Slab::new(ContainerProps::new().surface(SurfaceKind::Raised).scroll(Scroll::vertical())).id_salt(("inner", props.at)).show(ui, |ui, _| { for at in 0..6 { Lazy::new(at, 20.0).show(ui, |ui| { Button::new(format!("Row {at}")).show(ui); @@ -264,14 +268,17 @@ fn scrolling_card(props: &mut Card, ui: &mut Ui) { /// the narrow ones). const BESIDE: Pos2 = Pos2::new(140.0, 50.0); -/// Cards shown by `body` in a scrolling arena body, under a lead of `lead` points. +/// Cards shown by `body` in a scrolling arena body under a lead of `lead` points, as the gallery's grid shows them: each +/// in a row that runs only in view (`Lazy`). fn cards(lead: f32, body: fn(&mut Card, &mut Ui)) -> impl FnMut(&mut Ui) { move |ui: &mut Ui| { in_region(ui, Rect::from_min_size(Pos2::new(10.0, 10.0), Vec2::new(160.0, 200.0)), |ui| { Slab::new(ContainerProps::new().scroll(Scroll::vertical()).arena(true)).id_salt("cards").show(ui, |ui, _| { ui.add_space(lead); for at in 0..12 { - MemoView::new(("card", at), Card { at }, body).show(ui); + Lazy::new(("row", at), 40.0).show(ui, |ui| { + MemoView::new(("card", at), Card { at }, body).show(ui); + }); } }); });