Skip to content

A flex column nested inside a flex row results in unexpected layout calculation #4237

@Earthmark

Description

@Earthmark

Bevy version

0.6.1

Operating system & version

Windows 11

What you did

I compiled and ran this code (when a valid font)

use bevy::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_startup_system(setup_ui)
        .run();
}

fn setup_ui(mut c: Commands, assets: Res<AssetServer>) {
    c.spawn_bundle(UiCameraBundle::default());

    let style = TextStyle {
        font: assets.load("Karla-VariableFont_wght.ttf"),
        font_size: 50.0,
        ..Default::default()
    };

    let label = |s: &'static str| TextBundle {
        text: Text::with_section(s, style.clone(), Default::default()),
        ..Default::default()
    };

    fn row() -> NodeBundle {
        NodeBundle {
            style: Style {
                flex_direction: FlexDirection::Row,
                ..Default::default()
            },
            color: Color::NONE.into(),
            ..Default::default()
        }
    }

    fn column() -> NodeBundle {
        NodeBundle {
            style: Style {
                flex_direction: FlexDirection::Column,
                ..Default::default()
            },
            color: Color::NONE.into(),
            ..Default::default()
        }
    };

    c.spawn_bundle(row()).with_children(|c| {
        c.spawn_bundle(label("-"));

        c.spawn_bundle(column()).with_children(|c| {
            c.spawn_bundle(label("/"));
            c.spawn_bundle(label("\\"));
        });

        c.spawn_bundle(label("|"));
    });
}

What you expected to happen

I expected a vertically reversed version of this html

<html>

<head>
  <style>
    .row {
      display: flex;
      flex-direction: row;
    }

    .col {
      display: flex;
      flex-direction: column;
    }
  </style>
</head>

<body>
  <div class="row">
    <div>-</div>
    <div class="col">
      <div>/</div>
      <div>\</div>
    </div>
    <div>|</div>
  </div>
</body>

</html>

which looks like this
image

What actually happened

This is what bevy renders
image

The row flex was ignored, and the column goes off the screen. Elements after the column are also missing.

Additional information

If I remove the children of the column, but keep the column itself there the row works fine. It looks like the column having content seems to break the row calculation.
image

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