|
| 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