Port example 04

This commit is contained in:
2026-03-22 00:33:43 -04:00
parent 0d8bc38113
commit ed4c216f96
5 changed files with 615 additions and 17 deletions

View File

@@ -383,11 +383,17 @@ fn layout_element(
perf_stats.container_nodes += 1;
if element.children.is_empty() {
if pushed_clip {
scene.pop_clip();
}
return interaction;
}
let content = inset_rect(rect, content_insets(&element.style));
if content.size.width <= 0.0 || content.size.height <= 0.0 {
if pushed_clip {
scene.pop_clip();
}
return interaction;
}
interaction.children = layout_container_children(
@@ -1543,6 +1549,40 @@ mod tests {
);
}
#[test]
fn empty_rounded_container_pops_clip_before_following_sibling() {
let root = Element::column().children([
Element::column()
.height(56.0)
.corner_radius(12.0)
.background(Color::rgb(0x22, 0x33, 0x44)),
Element::paragraph(
"Sibling text should not inherit a stale clip from an empty rounded container.",
TextStyle::new(18.0, Color::rgb(0xFF, 0xFF, 0xFF)).with_line_height(24.0),
),
]);
let scene = layout_scene(1, UiSize::new(480.0, 240.0), &root);
let rounded_push = scene
.items
.iter()
.position(|item| matches!(item, DisplayItem::PushClip(_)))
.expect("rounded empty container should push a clip");
let rounded_pop = scene
.items
.iter()
.position(|item| matches!(item, DisplayItem::PopClip))
.expect("rounded empty container should pop its clip");
let sibling_text = scene
.items
.iter()
.position(|item| matches!(item, DisplayItem::Text(text) if text.text.contains("Sibling text")))
.expect("following sibling text should be emitted");
assert!(rounded_push < rounded_pop);
assert!(rounded_pop < sibling_text);
}
#[test]
fn shadowed_container_emits_shadow_rect_items() {
let root = Element::column().child(