Skip to content

Commit 9ae7aa4

Browse files
authored
Update testbed_ui to use Improved Spawning API (#18329)
# Objective Contributes to #18238 Updates the `text2d`, example to use the `children!` macro. ~~The SpawnIter usage in this example is maybe not the best. Very open to opinions. I even left one `with_children` that I thought was just much better than any alternative.~~ ## Solution Updates examples to use the Improved Spawning API merged in #17521 ## Testing - Did you test these changes? If so, how? - Opened the examples before and after and verified the same behavior was observed. I did this on Ubuntu 24.04.2 LTS using `--features wayland`. - Are there any parts that need more testing? - Other OS's and features can't hurt, but this is such a small change it shouldn't be a problem. - How can other people (reviewers) test your changes? Is there anything specific they need to know? - Run the examples yourself with and without these changes. - If relevant, what platforms did you test these changes on, and are there any important ones you can't test? - see above --- ## Showcase n/a ## Migration Guide n/a
1 parent 116484b commit 9ae7aa4

File tree

1 file changed

+41
-45
lines changed

1 file changed

+41
-45
lines changed

examples/testbed/ui.rs

Lines changed: 41 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -105,61 +105,57 @@ mod grid {
105105
pub fn setup(mut commands: Commands) {
106106
commands.spawn((Camera2d, StateScoped(super::Scene::Grid)));
107107
// Top-level grid (app frame)
108-
commands
109-
.spawn((
110-
Node {
111-
display: Display::Grid,
112-
width: Val::Percent(100.0),
113-
height: Val::Percent(100.0),
114-
grid_template_columns: vec![GridTrack::min_content(), GridTrack::flex(1.0)],
115-
grid_template_rows: vec![
116-
GridTrack::auto(),
117-
GridTrack::flex(1.0),
118-
GridTrack::px(40.),
119-
],
120-
..default()
121-
},
122-
BackgroundColor(Color::WHITE),
123-
StateScoped(super::Scene::Grid),
124-
))
125-
.with_children(|builder| {
108+
commands.spawn((
109+
Node {
110+
display: Display::Grid,
111+
width: Val::Percent(100.0),
112+
height: Val::Percent(100.0),
113+
grid_template_columns: vec![GridTrack::min_content(), GridTrack::flex(1.0)],
114+
grid_template_rows: vec![
115+
GridTrack::auto(),
116+
GridTrack::flex(1.0),
117+
GridTrack::px(40.),
118+
],
119+
..default()
120+
},
121+
BackgroundColor(Color::WHITE),
122+
StateScoped(super::Scene::Grid),
123+
children![
126124
// Header
127-
builder.spawn((
125+
(
128126
Node {
129127
display: Display::Grid,
130128
grid_column: GridPlacement::span(2),
131129
padding: UiRect::all(Val::Px(40.0)),
132130
..default()
133131
},
134132
BackgroundColor(RED.into()),
135-
));
136-
133+
),
137134
// Main content grid (auto placed in row 2, column 1)
138-
builder
139-
.spawn((
140-
Node {
141-
height: Val::Percent(100.0),
142-
aspect_ratio: Some(1.0),
143-
display: Display::Grid,
144-
grid_template_columns: RepeatedGridTrack::flex(3, 1.0),
145-
grid_template_rows: RepeatedGridTrack::flex(2, 1.0),
146-
row_gap: Val::Px(12.0),
147-
column_gap: Val::Px(12.0),
148-
..default()
149-
},
150-
BackgroundColor(Color::srgb(0.25, 0.25, 0.25)),
151-
))
152-
.with_children(|builder| {
153-
builder.spawn((Node::default(), BackgroundColor(ORANGE.into())));
154-
builder.spawn((Node::default(), BackgroundColor(BISQUE.into())));
155-
builder.spawn((Node::default(), BackgroundColor(BLUE.into())));
156-
builder.spawn((Node::default(), BackgroundColor(CRIMSON.into())));
157-
builder.spawn((Node::default(), BackgroundColor(AQUA.into())));
158-
});
159-
135+
(
136+
Node {
137+
height: Val::Percent(100.0),
138+
aspect_ratio: Some(1.0),
139+
display: Display::Grid,
140+
grid_template_columns: RepeatedGridTrack::flex(3, 1.0),
141+
grid_template_rows: RepeatedGridTrack::flex(2, 1.0),
142+
row_gap: Val::Px(12.0),
143+
column_gap: Val::Px(12.0),
144+
..default()
145+
},
146+
BackgroundColor(Color::srgb(0.25, 0.25, 0.25)),
147+
children![
148+
(Node::default(), BackgroundColor(ORANGE.into())),
149+
(Node::default(), BackgroundColor(BISQUE.into())),
150+
(Node::default(), BackgroundColor(BLUE.into())),
151+
(Node::default(), BackgroundColor(CRIMSON.into())),
152+
(Node::default(), BackgroundColor(AQUA.into())),
153+
]
154+
),
160155
// Right side bar (auto placed in row 2, column 2)
161-
builder.spawn((Node::DEFAULT, BackgroundColor(BLACK.into())));
162-
});
156+
(Node::DEFAULT, BackgroundColor(BLACK.into())),
157+
],
158+
));
163159
}
164160
}
165161

0 commit comments

Comments
 (0)