@@ -23,7 +23,7 @@ use bevy_render::{
23
23
view:: { ComputedVisibility , ExtractedView , ViewUniforms } ,
24
24
Extract , RenderApp , RenderStage ,
25
25
} ;
26
- use bevy_sprite:: { Rect , SpriteAssetEvents , TextureAtlas } ;
26
+ use bevy_sprite:: { Rect , SpriteAssetEvents , TextureAtlas , TextureSheet } ;
27
27
use bevy_text:: { DefaultTextPipeline , Text } ;
28
28
use bevy_transform:: components:: GlobalTransform ;
29
29
use bevy_utils:: FloatOrd ;
@@ -176,20 +176,23 @@ pub struct ExtractedUiNodes {
176
176
pub fn extract_uinodes (
177
177
mut extracted_uinodes : ResMut < ExtractedUiNodes > ,
178
178
images : Extract < Res < Assets < Image > > > ,
179
+ texture_atlases : Extract < Res < Assets < TextureAtlas > > > ,
179
180
uinode_query : Extract <
180
181
Query < (
181
182
& Node ,
182
183
& GlobalTransform ,
183
184
& UiColor ,
184
185
& UiImage ,
185
186
& ComputedVisibility ,
187
+ Option < & TextureSheet > ,
186
188
Option < & CalculatedClip > ,
187
189
) > ,
188
190
> ,
189
191
) {
190
192
extracted_uinodes. uinodes . clear ( ) ;
191
- for ( uinode, transform, color, image, visibility, clip) in uinode_query. iter ( ) {
192
- if !visibility. is_visible ( ) {
193
+ for ( uinode, transform, color, image, visibility, sheet, clip) in uinode_query. iter ( ) {
194
+ // Skip if the node is invisible or if its size is set to zero (e.g. when a parent is set to `Display::None`)
195
+ if !visibility. is_visible ( ) || uinode. size == Vec2 :: ZERO {
193
196
continue ;
194
197
}
195
198
let image = image. 0 . clone_weak ( ) ;
@@ -201,15 +204,29 @@ pub fn extract_uinodes(
201
204
if color. 0 . a ( ) == 0.0 {
202
205
continue ;
203
206
}
207
+ let ( atlas_size, rect_min) = sheet
208
+ . and_then ( |s| {
209
+ texture_atlases
210
+ . get ( & s. texture_atlas )
211
+ . map ( |a| ( a, s. texture_index ) )
212
+ } )
213
+ . and_then ( |( atlas, index) | {
214
+ atlas
215
+ . textures
216
+ . get ( index)
217
+ . map ( |rect| ( Some ( atlas. size ) , rect. min ) )
218
+ } )
219
+ . unwrap_or ( ( None , Vec2 :: ZERO ) ) ;
220
+
204
221
extracted_uinodes. uinodes . push ( ExtractedUiNode {
205
222
transform : transform. compute_matrix ( ) ,
206
223
color : color. 0 ,
207
224
rect : bevy_sprite:: Rect {
208
- min : Vec2 :: ZERO ,
209
- max : uinode. size ,
225
+ min : rect_min ,
226
+ max : rect_min + uinode. size ,
210
227
} ,
211
228
image,
212
- atlas_size : None ,
229
+ atlas_size,
213
230
clip : clip. map ( |clip| clip. clip ) ,
214
231
} ) ;
215
232
}
0 commit comments