layout: scroll tests pin both axes (padding box, content bound); two nested overlays pin their order

This commit is contained in:
Meta Vens 2026-11-28 06:53:28 +01:00
commit a8d234cfdb

View file

@ -1074,12 +1074,13 @@ fn nested_overlays_resolve_their_anchors_in_document_order() {
overlay("outer", at("target"), vec![ overlay("outer", at("target"), vec![
bx("pad", BoxStyle { margin: Edges { left: px(7.0), top: px(9.0), ..edges(px(0.0)) }, ..sized(40.0, 20.0) }, vec![]), bx("pad", BoxStyle { margin: Edges { left: px(7.0), top: px(9.0), ..edges(px(0.0)) }, ..sized(40.0, 20.0) }, vec![]),
overlay("inner", at("pad"), vec![bx("deep", sized(5.0, 5.0), vec![])]), overlay("inner", at("pad"), vec![bx("deep", sized(5.0, 5.0), vec![])]),
overlay("inner2", at("pad"), vec![bx("deep2", sized(5.0, 5.0), vec![])]),
]), ]),
overlay("sibling", Anchor::Viewport, vec![]), overlay("sibling", Anchor::Viewport, vec![]),
]); ]);
let laid = lay(root, 400.0, 300.0); let laid = lay(root, 400.0, 300.0);
// Each overlay is followed by the overlays inside it, then the next sibling. // Each overlay is followed by the overlays inside it, then the next sibling.
assert_eq!(ids(&laid), ["root", "target", "outer", "pad", "inner", "deep", "sibling"]); assert_eq!(ids(&laid), ["root", "target", "outer", "pad", "inner", "deep", "inner2", "deep2", "sibling"]);
// The overlay root is a row flex container at the anchor origin: its child starts at its margin. // The overlay root is a row flex container at the anchor origin: its child starts at its margin.
assert_eq!(rect(&laid, "pad"), (7.0, 9.0, 40.0, 20.0)); assert_eq!(rect(&laid, "pad"), (7.0, 9.0, 40.0, 20.0));
assert_eq!(rect(&laid, "inner"), (7.0, 9.0, 40.0, 20.0)); assert_eq!(rect(&laid, "inner"), (7.0, 9.0, 40.0, 20.0));
@ -1155,30 +1156,38 @@ fn scroll_extent_is_measured_from_the_padding_box() {
// A 4 px border on a 100x100 box: the padding box is 92x92, so the same content // A 4 px border on a 100x100 box: the padding box is 92x92, so the same content
// scrolls further than it would in the border box. // scrolls further than it would in the border box.
let paint = Paint { background: None, border: Some(Border { color: ColorRef::Rgba(Rgba { r: 0, g: 0, b: 0, a: 255 }), width: 4.0 }), radius: 0.0 }; let paint = Paint { background: None, border: Some(Border { color: ColorRef::Rgba(Rgba { r: 0, g: 0, b: 0, a: 255 }), width: 4.0 }), radius: 0.0 };
let rows: Vec<Node> = (0..10).map(|i| bx(&format!("row{i}"), BoxStyle { shrink: 0.0, ..sized(10.0, 25.0) }, vec![])).collect(); let rows: Vec<Node> = (0..10).map(|i| bx(&format!("row{i}"), BoxStyle { shrink: 0.0, ..sized(if i == 0 { 160.0 } else { 10.0 }, 25.0) }, vec![])).collect();
let style = BoxStyle { overflow: Overflow::Scroll, direction: Direction::Column, ..sized(100.0, 100.0) }; let style = BoxStyle { overflow: Overflow::Scroll, direction: Direction::Column, ..sized(100.0, 100.0) };
let laid = lay(bx("root", plain(), vec![bx_paint("list", style, paint, rows)]), 400.0, 300.0); let laid = lay(bx("root", plain(), vec![bx_paint("list", style, paint, rows)]), 400.0, 300.0);
let list = laid.nodes.iter().find(|n| n.id.as_str() == "list").unwrap(); let list = laid.nodes.iter().find(|n| n.id.as_str() == "list").unwrap();
assert_eq!(list.max_scroll, Some((0.0, 158.0))); assert_eq!(list.max_scroll, Some((68.0, 158.0)));
} }
#[test] #[test]
fn a_scroll_extent_past_the_bound_refuses_though_every_rect_is_in_range() { fn a_scroll_extent_past_the_bound_refuses_though_every_rect_is_in_range() {
// The scroll box sits far left, so the child absolute right edge is in range while its // The scroll box sits far left, so the child absolute right edge is in range while its
// extent from the box origin is past 2^21: only the content extent is out of range. // extent from the box origin is past 2^21: only the content extent is out of range.
let tree = |overflow: Overflow| { for horizontal in [true, false] {
let list = BoxStyle { overflow, shrink: 0.0, margin: Edges { left: px(-1_500_000.0), ..edges(px(0.0)) }, ..sized(100.0, 100.0) }; let tree = |overflow: Overflow| {
let child = BoxStyle { shrink: 0.0, margin: Edges { left: px(1_000_000.0), ..edges(px(0.0)) }, ..sized(2_000_000.0, 10.0) }; let (pull, push) = (px(-1_500_000.0), px(1_000_000.0));
bx("root", plain(), vec![bx("list", list, vec![bx("child", child, vec![])])]) let (list_margin, child_margin, child_size) = if horizontal {
}; (Edges { left: pull, ..edges(px(0.0)) }, Edges { left: push, ..edges(px(0.0)) }, (2_000_000.0, 10.0))
let run = |overflow: Overflow| { } else {
let tree = bind(&mut MemState::new(), &surface_of(tree(overflow))).unwrap(); (Edges { top: pull, ..edges(px(0.0)) }, Edges { top: push, ..edges(px(0.0)) }, (10.0, 2_000_000.0))
layout(&tree, &pixels(800.0, 600.0, 1.0), &mut FixedMeasure::pixels(&[])) };
}; let list = BoxStyle { overflow, shrink: 0.0, margin: list_margin, ..sized(100.0, 100.0) };
assert!(run(Overflow::Visible).is_ok(), "the same boxes without a scroll lay out"); let child = BoxStyle { shrink: 0.0, margin: child_margin, ..sized(child_size.0, child_size.1) };
match run(Overflow::Scroll) { bx("root", plain(), vec![bx("list", list, vec![bx("child", child, vec![])])])
Err(LayoutError::OutOfRange(d)) => assert_eq!(d.node.as_ref().map(|n| n.as_str()), Some("list")), };
other => panic!("{other:?}"), let run = |overflow: Overflow| {
let tree = bind(&mut MemState::new(), &surface_of(tree(overflow))).unwrap();
layout(&tree, &pixels(800.0, 600.0, 1.0), &mut FixedMeasure::pixels(&[]))
};
assert!(run(Overflow::Visible).is_ok(), "the same boxes without a scroll lay out, horizontal {horizontal}");
match run(Overflow::Scroll) {
Err(LayoutError::OutOfRange(d)) => assert_eq!(d.node.as_ref().map(|n| n.as_str()), Some("list")),
other => panic!("horizontal {horizontal}: {other:?}"),
}
} }
} }