1
1
//! This module contains the systems that update the stored UI nodes stack
2
2
3
3
use bevy_ecs:: prelude:: * ;
4
- use bevy_hierarchy:: prelude:: * ;
5
4
6
- use crate :: { Node , ZIndex } ;
5
+ use crate :: { Node , UiChildren , UiRootNodes , ZIndex } ;
7
6
8
7
/// The current UI stack, which contains all UI nodes ordered by their depth (back-to-front).
9
8
///
@@ -52,20 +51,20 @@ struct StackingContextEntry {
52
51
pub ( crate ) fn ui_stack_system (
53
52
mut cache : Local < StackingContextCache > ,
54
53
mut ui_stack : ResMut < UiStack > ,
55
- root_node_query : Query < Entity , ( With < Node > , Without < Parent > ) > ,
54
+ root_nodes : UiRootNodes ,
56
55
zindex_query : Query < & ZIndex , With < Node > > ,
57
- children_query : Query < & Children > ,
56
+ ui_children : UiChildren ,
58
57
mut update_query : Query < & mut Node > ,
59
58
) {
60
59
// Generate `StackingContext` tree
61
60
let mut global_context = cache. pop ( ) ;
62
61
let mut total_entry_count: usize = 0 ;
63
62
64
- for entity in & root_node_query {
63
+ for entity in root_nodes . iter ( ) {
65
64
insert_context_hierarchy (
66
65
& mut cache,
67
66
& zindex_query,
68
- & children_query ,
67
+ & ui_children ,
69
68
entity,
70
69
& mut global_context,
71
70
None ,
@@ -90,30 +89,24 @@ pub(crate) fn ui_stack_system(
90
89
fn insert_context_hierarchy (
91
90
cache : & mut StackingContextCache ,
92
91
zindex_query : & Query < & ZIndex , With < Node > > ,
93
- children_query : & Query < & Children > ,
92
+ ui_children : & UiChildren ,
94
93
entity : Entity ,
95
94
global_context : & mut StackingContext ,
96
95
parent_context : Option < & mut StackingContext > ,
97
96
total_entry_count : & mut usize ,
98
97
) {
99
98
let mut new_context = cache. pop ( ) ;
100
99
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
+ ) ;
117
110
}
118
111
119
112
// The node will be added either to global/parent based on its z-index type: global/local.
0 commit comments