@@ -28,44 +28,43 @@ struct ColorText;
28
28
fn setup ( mut commands : Commands , asset_server : Res < AssetServer > ) {
29
29
// UI camera
30
30
commands. spawn ( Camera2dBundle :: default ( ) ) ;
31
- // Text with one section
31
+ // Text with one section.
32
32
commands. spawn ( (
33
- // Create a TextBundle that has a Text with a single section.
34
- TextBundle :: from_section (
35
- // Accepts a `String` or any type that converts into a `String`, such as `&str`
36
- "hello\n bevy!" ,
37
- TextStyle {
38
- // This font is loaded and will be used instead of the default font.
39
- font : asset_server. load ( "fonts/FiraSans-Bold.ttf" ) ,
40
- font_size : 67.0 ,
41
- ..default ( )
42
- } ,
43
- ) // Set the justification of the Text
44
- . with_text_justify ( JustifyText :: Center )
45
- // Set the style of the TextBundle itself.
46
- . with_style ( Style {
33
+ // Accepts a `String` or any type that converts into a `String`, such as `&str`
34
+ TextNEW :: new ( "hello\n bevy!" ) ,
35
+ TextStyle {
36
+ // This font is loaded and will be used instead of the default font.
37
+ font : asset_server. load ( "fonts/FiraSans-Bold.ttf" ) ,
38
+ font_size : 67.0 ,
39
+ ..default ( )
40
+ } ,
41
+ // Set the justification of the Text
42
+ TextBlock :: new_with_justify ( JustifyText :: Center ) ,
43
+ // Set the style of the Node itself.
44
+ Style {
47
45
position_type : PositionType :: Absolute ,
48
46
bottom : Val :: Px ( 5.0 ) ,
49
47
right : Val :: Px ( 5.0 ) ,
50
48
..default ( )
51
- } ) ,
49
+ } ,
52
50
ColorText ,
53
51
) ) ;
54
52
55
53
// Text with multiple sections
56
- commands. spawn ( (
57
- // Create a TextBundle that has a Text with a list of sections.
58
- TextBundle :: from_sections ( [
59
- TextSection :: new (
60
- "FPS: " ,
61
- TextStyle {
62
- // This font is loaded and will be used instead of the default font.
63
- font : asset_server. load ( "fonts/FiraSans-Bold.ttf" ) ,
64
- font_size : 42.0 ,
65
- ..default ( )
66
- } ,
67
- ) ,
68
- TextSection :: from_style ( if cfg ! ( feature = "default_font" ) {
54
+ commands
55
+ . spawn ( (
56
+ // Create a Text with multiple child spans.
57
+ TextNEW :: new ( "FPS: " ) ,
58
+ TextStyle {
59
+ // This font is loaded and will be used instead of the default font.
60
+ font : asset_server. load ( "fonts/FiraSans-Bold.ttf" ) ,
61
+ font_size : 42.0 ,
62
+ ..default ( )
63
+ } ,
64
+ ) )
65
+ . with_child ( (
66
+ TextSpan :: default ( ) ,
67
+ if cfg ! ( feature = "default_font" ) {
69
68
TextStyle {
70
69
font_size : 33.0 ,
71
70
color : GOLD . into ( ) ,
@@ -79,49 +78,45 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
79
78
font_size : 33.0 ,
80
79
color : GOLD . into ( ) ,
81
80
}
82
- } ) ,
83
- ] ) ,
84
- FpsText ,
85
- ) ) ;
81
+ } ,
82
+ FpsText ,
83
+ ) ) ;
86
84
87
85
#[ cfg( feature = "default_font" ) ]
88
- commands. spawn (
86
+ commands. spawn ( (
89
87
// Here we are able to call the `From` method instead of creating a new `TextSection`.
90
88
// This will use the default font (a minimal subset of FiraMono) and apply the default styling.
91
- TextBundle :: from ( "From an &str into a TextBundle with the default font!" ) . with_style (
92
- Style {
93
- position_type : PositionType :: Absolute ,
94
- bottom : Val :: Px ( 5.0 ) ,
95
- left : Val :: Px ( 15.0 ) ,
96
- ..default ( )
97
- } ,
98
- ) ,
99
- ) ;
89
+ TextNEW :: new ( "From an &str into a Text with the default font!" ) ,
90
+ Style {
91
+ position_type : PositionType :: Absolute ,
92
+ bottom : Val :: Px ( 5.0 ) ,
93
+ left : Val :: Px ( 15.0 ) ,
94
+ ..default ( )
95
+ } ,
96
+ ) ) ;
100
97
101
98
#[ cfg( not( feature = "default_font" ) ) ]
102
- commands. spawn (
103
- TextBundle :: from_section (
104
- "Default font disabled" ,
105
- TextStyle {
106
- font : asset_server. load ( "fonts/FiraMono-Medium.ttf" ) ,
107
- ..default ( )
108
- } ,
109
- )
110
- . with_style ( Style {
99
+ commands. spawn ( (
100
+ TextNEW :: new ( "Default font disabled" ) ,
101
+ TextStyle {
102
+ font : asset_server. load ( "fonts/FiraMono-Medium.ttf" ) ,
103
+ ..default ( )
104
+ } ,
105
+ Style {
111
106
position_type : PositionType :: Absolute ,
112
107
bottom : Val :: Px ( 5.0 ) ,
113
108
left : Val :: Px ( 15.0 ) ,
114
109
..default ( )
115
- } ) ,
116
- ) ;
110
+ } ,
111
+ ) ) ;
117
112
}
118
113
119
- fn text_color_system ( time : Res < Time > , mut query : Query < & mut Text , With < ColorText > > ) {
120
- for mut text in & mut query {
114
+ fn text_color_system ( time : Res < Time > , mut query : Query < & mut TextStyle , With < ColorText > > ) {
115
+ for mut style in & mut query {
121
116
let seconds = time. elapsed_seconds ( ) ;
122
117
123
- // Update the color of the first and only section .
124
- text . sections [ 0 ] . style . color = Color :: srgb (
118
+ // Update the color of the ColorText span .
119
+ style. color = Color :: srgb (
125
120
ops:: sin ( 1.25 * seconds) / 2.0 + 0.5 ,
126
121
ops:: sin ( 0.75 * seconds) / 2.0 + 0.5 ,
127
122
ops:: sin ( 0.50 * seconds) / 2.0 + 0.5 ,
@@ -131,13 +126,13 @@ fn text_color_system(time: Res<Time>, mut query: Query<&mut Text, With<ColorText
131
126
132
127
fn text_update_system (
133
128
diagnostics : Res < DiagnosticsStore > ,
134
- mut query : Query < & mut Text , With < FpsText > > ,
129
+ mut query : Query < & mut TextSpan , With < FpsText > > ,
135
130
) {
136
- for mut text in & mut query {
131
+ for mut span in & mut query {
137
132
if let Some ( fps) = diagnostics. get ( & FrameTimeDiagnosticsPlugin :: FPS ) {
138
133
if let Some ( value) = fps. smoothed ( ) {
139
134
// Update the value of the second section
140
- text . sections [ 1 ] . value = format ! ( "{value:.2}" ) ;
135
+ * * span = format ! ( "{value:.2}" ) ;
141
136
}
142
137
}
143
138
}
0 commit comments