1
1
mod convert;
2
2
3
- use crate :: { CalculatedSize , ControlNode , Node , Style } ;
3
+ use crate :: { CalculatedSize , Node , Style } ;
4
4
use bevy_app:: EventReader ;
5
5
use bevy_ecs:: {
6
6
entity:: Entity ,
@@ -111,62 +111,19 @@ impl FlexSurface {
111
111
}
112
112
}
113
113
114
- pub fn update_children (
115
- & mut self ,
116
- entity : Entity ,
117
- children : & Children ,
118
- control_node_query : & mut Query < & mut ControlNode > ,
119
- unfiltered_children_query : & Query < & Children > ,
120
- ) {
114
+ pub fn update_children ( & mut self , entity : Entity , children : & Children ) {
121
115
let mut stretch_children = Vec :: with_capacity ( children. len ( ) ) ;
122
- fn inner (
123
- true_parent : Entity ,
124
- child : Entity ,
125
- control_node_query : & mut Query < & mut ControlNode > ,
126
- unfiltered_children_query : & Query < & Children > ,
127
- do_on_real : & mut impl FnMut ( Entity ) ,
128
- ) {
129
- if let Ok ( mut control_node) = control_node_query. get_mut ( child) {
130
- control_node. true_parent = Some ( true_parent) ;
131
- for & child in unfiltered_children_query
132
- . get ( child)
133
- . ok ( )
134
- . into_iter ( )
135
- . map ( |c| & * * c)
136
- . flatten ( )
137
- {
138
- inner (
139
- true_parent,
140
- child,
141
- control_node_query,
142
- unfiltered_children_query,
143
- do_on_real,
144
- ) ;
145
- }
116
+ for child in children. iter ( ) {
117
+ if let Some ( stretch_node) = self . entity_to_stretch . get ( child) {
118
+ stretch_children. push ( * stretch_node) ;
146
119
} else {
147
- do_on_real ( child) ;
120
+ warn ! (
121
+ "Unstyled child in a UI entity hierarchy. You are using an entity \
122
+ without UI components as a child of an entity with UI components, results may be unexpected."
123
+ ) ;
148
124
}
149
125
}
150
126
151
- for & child in children. iter ( ) {
152
- inner (
153
- entity,
154
- child,
155
- control_node_query,
156
- unfiltered_children_query,
157
- & mut |e| {
158
- if let Some ( stretch_node) = self . entity_to_stretch . get ( & e) {
159
- stretch_children. push ( * stretch_node) ;
160
- } else {
161
- warn ! (
162
- "Unstyled child in a UI entity hierarchy. You are using an entity \
163
- without UI components as a child of an entity with UI components, results may be unexpected."
164
- ) ;
165
- }
166
- } ,
167
- ) ;
168
- }
169
-
170
127
let stretch_node = self . entity_to_stretch . get ( & entity) . unwrap ( ) ;
171
128
self . stretch
172
129
. set_children ( * stretch_node, stretch_children)
@@ -250,10 +207,7 @@ pub fn flex_node_system(
250
207
( Entity , & Style , & CalculatedSize ) ,
251
208
( With < Node > , Changed < CalculatedSize > ) ,
252
209
> ,
253
- changed_children_query : Query < ( Entity , & Children ) , ( With < Node > , Changed < Children > ) > ,
254
- unfiltered_children_query : Query < & Children > ,
255
- mut control_node_query : Query < & mut ControlNode > ,
256
- changed_cnc_query : Query < Entity , ( Changed < Children > , With < ControlNode > ) > ,
210
+ children_query : Query < ( Entity , & Children ) , ( With < Node > , Changed < Children > ) > ,
257
211
mut node_transform_query : Query < ( Entity , & mut Node , & mut Transform , Option < & Parent > ) > ,
258
212
) {
259
213
// update window root nodes
@@ -308,28 +262,8 @@ pub fn flex_node_system(
308
262
}
309
263
310
264
// update children
311
- for ( entity, children) in changed_children_query. iter ( ) {
312
- flex_surface. update_children (
313
- entity,
314
- children,
315
- & mut control_node_query,
316
- & unfiltered_children_query,
317
- ) ;
318
- }
319
-
320
- for entity in changed_cnc_query. iter ( ) {
321
- let true_parent = if let Some ( e) = control_node_query. get_mut ( entity) . unwrap ( ) . true_parent {
322
- e
323
- } else {
324
- continue ;
325
- } ;
326
- let children = unfiltered_children_query. get ( true_parent) . unwrap ( ) ;
327
- flex_surface. update_children (
328
- true_parent,
329
- children,
330
- & mut control_node_query,
331
- & unfiltered_children_query,
332
- ) ;
265
+ for ( entity, children) in children_query. iter ( ) {
266
+ flex_surface. update_children ( entity, children) ;
333
267
}
334
268
335
269
// compute layouts
@@ -350,11 +284,7 @@ pub fn flex_node_system(
350
284
position. x = to_logical ( layout. location . x + layout. size . width / 2.0 ) ;
351
285
position. y = to_logical ( layout. location . y + layout. size . height / 2.0 ) ;
352
286
if let Some ( parent) = parent {
353
- let parent = control_node_query
354
- . get_mut ( parent. 0 )
355
- . map ( |cn| cn. true_parent . unwrap ( ) )
356
- . unwrap_or ( parent. 0 ) ;
357
- if let Ok ( parent_layout) = flex_surface. get_layout ( parent) {
287
+ if let Ok ( parent_layout) = flex_surface. get_layout ( parent. 0 ) {
358
288
position. x -= to_logical ( parent_layout. size . width / 2.0 ) ;
359
289
position. y -= to_logical ( parent_layout. size . height / 2.0 ) ;
360
290
}
0 commit comments