Skip to content

Commit a33161c

Browse files
authored
Update render_primitives example for children! macro (#18268)
# Objective Contributes to #18238 Updates the `render_primitives` example to use the `children!` macro. ## 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 e21dfe8 commit a33161c

File tree

1 file changed

+23
-31
lines changed

1 file changed

+23
-31
lines changed

examples/math/render_primitives.rs

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -368,39 +368,31 @@ fn setup_text(mut commands: Commands, cameras: Query<(Entity, &Camera)>) {
368368
.iter()
369369
.find_map(|(entity, camera)| camera.is_active.then_some(entity))
370370
.expect("run condition ensures existence");
371-
commands
372-
.spawn((
373-
HeaderNode,
374-
Node {
375-
justify_self: JustifySelf::Center,
376-
top: Val::Px(5.0),
377-
..Default::default()
378-
},
379-
UiTargetCamera(active_camera),
380-
))
381-
.with_children(|p| {
382-
p.spawn((
383-
Text::default(),
384-
HeaderText,
385-
TextLayout::new_with_justify(JustifyText::Center),
386-
))
387-
.with_children(|p| {
388-
p.spawn(TextSpan::new("Primitive: "));
389-
p.spawn(TextSpan(format!(
390-
"{text}",
391-
text = PrimitiveSelected::default()
392-
)));
393-
p.spawn(TextSpan::new("\n\n"));
394-
p.spawn(TextSpan::new(
371+
commands.spawn((
372+
HeaderNode,
373+
Node {
374+
justify_self: JustifySelf::Center,
375+
top: Val::Px(5.0),
376+
..Default::default()
377+
},
378+
UiTargetCamera(active_camera),
379+
children![(
380+
Text::default(),
381+
HeaderText,
382+
TextLayout::new_with_justify(JustifyText::Center),
383+
children![
384+
TextSpan::new("Primitive: "),
385+
TextSpan(format!("{text}", text = PrimitiveSelected::default())),
386+
TextSpan::new("\n\n"),
387+
TextSpan::new(
395388
"Press 'C' to switch between 2D and 3D mode\n\
396389
Press 'Up' or 'Down' to switch to the next/previous primitive",
397-
));
398-
p.spawn(TextSpan::new("\n\n"));
399-
p.spawn(TextSpan::new(
400-
"(If nothing is displayed, there's no rendering support yet)",
401-
));
402-
});
403-
});
390+
),
391+
TextSpan::new("\n\n"),
392+
TextSpan::new("(If nothing is displayed, there's no rendering support yet)",),
393+
]
394+
)],
395+
));
404396
}
405397

406398
fn update_text(

0 commit comments

Comments
 (0)