@@ -345,15 +345,14 @@ impl<'w, 's> UiCameraMapper<'w, 's> {
345
345
346
346
pub struct ExtractedUiNode {
347
347
pub z_order : f32 ,
348
- pub color : LinearRgba ,
349
- pub rect : Rect ,
350
348
pub image : AssetId < Image > ,
351
349
pub clip : Option < Rect > ,
352
350
/// Render world entity of the extracted camera corresponding to this node's target camera.
353
351
pub extracted_camera_entity : Entity ,
354
352
pub item : ExtractedUiItem ,
355
353
pub main_entity : MainEntity ,
356
354
pub render_entity : Entity ,
355
+ pub transform : Affine2 ,
357
356
}
358
357
359
358
/// The type of UI node.
@@ -366,6 +365,8 @@ pub enum NodeType {
366
365
367
366
pub enum ExtractedUiItem {
368
367
Node {
368
+ color : LinearRgba ,
369
+ rect : Rect ,
369
370
atlas_scaling : Option < Vec2 > ,
370
371
flip_x : bool ,
371
372
flip_y : bool ,
@@ -376,7 +377,6 @@ pub enum ExtractedUiItem {
376
377
/// Ordering: left, top, right, bottom.
377
378
border : BorderRect ,
378
379
node_type : NodeType ,
379
- transform : Affine2 ,
380
380
} ,
381
381
/// A contiguous sequence of text glyphs from the same section
382
382
Glyphs {
@@ -386,7 +386,8 @@ pub enum ExtractedUiItem {
386
386
}
387
387
388
388
pub struct ExtractedGlyph {
389
- pub transform : Affine2 ,
389
+ pub color : LinearRgba ,
390
+ pub translation : Vec2 ,
390
391
pub rect : Rect ,
391
392
}
392
393
@@ -464,17 +465,17 @@ pub fn extract_uinode_background_colors(
464
465
extracted_uinodes. uinodes . push ( ExtractedUiNode {
465
466
render_entity : commands. spawn ( TemporaryRenderEntity ) . id ( ) ,
466
467
z_order : uinode. stack_index as f32 + stack_z_offsets:: BACKGROUND_COLOR ,
467
- color : background_color. 0 . into ( ) ,
468
- rect : Rect {
469
- min : Vec2 :: ZERO ,
470
- max : uinode. size ,
471
- } ,
472
468
clip : clip. map ( |clip| clip. clip ) ,
473
469
image : AssetId :: default ( ) ,
474
470
extracted_camera_entity,
471
+ transform : transform. into ( ) ,
475
472
item : ExtractedUiItem :: Node {
473
+ color : background_color. 0 . into ( ) ,
474
+ rect : Rect {
475
+ min : Vec2 :: ZERO ,
476
+ max : uinode. size ,
477
+ } ,
476
478
atlas_scaling : None ,
477
- transform : transform. into ( ) ,
478
479
flip_x : false ,
479
480
flip_y : false ,
480
481
border : uinode. border ( ) ,
@@ -551,14 +552,14 @@ pub fn extract_uinode_images(
551
552
extracted_uinodes. uinodes . push ( ExtractedUiNode {
552
553
z_order : uinode. stack_index as f32 + stack_z_offsets:: IMAGE ,
553
554
render_entity : commands. spawn ( TemporaryRenderEntity ) . id ( ) ,
554
- color : image. color . into ( ) ,
555
- rect,
556
555
clip : clip. map ( |clip| clip. clip ) ,
557
556
image : image. image . id ( ) ,
558
557
extracted_camera_entity,
558
+ transform : transform. into ( ) ,
559
559
item : ExtractedUiItem :: Node {
560
+ color : image. color . into ( ) ,
561
+ rect,
560
562
atlas_scaling,
561
- transform : transform. into ( ) ,
562
563
flip_x : image. flip_x ,
563
564
flip_y : image. flip_y ,
564
565
border : uinode. border ,
@@ -649,17 +650,17 @@ pub fn extract_uinode_borders(
649
650
650
651
extracted_uinodes. uinodes . push ( ExtractedUiNode {
651
652
z_order : computed_node. stack_index as f32 + stack_z_offsets:: BORDER ,
652
- color,
653
- rect : Rect {
654
- max : computed_node. size ( ) ,
655
- ..Default :: default ( )
656
- } ,
657
653
image,
658
654
clip : maybe_clip. map ( |clip| clip. clip ) ,
659
655
extracted_camera_entity,
656
+ transform : transform. into ( ) ,
660
657
item : ExtractedUiItem :: Node {
658
+ color,
659
+ rect : Rect {
660
+ max : computed_node. size ( ) ,
661
+ ..Default :: default ( )
662
+ } ,
661
663
atlas_scaling : None ,
662
- transform : transform. into ( ) ,
663
664
flip_x : false ,
664
665
flip_y : false ,
665
666
border : computed_node. border ( ) ,
@@ -682,16 +683,16 @@ pub fn extract_uinode_borders(
682
683
extracted_uinodes. uinodes . push ( ExtractedUiNode {
683
684
z_order : computed_node. stack_index as f32 + stack_z_offsets:: BORDER ,
684
685
render_entity : commands. spawn ( TemporaryRenderEntity ) . id ( ) ,
685
- color : outline. color . into ( ) ,
686
- rect : Rect {
687
- max : outline_size,
688
- ..Default :: default ( )
689
- } ,
690
686
image,
691
687
clip : maybe_clip. map ( |clip| clip. clip ) ,
692
688
extracted_camera_entity,
689
+ transform : transform. into ( ) ,
693
690
item : ExtractedUiItem :: Node {
694
- transform : transform. into ( ) ,
691
+ color : outline. color . into ( ) ,
692
+ rect : Rect {
693
+ max : outline_size,
694
+ ..Default :: default ( )
695
+ } ,
695
696
atlas_scaling : None ,
696
697
flip_x : false ,
697
698
flip_y : false ,
@@ -873,17 +874,17 @@ pub fn extract_viewport_nodes(
873
874
extracted_uinodes. uinodes . push ( ExtractedUiNode {
874
875
z_order : uinode. stack_index as f32 + stack_z_offsets:: IMAGE ,
875
876
render_entity : commands. spawn ( TemporaryRenderEntity ) . id ( ) ,
876
- color : LinearRgba :: WHITE ,
877
- rect : Rect {
878
- min : Vec2 :: ZERO ,
879
- max : uinode. size ,
880
- } ,
881
877
clip : clip. map ( |clip| clip. clip ) ,
882
878
image : image. id ( ) ,
883
879
extracted_camera_entity,
880
+ transform : transform. into ( ) ,
884
881
item : ExtractedUiItem :: Node {
882
+ color : LinearRgba :: WHITE ,
883
+ rect : Rect {
884
+ min : Vec2 :: ZERO ,
885
+ max : uinode. size ,
886
+ } ,
885
887
atlas_scaling : None ,
886
- transform : transform. into ( ) ,
887
888
flip_x : false ,
888
889
flip_y : false ,
889
890
border : uinode. border ( ) ,
@@ -908,6 +909,7 @@ pub fn extract_text_sections(
908
909
Option < & CalculatedClip > ,
909
910
& ComputedUiTargetCamera ,
910
911
& ComputedTextBlock ,
912
+ & TextColor ,
911
913
& TextLayoutInfo ,
912
914
) > ,
913
915
> ,
@@ -926,6 +928,7 @@ pub fn extract_text_sections(
926
928
clip,
927
929
camera,
928
930
computed_block,
931
+ text_color,
929
932
text_layout_info,
930
933
) in & uinode_query
931
934
{
@@ -940,6 +943,8 @@ pub fn extract_text_sections(
940
943
941
944
let transform = Affine2 :: from ( * transform) * Affine2 :: from_translation ( -0.5 * uinode. size ( ) ) ;
942
945
946
+ let mut color = text_color. 0 . to_linear ( ) ;
947
+
943
948
for (
944
949
i,
945
950
PositionedGlyph {
@@ -956,14 +961,15 @@ pub fn extract_text_sections(
956
961
. textures [ atlas_info. location . glyph_index ]
957
962
. as_rect ( ) ;
958
963
extracted_uinodes. glyphs . push ( ExtractedGlyph {
959
- transform : transform * Affine2 :: from_translation ( * position) ,
964
+ color,
965
+ translation : * position,
960
966
rect,
961
967
} ) ;
962
968
963
969
if text_layout_info. glyphs . get ( i + 1 ) . is_none_or ( |info| {
964
970
info. span_index != * span_index || info. atlas_info . texture != atlas_info. texture
965
971
} ) {
966
- let color = text_styles
972
+ color = text_styles
967
973
. get (
968
974
computed_block
969
975
. entities ( )
@@ -976,13 +982,12 @@ pub fn extract_text_sections(
976
982
extracted_uinodes. uinodes . push ( ExtractedUiNode {
977
983
z_order : uinode. stack_index as f32 + stack_z_offsets:: TEXT ,
978
984
render_entity : commands. spawn ( TemporaryRenderEntity ) . id ( ) ,
979
- color,
980
985
image : atlas_info. texture ,
981
986
clip : clip. map ( |clip| clip. clip ) ,
982
987
extracted_camera_entity,
983
- rect,
984
988
item : ExtractedUiItem :: Glyphs { range : start..end } ,
985
989
main_entity : entity. into ( ) ,
990
+ transform,
986
991
} ) ;
987
992
start = end;
988
993
}
@@ -1047,21 +1052,21 @@ pub fn extract_text_shadows(
1047
1052
. textures [ atlas_info. location . glyph_index ]
1048
1053
. as_rect ( ) ;
1049
1054
extracted_uinodes. glyphs . push ( ExtractedGlyph {
1050
- transform : node_transform * Affine2 :: from_translation ( * position) ,
1055
+ color : shadow. color . into ( ) ,
1056
+ translation : * position,
1051
1057
rect,
1052
1058
} ) ;
1053
1059
1054
1060
if text_layout_info. glyphs . get ( i + 1 ) . is_none_or ( |info| {
1055
1061
info. span_index != * span_index || info. atlas_info . texture != atlas_info. texture
1056
1062
} ) {
1057
1063
extracted_uinodes. uinodes . push ( ExtractedUiNode {
1064
+ transform : node_transform,
1058
1065
z_order : uinode. stack_index as f32 + stack_z_offsets:: TEXT ,
1059
1066
render_entity : commands. spawn ( TemporaryRenderEntity ) . id ( ) ,
1060
- color : shadow. color . into ( ) ,
1061
1067
image : atlas_info. texture ,
1062
1068
clip : clip. map ( |clip| clip. clip ) ,
1063
1069
extracted_camera_entity,
1064
- rect,
1065
1070
item : ExtractedUiItem :: Glyphs { range : start..end } ,
1066
1071
main_entity : entity. into ( ) ,
1067
1072
} ) ;
@@ -1114,17 +1119,17 @@ pub fn extract_text_background_colors(
1114
1119
extracted_uinodes. uinodes . push ( ExtractedUiNode {
1115
1120
z_order : uinode. stack_index as f32 + stack_z_offsets:: TEXT ,
1116
1121
render_entity : commands. spawn ( TemporaryRenderEntity ) . id ( ) ,
1117
- color : text_background_color. 0 . to_linear ( ) ,
1118
- rect : Rect {
1119
- min : Vec2 :: ZERO ,
1120
- max : rect. size ( ) ,
1121
- } ,
1122
1122
clip : clip. map ( |clip| clip. clip ) ,
1123
1123
image : AssetId :: default ( ) ,
1124
1124
extracted_camera_entity,
1125
+ transform : transform * Affine2 :: from_translation ( rect. center ( ) ) ,
1125
1126
item : ExtractedUiItem :: Node {
1127
+ color : text_background_color. 0 . to_linear ( ) ,
1128
+ rect : Rect {
1129
+ min : Vec2 :: ZERO ,
1130
+ max : rect. size ( ) ,
1131
+ } ,
1126
1132
atlas_scaling : None ,
1127
- transform : transform * Affine2 :: from_translation ( rect. center ( ) ) ,
1128
1133
flip_x : false ,
1129
1134
flip_y : false ,
1130
1135
border : uinode. border ( ) ,
@@ -1397,18 +1402,21 @@ pub fn prepare_uinodes(
1397
1402
border_radius,
1398
1403
border,
1399
1404
node_type,
1400
- transform,
1405
+ rect,
1406
+ color,
1401
1407
} => {
1402
1408
let mut flags = if extracted_uinode. image != AssetId :: default ( ) {
1403
1409
shader_flags:: TEXTURED
1404
1410
} else {
1405
1411
shader_flags:: UNTEXTURED
1406
1412
} ;
1407
1413
1408
- let mut uinode_rect = extracted_uinode . rect ;
1414
+ let mut uinode_rect = * rect;
1409
1415
1410
1416
let rect_size = uinode_rect. size ( ) ;
1411
1417
1418
+ let transform = extracted_uinode. transform ;
1419
+
1412
1420
// Specify the corners of the node
1413
1421
let positions = QUAD_VERTEX_POSITIONS
1414
1422
. map ( |pos| transform. transform_point2 ( pos * rect_size) . extend ( 0. ) ) ;
@@ -1516,7 +1524,7 @@ pub fn prepare_uinodes(
1516
1524
. map ( |pos| pos / atlas_extent)
1517
1525
} ;
1518
1526
1519
- let color = extracted_uinode . color . to_f32_array ( ) ;
1527
+ let color = color. to_f32_array ( ) ;
1520
1528
if let NodeType :: Border ( border_flags) = * node_type {
1521
1529
flags |= border_flags;
1522
1530
}
@@ -1548,16 +1556,18 @@ pub fn prepare_uinodes(
1548
1556
1549
1557
let atlas_extent = image. size_2d ( ) . as_vec2 ( ) ;
1550
1558
1551
- let color = extracted_uinode. color . to_f32_array ( ) ;
1552
1559
for glyph in & extracted_uinodes. glyphs [ range. clone ( ) ] {
1560
+ let color = glyph. color . to_f32_array ( ) ;
1553
1561
let glyph_rect = glyph. rect ;
1554
1562
let rect_size = glyph_rect. size ( ) ;
1555
1563
1556
1564
// Specify the corners of the glyph
1557
1565
let positions = QUAD_VERTEX_POSITIONS . map ( |pos| {
1558
- glyph
1566
+ extracted_uinode
1559
1567
. transform
1560
- . transform_point2 ( pos * glyph_rect. size ( ) )
1568
+ . transform_point2 (
1569
+ glyph. translation + pos * glyph_rect. size ( ) ,
1570
+ )
1561
1571
. extend ( 0. )
1562
1572
} ) ;
1563
1573
@@ -1593,7 +1603,7 @@ pub fn prepare_uinodes(
1593
1603
1594
1604
// cull nodes that are completely clipped
1595
1605
let transformed_rect_size =
1596
- glyph . transform . transform_vector2 ( rect_size) ;
1606
+ extracted_uinode . transform . transform_vector2 ( rect_size) ;
1597
1607
if positions_diff[ 0 ] . x - positions_diff[ 1 ] . x
1598
1608
>= transformed_rect_size. x . abs ( )
1599
1609
|| positions_diff[ 1 ] . y - positions_diff[ 2 ] . y
0 commit comments