Skip to content

Commit b825f63

Browse files
committed
Use UiChildren in bevy_ui::stack
1 parent 220bd4f commit b825f63

File tree

1 file changed

+16
-23
lines changed

1 file changed

+16
-23
lines changed

crates/bevy_ui/src/stack.rs

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
//! This module contains the systems that update the stored UI nodes stack
22
33
use bevy_ecs::prelude::*;
4-
use bevy_hierarchy::prelude::*;
54

6-
use crate::{Node, ZIndex};
5+
use crate::{Node, UiChildren, UiRootNodes, ZIndex};
76

87
/// The current UI stack, which contains all UI nodes ordered by their depth (back-to-front).
98
///
@@ -52,20 +51,20 @@ struct StackingContextEntry {
5251
pub(crate) fn ui_stack_system(
5352
mut cache: Local<StackingContextCache>,
5453
mut ui_stack: ResMut<UiStack>,
55-
root_node_query: Query<Entity, (With<Node>, Without<Parent>)>,
54+
root_nodes: UiRootNodes,
5655
zindex_query: Query<&ZIndex, With<Node>>,
57-
children_query: Query<&Children>,
56+
ui_children: UiChildren,
5857
mut update_query: Query<&mut Node>,
5958
) {
6059
// Generate `StackingContext` tree
6160
let mut global_context = cache.pop();
6261
let mut total_entry_count: usize = 0;
6362

64-
for entity in &root_node_query {
63+
for entity in root_nodes.iter() {
6564
insert_context_hierarchy(
6665
&mut cache,
6766
&zindex_query,
68-
&children_query,
67+
&ui_children,
6968
entity,
7069
&mut global_context,
7170
None,
@@ -90,30 +89,24 @@ pub(crate) fn ui_stack_system(
9089
fn insert_context_hierarchy(
9190
cache: &mut StackingContextCache,
9291
zindex_query: &Query<&ZIndex, With<Node>>,
93-
children_query: &Query<&Children>,
92+
ui_children: &UiChildren,
9493
entity: Entity,
9594
global_context: &mut StackingContext,
9695
parent_context: Option<&mut StackingContext>,
9796
total_entry_count: &mut usize,
9897
) {
9998
let mut new_context = cache.pop();
10099

101-
if let Ok(children) = children_query.get(entity) {
102-
// Reserve space for all children. In practice, some may not get pushed since
103-
// nodes with `ZIndex::Global` are pushed to the global (root) context.
104-
new_context.entries.reserve_exact(children.len());
105-
106-
for entity in children {
107-
insert_context_hierarchy(
108-
cache,
109-
zindex_query,
110-
children_query,
111-
*entity,
112-
global_context,
113-
Some(&mut new_context),
114-
total_entry_count,
115-
);
116-
}
100+
for entity in ui_children.iter_ui_children(entity) {
101+
insert_context_hierarchy(
102+
cache,
103+
zindex_query,
104+
ui_children,
105+
entity,
106+
global_context,
107+
Some(&mut new_context),
108+
total_entry_count,
109+
);
117110
}
118111

119112
// The node will be added either to global/parent based on its z-index type: global/local.

0 commit comments

Comments
 (0)