@@ -3,7 +3,11 @@ use bevy::{
3
3
prelude:: * ,
4
4
ui:: ContentSize ,
5
5
} ;
6
- use bevy_vello:: { VelloPlugin , prelude:: * , text:: VelloTextAnchor } ;
6
+ use bevy_vello:: {
7
+ VelloPlugin ,
8
+ prelude:: * ,
9
+ text:: { VelloTextAlign , VelloTextAnchor } ,
10
+ } ;
7
11
8
12
const EMBEDDED_FONT : & str = "embedded://text/assets/RobotoFlex-VariableFont_GRAD,XOPQ,XTRA,YOPQ,YTAS,YTDE,YTFI,YTLC,YTUC,opsz,slnt,wdth,wght.ttf" ;
9
13
@@ -32,35 +36,61 @@ fn setup_camera(mut commands: Commands) {
32
36
}
33
37
34
38
fn setup_worldspace_text ( mut commands : Commands , asset_server : ResMut < AssetServer > ) {
39
+ let brush = vello:: peniko:: Brush :: Solid ( vello:: peniko:: Color :: WHITE ) ;
40
+
41
+ commands. spawn ( (
42
+ VelloTextBundle {
43
+ text : VelloTextSection {
44
+ value : "bevy_vello using RobotoFlex-VariableFont" . to_string ( ) ,
45
+ style : VelloTextStyle {
46
+ font : asset_server. load ( EMBEDDED_FONT ) ,
47
+ brush : brush. clone ( ) ,
48
+ line_height : 1.5 ,
49
+ word_spacing : 2.0 ,
50
+ letter_spacing : 2.0 ,
51
+ font_size : 32.0 ,
52
+ ..default ( )
53
+ } ,
54
+ ..default ( )
55
+ } ,
56
+ text_anchor : VelloTextAnchor :: Center ,
57
+ transform : Transform :: from_xyz ( 0.0 , 150.0 , 0.0 ) ,
58
+ ..default ( )
59
+ } ,
60
+ WithAnimatedFont ,
61
+ ) ) ;
62
+
35
63
commands. spawn ( VelloTextBundle {
36
64
text : VelloTextSection {
37
65
value : "bevy_vello using Bevy's default font" . to_string ( ) ,
38
66
style : VelloTextStyle {
39
67
font_size : 24.0 ,
40
68
..default ( )
41
69
} ,
70
+ ..default ( )
42
71
} ,
43
72
text_anchor : VelloTextAnchor :: Center ,
44
- transform : Transform :: from_xyz ( 0.0 , - 100 .0, 0.0 ) ,
73
+ transform : Transform :: from_xyz ( 0.0 , 40 .0, 0.0 ) ,
45
74
..default ( )
46
75
} ) ;
47
76
48
- let brush = vello:: peniko:: Brush :: Solid ( vello:: peniko:: Color :: WHITE ) ;
49
-
50
77
commands. spawn ( VelloTextBundle {
51
78
text : VelloTextSection {
52
- value : "bevy_vello using RobotoFlex-VariableFont" . to_string ( ) ,
79
+ value : "Justified text along a width\n but the last line is not justified" . to_string ( ) ,
80
+ text_align : VelloTextAlign :: Justified ,
81
+ width : Some ( 720.0 ) ,
53
82
style : VelloTextStyle {
54
83
font : asset_server. load ( EMBEDDED_FONT ) ,
55
84
brush,
56
85
line_height : 1.5 ,
57
86
word_spacing : 2.0 ,
58
87
letter_spacing : 2.0 ,
59
- font_size : 48 .0,
88
+ font_size : 32 .0,
60
89
..default ( )
61
90
} ,
62
91
} ,
63
92
text_anchor : VelloTextAnchor :: Center ,
93
+ transform : Transform :: from_xyz ( 0.0 , -100.0 , 0.0 ) ,
64
94
..default ( )
65
95
} ) ;
66
96
}
@@ -121,9 +151,12 @@ fn toggle_animations(
121
151
122
152
const ANIMATION_SPEED : f32 = 5.0 ;
123
153
154
+ #[ derive( Component ) ]
155
+ struct WithAnimatedFont ;
156
+
124
157
fn animate_axes (
125
158
time : Res < Time > ,
126
- mut query : Query < & mut VelloTextSection > ,
159
+ mut text_section : Single < & mut VelloTextSection , With < WithAnimatedFont > > ,
127
160
animation_toggles : Res < AnimationToggles > ,
128
161
) {
129
162
let sin_time = ( time. elapsed_secs ( ) * ANIMATION_SPEED )
@@ -144,54 +177,52 @@ fn animate_axes(
144
177
let descender_depth = sin_time. remap ( 0. , 1. , -98. , -305. ) ;
145
178
let figure_height = sin_time. remap ( 0. , 1. , 560. , 788. ) ;
146
179
147
- for mut text_section in query. iter_mut ( ) {
148
- if animation_toggles. weight {
149
- text_section. style . font_axes . weight = Some ( font_weight) ;
150
- }
180
+ if animation_toggles. weight {
181
+ text_section. style . font_axes . weight = Some ( font_weight) ;
182
+ }
151
183
152
- if animation_toggles. width {
153
- text_section. style . font_axes . width = Some ( font_width) ;
154
- }
184
+ if animation_toggles. width {
185
+ text_section. style . font_axes . width = Some ( font_width) ;
186
+ }
155
187
156
- if animation_toggles. slant {
157
- text_section. style . font_axes . slant = Some ( slant) ;
158
- }
188
+ if animation_toggles. slant {
189
+ text_section. style . font_axes . slant = Some ( slant) ;
190
+ }
159
191
160
- if animation_toggles. grade {
161
- text_section. style . font_axes . grade = Some ( grade) ;
162
- }
192
+ if animation_toggles. grade {
193
+ text_section. style . font_axes . grade = Some ( grade) ;
194
+ }
163
195
164
- if animation_toggles. thick_stroke {
165
- text_section. style . font_axes . thick_stroke = Some ( thick_stroke) ;
166
- }
196
+ if animation_toggles. thick_stroke {
197
+ text_section. style . font_axes . thick_stroke = Some ( thick_stroke) ;
198
+ }
167
199
168
- if animation_toggles. thin_stroke {
169
- text_section. style . font_axes . thin_stroke = Some ( thin_stroke) ;
170
- }
200
+ if animation_toggles. thin_stroke {
201
+ text_section. style . font_axes . thin_stroke = Some ( thin_stroke) ;
202
+ }
171
203
172
- if animation_toggles. counter_width {
173
- text_section. style . font_axes . counter_width = Some ( counter_width) ;
174
- }
204
+ if animation_toggles. counter_width {
205
+ text_section. style . font_axes . counter_width = Some ( counter_width) ;
206
+ }
175
207
176
- if animation_toggles. uppercase_height {
177
- text_section. style . font_axes . uppercase_height = Some ( uppercase_height) ;
178
- }
208
+ if animation_toggles. uppercase_height {
209
+ text_section. style . font_axes . uppercase_height = Some ( uppercase_height) ;
210
+ }
179
211
180
- if animation_toggles. lowercase_height {
181
- text_section. style . font_axes . lowercase_height = Some ( lowercase_height) ;
182
- }
212
+ if animation_toggles. lowercase_height {
213
+ text_section. style . font_axes . lowercase_height = Some ( lowercase_height) ;
214
+ }
183
215
184
- if animation_toggles. ascender_height {
185
- text_section. style . font_axes . ascender_height = Some ( ascender_height) ;
186
- }
216
+ if animation_toggles. ascender_height {
217
+ text_section. style . font_axes . ascender_height = Some ( ascender_height) ;
218
+ }
187
219
188
- if animation_toggles. descender_depth {
189
- text_section. style . font_axes . descender_depth = Some ( descender_depth) ;
190
- }
220
+ if animation_toggles. descender_depth {
221
+ text_section. style . font_axes . descender_depth = Some ( descender_depth) ;
222
+ }
191
223
192
- if animation_toggles. figure_height {
193
- text_section. style . font_axes . figure_height = Some ( figure_height) ;
194
- }
224
+ if animation_toggles. figure_height {
225
+ text_section. style . font_axes . figure_height = Some ( figure_height) ;
195
226
}
196
227
}
197
228
0 commit comments