Skip to content

Unexpected extra blank space #18764

Open
Open
@lomirus

Description

@lomirus

Bevy version

0.16.0

What you did

[dependencies.bevy]
version = "0.16.0"
default-features = false
features = ["dynamic_linking", "bevy_ui", "bevy_winit", "bevy_ui_debug", "default_font"]
use bevy::prelude::*;

const BAR_WIDTH: f32 = 250.0;

fn init(mut commands: Commands) {
    commands.spawn((Camera3d::default(), IsDefaultUiCamera));

    commands.spawn((
        Node {
            align_items: AlignItems::Center,
            ..default()
        },
        children![(
            Node {
                flex_direction: FlexDirection::Column,
                width: Val::Px(BAR_WIDTH),
                ..default()
            },
            BackgroundColor(Color::WHITE),
            children![
                (
                    Text::new("Jan 1, 2000 01:00"),
                    TextFont {
                        font_size: 20.0,
                        ..default()
                    },
                    TextColor::from(Color::BLACK),
                ),
                (
                    Node {
                        width: Val::Px(BAR_WIDTH),
                        height: Val::Px(24.0),
                        ..default()
                    },
                    BackgroundColor(Srgba::hex("3ba6a3").unwrap().into()),
                )
            ]
        )],
    ));
}

fn toggle_debug_overlay(
    input: Res<ButtonInput<KeyCode>>,
    mut debug_options: ResMut<UiDebugOptions>,
) {
    if input.just_pressed(KeyCode::Space) {
        debug_options.toggle();
    }
}

fn main() {
    App::new()
        .add_systems(Startup, init)
        .add_systems(Update, toggle_debug_overlay)
        .add_plugins(DefaultPlugins)
        .run();
}

What went wrong

You can see that there is an extra blank area below the teal bar:

Image

However, there is no extra node to support the height.

It should look like this:

Image

Additional information

I found that simply removing AlignItems::Center from the outermost Node fixed the issue. However, AlignItems shouldn't cause this behavior (and it is required in my actual game), so I believe this is likely a bug, and it's related to AlignItems (at least).

Result of self.taffy.print_tree(implicit_viewport_node):

TREE
└──  GRID [x: 0    y: 0    w: 1600 h: 900  content_w: 313  content_h: 150  border: l:0 r:0 t:0 b:0, padding: l:0 r:0 t:0 b:0] (NodeId(4294967301))
    └──  FLEX ROW [x: 0    y: 0    w: 313  h: 150  content_w: 313  content_h: 150  border: l:0 r:0 t:0 b:0, padding: l:0 r:0 t:0 b:0] (NodeId(4294967298))
        └──  FLEX COL [x: 0    y: 0    w: 313  h: 150  content_w: 313  content_h: 60   border: l:0 r:0 t:0 b:0, padding: l:0 r:0 t:0 b:0] (NodeId(4294967300))
            ├──  LEAF [x: 0    y: 0    w: 313  h: 30   content_w: 256  content_h: 30   border: l:0 r:0 t:0 b:0, padding: l:0 r:0 t:0 b:0] (NodeId(4294967299))
            └──  LEAF [x: 0    y: 30   w: 313  h: 30   content_w: 0    content_h: 0    border: l:0 r:0 t:0 b:0, padding: l:0 r:0 t:0 b:0] (NodeId(4294967297))

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-UIGraphical user interfaces, styles, layouts, and widgetsC-BugAn unexpected or incorrect behaviorS-Needs-InvestigationThis issue requires detective work to figure out what's going wrong

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions