From 25103df30133f30076f9ef1852e4873ad4c6448f Mon Sep 17 00:00:00 2001 From: krunchington Date: Wed, 12 Mar 2025 16:52:39 -0700 Subject: [PATCH] Update gamepad_viewer to use children macro (#18282) # Objective Contributes to #18238 Updates the `gamepad_viewer`, 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 --- examples/tools/gamepad_viewer.rs | 213 ++++++++++++++----------------- 1 file changed, 98 insertions(+), 115 deletions(-) diff --git a/examples/tools/gamepad_viewer.rs b/examples/tools/gamepad_viewer.rs index 32549893c6..c8092c2ebe 100644 --- a/examples/tools/gamepad_viewer.rs +++ b/examples/tools/gamepad_viewer.rs @@ -132,41 +132,40 @@ fn setup(mut commands: Commands, meshes: Res, materials: Res, materials: Res, ) { let mut spawn_trigger = |x, y, button_type| { - commands - .spawn(GamepadButtonBundle::new( + commands.spawn(( + GamepadButtonBundle::new( button_type, meshes.trigger.clone(), materials.normal.clone(), x, y, - )) - .with_children(|parent| { - parent.spawn(( - Transform::from_xyz(0., 0., 1.), - Text(format!("{:.3}", 0.)), - TextFont { - font_size: 13., - ..default() - }, - TextWithButtonValue(button_type), - )); - }); + ), + children![( + Transform::from_xyz(0., 0., 1.), + Text(format!("{:.3}", 0.)), + TextFont { + font_size: 13., + ..default() + }, + TextWithButtonValue(button_type), + )], + )); }; spawn_trigger(-BUTTONS_X, BUTTONS_Y + 145., GamepadButton::LeftTrigger2); @@ -374,18 +358,17 @@ fn setup_triggers( fn setup_connected(mut commands: Commands) { // This is UI text, unlike other text in this example which is 2d. - commands - .spawn(( - Text::new("Connected Gamepads:\n"), - Node { - position_type: PositionType::Absolute, - top: Val::Px(12.), - left: Val::Px(12.), - ..default() - }, - ConnectedGamepadsText, - )) - .with_child(TextSpan::new("None")); + commands.spawn(( + Text::new("Connected Gamepads:\n"), + Node { + position_type: PositionType::Absolute, + top: Val::Px(12.), + left: Val::Px(12.), + ..default() + }, + ConnectedGamepadsText, + children![TextSpan::new("None")], + )); } fn update_buttons(