Skip to content

Commit 32766b3

Browse files
committed
Fix example and reuse uinodes vector
1 parent 36dfd25 commit 32766b3

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

crates/bevy_ui/src/stack.rs

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@ pub fn ui_stack_system(
4646
);
4747
}
4848

49-
*ui_stack = UiStack {
50-
uinodes: Vec::<Entity>::with_capacity(total_entry_count),
51-
};
52-
49+
ui_stack.uinodes.clear();
50+
ui_stack.uinodes.reserve(total_entry_count);
5351
fill_stack_recursively(&mut ui_stack.uinodes, &mut global_context);
5452
}
5553

@@ -141,46 +139,46 @@ mod tests {
141139

142140
let mut queue = CommandQueue::default();
143141
let mut commands = Commands::new(&mut queue, &world);
144-
commands.spawn_bundle(node_with_zindex("0", ZIndex::Global(2)));
142+
commands.spawn(node_with_zindex("0", ZIndex::Global(2)));
145143

146144
commands
147-
.spawn_bundle(node_with_zindex("1", ZIndex::Local(1)))
145+
.spawn(node_with_zindex("1", ZIndex::Local(1)))
148146
.with_children(|parent| {
149147
parent
150-
.spawn_bundle(node_without_zindex("1-0"))
148+
.spawn(node_without_zindex("1-0"))
151149
.with_children(|parent| {
152-
parent.spawn_bundle(node_without_zindex("1-0-0"));
153-
parent.spawn_bundle(node_without_zindex("1-0-1"));
154-
parent.spawn_bundle(node_with_zindex("1-0-2", ZIndex::Local(-1)));
150+
parent.spawn(node_without_zindex("1-0-0"));
151+
parent.spawn(node_without_zindex("1-0-1"));
152+
parent.spawn(node_with_zindex("1-0-2", ZIndex::Local(-1)));
155153
});
156-
parent.spawn_bundle(node_without_zindex("1-1"));
154+
parent.spawn(node_without_zindex("1-1"));
157155
parent
158-
.spawn_bundle(node_with_zindex("1-2", ZIndex::Global(-1)))
156+
.spawn(node_with_zindex("1-2", ZIndex::Global(-1)))
159157
.with_children(|parent| {
160-
parent.spawn_bundle(node_without_zindex("1-2-0"));
161-
parent.spawn_bundle(node_with_zindex("1-2-1", ZIndex::Global(-3)));
158+
parent.spawn(node_without_zindex("1-2-0"));
159+
parent.spawn(node_with_zindex("1-2-1", ZIndex::Global(-3)));
162160
parent
163-
.spawn_bundle(node_without_zindex("1-2-2"))
161+
.spawn(node_without_zindex("1-2-2"))
164162
.with_children(|_| ());
165-
parent.spawn_bundle(node_without_zindex("1-2-3"));
163+
parent.spawn(node_without_zindex("1-2-3"));
166164
});
167-
parent.spawn_bundle(node_without_zindex("1-3"));
165+
parent.spawn(node_without_zindex("1-3"));
168166
});
169167

170168
commands
171-
.spawn_bundle(node_without_zindex("2"))
169+
.spawn(node_without_zindex("2"))
172170
.with_children(|parent| {
173171
parent
174-
.spawn_bundle(node_without_zindex("2-0"))
172+
.spawn(node_without_zindex("2-0"))
175173
.with_children(|_parent| ());
176174
parent
177-
.spawn_bundle(node_without_zindex("2-1"))
175+
.spawn(node_without_zindex("2-1"))
178176
.with_children(|parent| {
179-
parent.spawn_bundle(node_without_zindex("2-1-0"));
177+
parent.spawn(node_without_zindex("2-1-0"));
180178
});
181179
});
182180

183-
commands.spawn_bundle(node_with_zindex("3", ZIndex::Global(-2)));
181+
commands.spawn(node_with_zindex("3", ZIndex::Global(-2)));
184182

185183
queue.apply(&mut world);
186184

0 commit comments

Comments
 (0)