-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Expand file tree
/
Copy pathfont_variations.rs
More file actions
61 lines (56 loc) · 1.98 KB
/
Copy pathfont_variations.rs
File metadata and controls
61 lines (56 loc) · 1.98 KB
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
//! This example demonstrates how to use font variations to control variable font axes.
use bevy::prelude::*;
use bevy::text::{FontVariationTag, FontVariations};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.run();
}
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
let font: FontSource = asset_server.load("fonts/MonaSans-VariableFont.ttf").into();
commands.spawn(Camera2d);
commands.spawn((
Node {
flex_direction: FlexDirection::Column,
align_self: AlignSelf::Center,
justify_self: JustifySelf::Center,
align_items: AlignItems::Center,
..default()
},
children![
(
Text::new("Font Variations (wght axis)"),
TextFont {
font: font.clone(),
font_size: FontSize::Px(32.0),
..default()
},
Underline,
),
(
Node {
flex_direction: FlexDirection::Column,
padding: px(8.).all(),
row_gap: px(8.),
..default()
},
Children::spawn(SpawnIter(
[100, 200, 300, 400, 500, 600, 700, 800, 900]
.into_iter()
.map(move |weight| (
Text(format!("wght {weight}")),
TextFont {
font: font.clone(),
font_size: FontSize::Px(32.0),
font_variations: FontVariations::builder()
.set(FontVariationTag::WEIGHT, weight as f32)
.build(),
..default()
},
))
)),
),
],
));
}