1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
use crateFontMesh;
use *;
/// Determines where the text mesh is positioned relative to its transform origin.
///
/// The anchor point acts as a pivot for positioning the text. For example, [`TextAnchor::Center`]
/// places the transform at the center of the text bounds, while [`TextAnchor::BottomLeft`]
/// places it at the bottom-left corner.
///
/// # Examples
///
/// ```
/// # use bevy_fontmesh::prelude::*;
/// # use bevy::prelude::*;
/// # use bevy::prelude::default;
/// // Text centered on its transform
/// let style = TextMeshStyle {
/// anchor: TextAnchor::Center,
/// ..default()
/// };
///
/// // Text positioned by its top-left corner
/// let style = TextMeshStyle {
/// anchor: TextAnchor::TopLeft,
/// ..default()
/// };
///
/// // Custom pivot point at 25% from left, 75% from bottom
/// let style = TextMeshStyle {
/// anchor: TextAnchor::Custom(Vec2::new(0.25, 0.75)),
/// ..default()
/// };
/// ```
/// Component for generating 3D text meshes from fonts.
///
/// When added to an entity, this component triggers automatic generation of a 3D mesh
/// based on the specified text, font, and style. The mesh is regenerated whenever the
/// component changes.
///
/// # Examples
///
/// ```no_run
/// # use bevy::prelude::*;
/// # use bevy_fontmesh::prelude::*;
/// # fn example(mut commands: Commands, asset_server: Res<AssetServer>) {
/// commands.spawn(TextMeshBundle::<StandardMaterial> {
/// text_mesh: TextMesh {
/// text: "Hello, World!".to_string(),
/// font: asset_server.load("fonts/font.ttf"),
/// style: TextMeshStyle {
/// depth: 0.5,
/// subdivision: 25,
/// anchor: TextAnchor::Center,
/// justify: JustifyText::Center,
/// },
/// },
/// ..default()
/// });
/// # }
/// ```
///
/// # Multiline Text
///
/// Use `\n` for line breaks:
///
/// ```no_run
/// # use bevy::prelude::*;
/// # use bevy_fontmesh::prelude::*;
/// # fn example(mut commands: Commands, asset_server: Res<AssetServer>) {
/// commands.spawn(TextMeshBundle::<StandardMaterial> {
/// text_mesh: TextMesh {
/// text: "Line 1\nLine 2\nLine 3".to_string(),
/// font: asset_server.load("fonts/font.ttf"),
/// ..default()
/// },
/// ..default()
/// });
/// # }
/// ```
/// Controls horizontal alignment of multiline text.
///
/// This determines how multiple lines of text are aligned relative to each other.
/// For single-line text, justification has no visual effect.
///
/// # Examples
///
/// ```
/// # use bevy_fontmesh::prelude::*;
/// # use bevy::prelude::default;
/// // Left-aligned text (default)
/// let style = TextMeshStyle {
/// justify: JustifyText::Left,
/// ..default()
/// };
///
/// // Centered text
/// let style = TextMeshStyle {
/// justify: JustifyText::Center,
/// ..default()
/// };
///
/// // Right-aligned text
/// let style = TextMeshStyle {
/// justify: JustifyText::Right,
/// ..default()
/// };
/// ```
/// Visual styling parameters for generated text meshes.
///
/// Controls the 3D extrusion depth, curve smoothness, positioning, and alignment
/// of the generated mesh geometry.
///
/// # Examples
///
/// ```
/// # use bevy_fontmesh::prelude::*;
/// # use bevy::prelude::default;
/// // Flat 2D-style text
/// let flat = TextMeshStyle {
/// depth: 0.0,
/// subdivision: 15,
/// ..default()
/// };
///
/// // Deep 3D text with high quality curves
/// let deep = TextMeshStyle {
/// depth: 1.0,
/// subdivision: 30,
/// anchor: TextAnchor::Center,
/// justify: JustifyText::Center,
/// };
///
/// // Low-poly stylized text
/// let lowpoly = TextMeshStyle {
/// depth: 0.2,
/// subdivision: 5,
/// ..default()
/// };
/// ```
/// Component for generating individual 3D mesh entities for each character.
///
/// Unlike [`TextMesh`] which creates a single combined mesh for all characters,
/// `TextMeshGlyphs` spawns a separate child entity for each character. This enables:
/// - Per-character materials (different colors for syntax highlighting)
/// - Per-character animations and effects
/// - Efficient updates when only some characters change
/// - Individual character picking/interaction
///
/// Each child entity will have a [`GlyphMesh`] component with its character index.
///
/// # Examples
///
/// ```no_run
/// # use bevy::prelude::*;
/// # use bevy_fontmesh::prelude::*;
/// # fn example(
/// # mut commands: Commands,
/// # asset_server: Res<AssetServer>,
/// # mut materials: ResMut<Assets<StandardMaterial>>,
/// # ) {
/// commands.spawn(TextMeshGlyphsBundle {
/// text_glyphs: TextMeshGlyphs {
/// text: "Hello".to_string(),
/// font: asset_server.load("fonts/font.ttf"),
/// style: TextMeshStyle::default(),
/// },
/// // Default material for all glyphs (can be overridden per-glyph)
/// material: MeshMaterial3d(materials.add(StandardMaterial::default())),
/// ..default()
/// });
/// # }
/// ```
/// Marker component for individual glyph mesh entities.
///
/// This component is automatically added to child entities spawned by [`TextMeshGlyphs`].
/// It contains metadata about the glyph's position in the text.
///
/// # Fields
///
/// - `char_index`: The index of this character in the original text string
/// - `line_index`: The line number (0-indexed) this character appears on
/// - `character`: The actual character this glyph represents
/// Convenience bundle for spawning 3D text with per-character entities.
///
/// This bundle is similar to [`TextMeshBundle`] but uses [`TextMeshGlyphs`] instead,
/// which spawns separate child entities for each character.
///
/// # Examples
///
/// ```no_run
/// # use bevy::prelude::*;
/// # use bevy_fontmesh::prelude::*;
/// # fn example(
/// # mut commands: Commands,
/// # asset_server: Res<AssetServer>,
/// # mut materials: ResMut<Assets<StandardMaterial>>,
/// # ) {
/// commands.spawn(TextMeshGlyphsBundle {
/// text_glyphs: TextMeshGlyphs {
/// text: "Code".to_string(),
/// font: asset_server.load("fonts/font.ttf"),
/// style: TextMeshStyle {
/// depth: 0.1,
/// ..default()
/// },
/// },
/// material: MeshMaterial3d(materials.add(StandardMaterial {
/// base_color: Color::WHITE,
/// ..default()
/// })),
/// transform: Transform::from_xyz(0.0, 0.0, 0.0),
/// ..default()
/// });
/// # }
/// ```
/// Convenience bundle for spawning 3D text entities.
///
/// This bundle includes all necessary components for rendering 3D text in Bevy:
/// the [`TextMesh`] component for mesh generation, along with all standard 3D rendering
/// components (mesh, material, transform, visibility).
///
/// # Examples
///
/// ```no_run
/// # use bevy::prelude::*;
/// # use bevy_fontmesh::prelude::*;
/// # fn example(
/// # mut commands: Commands,
/// # asset_server: Res<AssetServer>,
/// # mut materials: ResMut<Assets<StandardMaterial>>,
/// # ) {
/// commands.spawn(TextMeshBundle {
/// text_mesh: TextMesh {
/// text: "Hello, Bevy!".to_string(),
/// font: asset_server.load("fonts/font.ttf"),
/// style: TextMeshStyle {
/// depth: 0.5,
/// anchor: TextAnchor::Center,
/// ..default()
/// },
/// },
/// material: MeshMaterial3d(materials.add(StandardMaterial {
/// base_color: Color::srgb(1.0, 0.5, 0.2),
/// ..default()
/// })),
/// transform: Transform::from_xyz(0.0, 1.0, 0.0),
/// ..default()
/// });
/// # }
/// ```
/// Render the entity's text mesh at a constant *screen-pixel* size,
/// independent of camera distance / zoom.
///
/// Each frame the [`scale_screen_size`](crate::system::scale_screen_size)
/// system rewrites the entity's `Transform.scale` (uniform on all axes)
/// so that one line of text covers `pixel_height` pixels in the active
/// camera's render target. Position stays whatever you put it at; only
/// scale changes.
///
/// Works with both orthographic and perspective cameras and with cameras
/// rendering to either a window or a `RenderTarget::Image`. For a
/// perspective camera the system measures `world_per_pixel` at the
/// entity's depth, so screen-stable size holds wherever the entity sits
/// in front of the lens.
///
/// # Caveats
///
/// - Rewrites the *entity's* scale, so don't keep your own per-frame
/// scale tweaks on the same `Transform.scale` field — they'll be
/// overwritten. Apply scale on a parent or a child instead.
/// - Children of a `ScreenSize` entity inherit its scale, which means
/// their *positions* under the parent's local frame also scale. Put
/// ScreenSize on leaf label entities, not on a parent intended to
/// carry world-position layout.
/// - Picks the first camera it finds when there are multiple. Filter
/// with [`ScreenSizeCamera`] if you need to pin to a specific one.
/// Marker on a `Camera` to opt that camera into being the one
/// `ScreenSize` measures against. If no entity in the world has this
/// marker, the screen-size system falls back to whichever camera
/// `Query<&Camera>` returns first — fine for single-camera apps.
;