bevyengine / bevyengine/bevy

Flexbox Nodes within a CSS Flex are inproperly snapping to pixels

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

Description

Trying to make my first UI in bevy ( version 0.18.0 ).

If you use Display::Flex inside a Display::Grid layout like this:

```
use bevy::{
prelude::*,
};

fn main() {
App::new()
.insert_resource(ClearColor(Color::BLACK))
.add_plugins(DefaultPlugins)
.add_systems(Startup, spawn_layout)
.run();
}

fn spawn_layout(
mut commands: Commands,
) {
commands.spawn(Camera2d);

let rows = [
0.0,
0.2,
0.4,
0.6,
0.8,
1.0,
];

commands.spawn((
Node {
display: Display::Grid,

width: percent(100),
height: percent(100),

grid_template_columns: vec![GridTrack::flex(1.0)],

// This:
grid_template_rows: vec![
GridTrack::flex(1.0),
GridTrack::flex(1.0),
],

..default()
},
BackgroundColor(Color::BLACK),

children![
(
Node { display: Display::Grid, ..default() },
),
(
Node {
display: Display::Grid,

..default()
},

children![
(
Node {
display: Display::Flex,
flex_direction: FlexDirection::Column,

..default()
},

Children::spawn(SpawnIter(
rows.into_iter().map(move |v| node(v)),
)),
),
]
),
],
)
);
}

fn node(u: f32) -> impl Bundle {
let width = 35.0;
let hue = u * 120.0;
let left = Val::Percent( u * (100.0 - width) );
let right = Val::Percent(100.0-(u * (100.0 - width) + width));

(
Node {
width: percent(100),
height: percent(100),

..default()
},
BackgroundColor(Color::hsva(hue, 0.3, 0.3, 0.5)),
children![
(
Node {
position_type: PositionType::Absolute,

left,
right,
top: Val::Percent(0.0),
bottom: Val::Percent(0.0),

..default()
},
BackgroundColor(Color::WHITE.with_alpha(0.15)),

),
]
)
}
```

At some window sizes nodes are misaligned like this:

https://github.com/user-attachments/assets/bb6950a1-4362-49cf-8844-df59de852227

Image

Image

---

```INFO bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "Windows 10 Pro", kernel: "19045", cpu: "Intel(R) Core(TM) i5-8400 CPU @ 2.80GHz", core_count: "6", memory: "31.8 GiB" }```

```INFO bevy_render::renderer: AdapterInfo { name: "NVIDIA GeForce GTX 1660 Ti", vendor: 4318, device: 8578, device_type: DiscreteGpu, driver: "32.0.15.8180", driver_info: "", backend: Dx12 }```

Contributor guide

Open the contributing guide

Research direction

Start by running the provided Bevy 0.18 example from main, focusing on spawn_layout and node, and resize the window through sizes that reproduce the misalignment. Inspect the UI grid/flex layout and pixel-snapping behavior, then verify that the flexbox child nodes remain aligned across the reported window sizes.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
game-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.