1
1
//! This module contains systems that update the UI when something changes
2
2
3
- use crate :: { CalculatedClip , Display , OverflowAxis , Style , TargetCamera , UiRootNodes } ;
3
+ use crate :: { CalculatedClip , Display , OverflowAxis , Style , TargetCamera , UiChildren , UiRootNodes } ;
4
4
5
5
use super :: Node ;
6
6
use bevy_ecs:: {
7
7
entity:: Entity ,
8
- query:: { Changed , With , Without } ,
8
+ query:: { Changed , With } ,
9
9
system:: { Commands , Query } ,
10
10
} ;
11
- use bevy_hierarchy:: { Children , Parent } ;
12
11
use bevy_math:: Rect ;
13
12
use bevy_transform:: components:: GlobalTransform ;
14
13
use bevy_utils:: HashSet ;
@@ -18,12 +17,12 @@ pub fn update_clipping_system(
18
17
mut commands : Commands ,
19
18
root_nodes : UiRootNodes ,
20
19
mut node_query : Query < ( & Node , & GlobalTransform , & Style , Option < & mut CalculatedClip > ) > ,
21
- children_query : Query < & Children > ,
20
+ ui_children : UiChildren ,
22
21
) {
23
22
for root_node in root_nodes. iter ( ) {
24
23
update_clipping (
25
24
& mut commands,
26
- & children_query ,
25
+ & ui_children ,
27
26
& mut node_query,
28
27
root_node,
29
28
None ,
@@ -33,7 +32,7 @@ pub fn update_clipping_system(
33
32
34
33
fn update_clipping (
35
34
commands : & mut Commands ,
36
- children_query : & Query < & Children > ,
35
+ ui_children : & UiChildren ,
37
36
node_query : & mut Query < ( & Node , & GlobalTransform , & Style , Option < & mut CalculatedClip > ) > ,
38
37
entity : Entity ,
39
38
mut maybe_inherited_clip : Option < Rect > ,
@@ -92,35 +91,33 @@ fn update_clipping(
92
91
Some ( maybe_inherited_clip. map_or ( node_rect, |c| c. intersect ( node_rect) ) )
93
92
} ;
94
93
95
- if let Ok ( children) = children_query. get ( entity) {
96
- for & child in children {
97
- update_clipping ( commands, children_query, node_query, child, children_clip) ;
98
- }
94
+ for child in ui_children. iter_ui_children ( entity) {
95
+ update_clipping ( commands, ui_children, node_query, child, children_clip) ;
99
96
}
100
97
}
101
98
102
99
pub fn update_target_camera_system (
103
100
mut commands : Commands ,
104
101
changed_root_nodes_query : Query <
105
102
( Entity , Option < & TargetCamera > ) ,
106
- ( With < Node > , Without < Parent > , Changed < TargetCamera > ) ,
103
+ ( With < Node > , Changed < TargetCamera > ) ,
107
104
> ,
108
- changed_children_query : Query < ( Entity , Option < & TargetCamera > ) , ( With < Node > , Changed < Children > ) > ,
109
- children_query : Query < & Children , With < Node > > ,
110
- node_query : Query < Option < & TargetCamera > , With < Node > > ,
105
+ node_query : Query < ( Entity , Option < & TargetCamera > ) , With < Node > > ,
106
+ ui_root_nodes : UiRootNodes ,
107
+ ui_children : UiChildren ,
111
108
) {
112
109
// Track updated entities to prevent redundant updates, as `Commands` changes are deferred,
113
110
// and updates done for changed_children_query can overlap with itself or with root_node_query
114
111
let mut updated_entities = HashSet :: new ( ) ;
115
112
116
113
// Assuming that TargetCamera is manually set on the root node only,
117
114
// update root nodes first, since it implies the biggest change
118
- for ( root_node, target_camera) in & changed_root_nodes_query {
115
+ for ( root_node, target_camera) in changed_root_nodes_query. iter_many ( ui_root_nodes . iter ( ) ) {
119
116
update_children_target_camera (
120
117
root_node,
121
118
target_camera,
122
119
& node_query,
123
- & children_query ,
120
+ & ui_children ,
124
121
& mut commands,
125
122
& mut updated_entities,
126
123
) ;
@@ -129,12 +126,16 @@ pub fn update_target_camera_system(
129
126
// If the root node TargetCamera was changed, then every child is updated
130
127
// by this point, and iteration will be skipped.
131
128
// Otherwise, update changed children
132
- for ( parent, target_camera) in & changed_children_query {
129
+ for ( parent, target_camera) in & node_query {
130
+ if !ui_children. is_changed ( parent) {
131
+ continue ;
132
+ }
133
+
133
134
update_children_target_camera (
134
135
parent,
135
136
target_camera,
136
137
& node_query,
137
- & children_query ,
138
+ & ui_children ,
138
139
& mut commands,
139
140
& mut updated_entities,
140
141
) ;
@@ -144,19 +145,15 @@ pub fn update_target_camera_system(
144
145
fn update_children_target_camera (
145
146
entity : Entity ,
146
147
camera_to_set : Option < & TargetCamera > ,
147
- node_query : & Query < Option < & TargetCamera > , With < Node > > ,
148
- children_query : & Query < & Children , With < Node > > ,
148
+ node_query : & Query < ( Entity , Option < & TargetCamera > ) , With < Node > > ,
149
+ ui_children : & UiChildren ,
149
150
commands : & mut Commands ,
150
151
updated_entities : & mut HashSet < Entity > ,
151
152
) {
152
- let Ok ( children) = children_query. get ( entity) else {
153
- return ;
154
- } ;
155
-
156
- for & child in children {
153
+ for child in ui_children. iter_ui_children ( entity) {
157
154
// Skip if the child has already been updated or update is not needed
158
155
if updated_entities. contains ( & child)
159
- || camera_to_set == node_query. get ( child) . ok ( ) . flatten ( )
156
+ || camera_to_set == node_query. get ( child) . ok ( ) . and_then ( | ( _ , camera ) | camera )
160
157
{
161
158
continue ;
162
159
}
@@ -175,7 +172,7 @@ fn update_children_target_camera(
175
172
child,
176
173
camera_to_set,
177
174
node_query,
178
- children_query ,
175
+ ui_children ,
179
176
commands,
180
177
updated_entities,
181
178
) ;
0 commit comments