Skip to content

Commit 3d72f49

Browse files
authored
Layout rounding debug example (bevyengine#16096)
# Objective Simple example for debugging layout rounding errors. <img width="1039" height="752" alt="layout_rounding_debug" src="https://github.com/user-attachments/assets/12673000-e267-467e-b25b-3f8001c1347c"> Any white lines are gaps in the layout caused by coordinate rounding errors.
1 parent 86ee8e4 commit 3d72f49

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3856,3 +3856,12 @@ doc-scrape-examples = true
38563856

38573857
[package.metadata.example.testbed_3d]
38583858
hidden = true
3859+
3860+
3861+
[[example]]
3862+
name = "testbed_ui_layout_rounding"
3863+
path = "examples/testbed/ui_layout_rounding.rs"
3864+
doc-scrape-examples = true
3865+
3866+
[package.metadata.example.testbed_ui_layout_rounding]
3867+
hidden = true
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//! Spawns a simple grid layout with nodes laid out covering a white background useful for catching layout rounding errors.
2+
//! Any white lines seen are gaps in the layout are caused by coordinate rounding bugs.
3+
4+
use bevy::{
5+
color::palettes::css::{DARK_BLUE, MAROON},
6+
prelude::*,
7+
ui::UiScale,
8+
winit::WinitSettings,
9+
};
10+
11+
fn main() {
12+
App::new()
13+
.add_plugins(DefaultPlugins)
14+
.insert_resource(WinitSettings::desktop_app())
15+
.insert_resource(UiScale(1.5))
16+
.add_systems(Startup, setup)
17+
.run();
18+
}
19+
20+
fn setup(mut commands: Commands) {
21+
commands.spawn((Camera2d, UiAntiAlias::Off));
22+
23+
commands
24+
.spawn((
25+
Node {
26+
display: Display::Grid,
27+
width: Val::Percent(100.),
28+
height: Val::Percent(100.),
29+
grid_template_rows: vec![RepeatedGridTrack::fr(10, 1.)],
30+
..Default::default()
31+
},
32+
BackgroundColor(Color::WHITE),
33+
))
34+
.with_children(|commands| {
35+
for i in 2..12 {
36+
commands
37+
.spawn(Node {
38+
display: Display::Grid,
39+
grid_template_columns: vec![RepeatedGridTrack::fr(i, 1.)],
40+
..Default::default()
41+
})
42+
.with_children(|commands| {
43+
for _ in 0..i {
44+
commands.spawn((
45+
Node {
46+
border: UiRect::all(Val::Px(5.)),
47+
..Default::default()
48+
},
49+
BackgroundColor(MAROON.into()),
50+
BorderColor(DARK_BLUE.into()),
51+
));
52+
}
53+
});
54+
}
55+
});
56+
}

0 commit comments

Comments
 (0)