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
https://github.com/bevyengine/bevy/pull/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
This commit is contained in:
krunchington 2025-03-11 21:49:07 -07:00 committed by GitHub
parent e21dfe81ce
commit a33161cf5b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -368,8 +368,7 @@ fn setup_text(mut commands: Commands, cameras: Query<(Entity, &Camera)>) {
.iter() .iter()
.find_map(|(entity, camera)| camera.is_active.then_some(entity)) .find_map(|(entity, camera)| camera.is_active.then_some(entity))
.expect("run condition ensures existence"); .expect("run condition ensures existence");
commands commands.spawn((
.spawn((
HeaderNode, HeaderNode,
Node { Node {
justify_self: JustifySelf::Center, justify_self: JustifySelf::Center,
@ -377,30 +376,23 @@ fn setup_text(mut commands: Commands, cameras: Query<(Entity, &Camera)>) {
..Default::default() ..Default::default()
}, },
UiTargetCamera(active_camera), UiTargetCamera(active_camera),
)) children![(
.with_children(|p| {
p.spawn((
Text::default(), Text::default(),
HeaderText, HeaderText,
TextLayout::new_with_justify(JustifyText::Center), TextLayout::new_with_justify(JustifyText::Center),
)) children![
.with_children(|p| { TextSpan::new("Primitive: "),
p.spawn(TextSpan::new("Primitive: ")); TextSpan(format!("{text}", text = PrimitiveSelected::default())),
p.spawn(TextSpan(format!( TextSpan::new("\n\n"),
"{text}", TextSpan::new(
text = PrimitiveSelected::default()
)));
p.spawn(TextSpan::new("\n\n"));
p.spawn(TextSpan::new(
"Press 'C' to switch between 2D and 3D mode\n\ "Press 'C' to switch between 2D and 3D mode\n\
Press 'Up' or 'Down' to switch to the next/previous primitive", Press 'Up' or 'Down' to switch to the next/previous primitive",
),
TextSpan::new("\n\n"),
TextSpan::new("(If nothing is displayed, there's no rendering support yet)",),
]
)],
)); ));
p.spawn(TextSpan::new("\n\n"));
p.spawn(TextSpan::new(
"(If nothing is displayed, there's no rendering support yet)",
));
});
});
} }
fn update_text( fn update_text(