bevyengine / bevyengine/bevy

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

Open
#4,237 4 comments 0 reactions 0 assignees View on GitHub
A-UI C-Bug
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## Bevy version

0.6.1

## Operating system & version

Windows 11

## What you did

I compiled and ran this code (when a valid font)
```rust
use bevy::prelude::*;

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

fn setup_ui(mut c: Commands, assets: Res) {
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


.row {
display: flex;
flex-direction: row;
}

.col {
display: flex;
flex-direction: column;
}


-


/

\


|

```
which looks like this
![image](https://user-images.githubusercontent.com/1251609/158731720-3544a945-1117-4bd9-8ca6-74320d19e343.png)

## What actually happened

This is what bevy renders
![image](https://user-images.githubusercontent.com/1251609/158731841-c62d9e7f-d02e-466d-9dd2-b4bd88a41dcc.png)

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](https://user-images.githubusercontent.com/1251609/158732128-57a2066a-d329-48ff-a36a-e01386f94453.png)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.