Skip to content

Commit f68ed87

Browse files
authored
Update text_input and virtual_time examples to use Improved Spawning API (#18249)
# Objective Contributes to #18238 Updates the `text_input` and `virtual_time` examples to use the `children!` macro. I wanted to keep the PR small but chose to do two examples since they both included only a single `with_children` call. ## 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 76ab6a9 commit f68ed87

File tree

2 files changed

+31
-38
lines changed

2 files changed

+31
-38
lines changed

examples/input/text_input.rs

+19-22
Original file line numberDiff line numberDiff line change
@@ -34,33 +34,30 @@ fn setup_scene(mut commands: Commands, asset_server: Res<AssetServer>) {
3434
// sections that will hold text input.
3535
let font = asset_server.load("fonts/FiraMono-Medium.ttf");
3636

37-
commands
38-
.spawn((
39-
Text::default(),
40-
Node {
41-
position_type: PositionType::Absolute,
42-
top: Val::Px(12.0),
43-
left: Val::Px(12.0),
44-
..default()
45-
},
46-
))
47-
.with_children(|p| {
48-
p.spawn(TextSpan::new(
49-
"Click to toggle IME. Press return to start a new line.\n\n",
50-
));
51-
p.spawn(TextSpan::new("IME Enabled: "));
52-
p.spawn(TextSpan::new("false\n"));
53-
p.spawn(TextSpan::new("IME Active: "));
54-
p.spawn(TextSpan::new("false\n"));
55-
p.spawn(TextSpan::new("IME Buffer: "));
56-
p.spawn((
37+
commands.spawn((
38+
Text::default(),
39+
Node {
40+
position_type: PositionType::Absolute,
41+
top: Val::Px(12.0),
42+
left: Val::Px(12.0),
43+
..default()
44+
},
45+
children![
46+
TextSpan::new("Click to toggle IME. Press return to start a new line.\n\n",),
47+
TextSpan::new("IME Enabled: "),
48+
TextSpan::new("false\n"),
49+
TextSpan::new("IME Active: "),
50+
TextSpan::new("false\n"),
51+
TextSpan::new("IME Buffer: "),
52+
(
5753
TextSpan::new("\n"),
5854
TextFont {
5955
font: font.clone(),
6056
..default()
6157
},
62-
));
63-
});
58+
),
59+
],
60+
));
6461

6562
commands.spawn((
6663
Text2d::new(""),

examples/time/virtual_time.rs

+12-16
Original file line numberDiff line numberDiff line change
@@ -76,40 +76,35 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, mut time: ResMu
7676
// info UI
7777
let font_size = 33.;
7878

79-
commands
80-
.spawn(Node {
79+
commands.spawn((
80+
Node {
8181
display: Display::Flex,
8282
justify_content: JustifyContent::SpaceBetween,
8383
width: Val::Percent(100.),
8484
position_type: PositionType::Absolute,
8585
top: Val::Px(0.),
8686
padding: UiRect::all(Val::Px(20.0)),
8787
..default()
88-
})
89-
.with_children(|builder| {
90-
// real time info
91-
builder.spawn((
88+
},
89+
children![
90+
(
9291
Text::default(),
9392
TextFont {
9493
font_size,
9594
..default()
9695
},
9796
RealTime,
98-
));
99-
100-
// keybindings
101-
builder.spawn((
97+
),
98+
(
10299
Text::new("CONTROLS\nUn/Pause: Space\nSpeed+: Up\nSpeed-: Down"),
103100
TextFont {
104101
font_size,
105102
..default()
106103
},
107104
TextColor(Color::srgb(0.85, 0.85, 0.85)),
108105
TextLayout::new_with_justify(JustifyText::Center),
109-
));
110-
111-
// virtual time info
112-
builder.spawn((
106+
),
107+
(
113108
Text::default(),
114109
TextFont {
115110
font_size,
@@ -118,8 +113,9 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, mut time: ResMu
118113
TextColor(virtual_color),
119114
TextLayout::new_with_justify(JustifyText::Right),
120115
VirtualTime,
121-
));
122-
});
116+
),
117+
],
118+
));
123119
}
124120

125121
/// Move sprites using `Real` (unscaled) time

0 commit comments

Comments
 (0)