Skip to content

Invalid ui node size when creating tree with 5-level depth and 100% height #7994

@jkb0o

Description

@jkb0o

Bevy version

bevy: 0.11.0-dev 21ddc60
taffy: 0.3.6

What you did

I create multiple nested ui nodes with depth level at least 5 and provide to them different style params (padding, margin and size):

commands.spawn(NodeBundle {
    background_color: Color::WHITE.into(),
    style: Style { 
        margin: UiRect::all(Val::Px(20.)),
        size: Size::new(Val::Percent(20.), Val::Px(200.)),
        align_items: AlignItems::FlexStart,
        justify_content: JustifyContent::FlexStart,
        ..default()
    },
    ..default()
}).with_children(|parent| {
    for idx in 0..4 {
        parent.spawn(NodeBundle {
            background_color: Color::RED.into(),
            style: Style {
                min_size: Size::all(Val::Px(40.)),
                margin: UiRect::all(Val::Px(5.)),
                padding: UiRect::all(Val::Px(5.)),
                ..default()
            },
            ..default()
        }).with_children(|parent| {
            parent.spawn(NodeBundle {
                background_color: Color::GREEN.into(),
                style: Style {
                    size: Size::all(Val::Percent(100.)),
                    padding: UiRect::all(Val::Px(5.0)),
                    ..default()
                },
                ..default()
            })
            .with_children(|parent| {
                let mut size = Size::default();
                size.width = Val::Percent(100.);
                if idx >= 2 {
                    // Commenting this line makes all nodes
                    // behaves the same
                    size.height = Val::Percent(100.);
                }
                parent.spawn(NodeBundle {
                    background_color: Color::BLUE.into(),
                    style: Style {
                        size,
                        padding: UiRect::all(Val::Px(5.)),
                        ..default()
                    },
                    ..default()
                })
                // Commenting this makes all nodes bahaves the same
                // no matter what the size of blue node
                .with_children(|parent| {
                    parent.spawn(NodeBundle::default());
                })
                ;
            })
            ;
        });
    }
});

What went wrong

Setting height to the blue node to Val::Percent(100.) makes the outer nodes grow. This happens only if the blue node has another child. On the screenshot the first two nodes use default height, the rest two nodes has 100% height:

Screenshot 2023-03-09 at 08 07 12

I expect all nodes are the same size in both cases: if I specify the 100% height to the blue one or if I add extra empty children to blue nodes.

Example project: ui_height_0_11.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-UIGraphical user interfaces, styles, layouts, and widgetsC-BugAn unexpected or incorrect behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions