Skip to content

Update testbed_ui to use Improved Spawning API #18329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 41 additions & 45 deletions examples/testbed/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,61 +105,57 @@ mod grid {
pub fn setup(mut commands: Commands) {
commands.spawn((Camera2d, StateScoped(super::Scene::Grid)));
// Top-level grid (app frame)
commands
.spawn((
Node {
display: Display::Grid,
width: Val::Percent(100.0),
height: Val::Percent(100.0),
grid_template_columns: vec![GridTrack::min_content(), GridTrack::flex(1.0)],
grid_template_rows: vec![
GridTrack::auto(),
GridTrack::flex(1.0),
GridTrack::px(40.),
],
..default()
},
BackgroundColor(Color::WHITE),
StateScoped(super::Scene::Grid),
))
.with_children(|builder| {
commands.spawn((
Node {
display: Display::Grid,
width: Val::Percent(100.0),
height: Val::Percent(100.0),
grid_template_columns: vec![GridTrack::min_content(), GridTrack::flex(1.0)],
grid_template_rows: vec![
GridTrack::auto(),
GridTrack::flex(1.0),
GridTrack::px(40.),
],
..default()
},
BackgroundColor(Color::WHITE),
StateScoped(super::Scene::Grid),
children![
// Header
builder.spawn((
(
Node {
display: Display::Grid,
grid_column: GridPlacement::span(2),
padding: UiRect::all(Val::Px(40.0)),
..default()
},
BackgroundColor(RED.into()),
));

),
// Main content grid (auto placed in row 2, column 1)
builder
.spawn((
Node {
height: Val::Percent(100.0),
aspect_ratio: Some(1.0),
display: Display::Grid,
grid_template_columns: RepeatedGridTrack::flex(3, 1.0),
grid_template_rows: RepeatedGridTrack::flex(2, 1.0),
row_gap: Val::Px(12.0),
column_gap: Val::Px(12.0),
..default()
},
BackgroundColor(Color::srgb(0.25, 0.25, 0.25)),
))
.with_children(|builder| {
builder.spawn((Node::default(), BackgroundColor(ORANGE.into())));
builder.spawn((Node::default(), BackgroundColor(BISQUE.into())));
builder.spawn((Node::default(), BackgroundColor(BLUE.into())));
builder.spawn((Node::default(), BackgroundColor(CRIMSON.into())));
builder.spawn((Node::default(), BackgroundColor(AQUA.into())));
});

(
Node {
height: Val::Percent(100.0),
aspect_ratio: Some(1.0),
display: Display::Grid,
grid_template_columns: RepeatedGridTrack::flex(3, 1.0),
grid_template_rows: RepeatedGridTrack::flex(2, 1.0),
row_gap: Val::Px(12.0),
column_gap: Val::Px(12.0),
..default()
},
BackgroundColor(Color::srgb(0.25, 0.25, 0.25)),
children![
(Node::default(), BackgroundColor(ORANGE.into())),
(Node::default(), BackgroundColor(BISQUE.into())),
(Node::default(), BackgroundColor(BLUE.into())),
(Node::default(), BackgroundColor(CRIMSON.into())),
(Node::default(), BackgroundColor(AQUA.into())),
]
),
// Right side bar (auto placed in row 2, column 2)
builder.spawn((Node::DEFAULT, BackgroundColor(BLACK.into())));
});
(Node::DEFAULT, BackgroundColor(BLACK.into())),
],
));
}
}

Expand Down