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//! This example demonstrates how to use font weights with text.
use bevy::prelude::*;
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 Weights"),
TextFont {
font: font.clone(),
font_size: 32.0,
..default()
},
Underline,
),
(
Node {
flex_direction: FlexDirection::Column,
padding: px(8.).all(),
row_gap: px(8.),
..default()
},
children![
(
Text::new("Weight 100"),
TextFont {
font: font.clone(),
font_size: 32.0,
weight: FontWeight(100),
..default()
},
),
(
Text::new("Weight 134"),
TextFont {
font: font.clone(),
font_size: 32.0,
weight: FontWeight(134),
..default()
},
),
(
Text::new("Weight 200"),
TextFont {
font: font.clone(),
font_size: 32.0,
weight: FontWeight(200),
..default()
},
),
(
Text::new("Weight 300"),
TextFont {
font: font.clone(),
font_size: 32.0,
weight: FontWeight(300),
..default()
},
),
(
Text::new("Weight 400"),
TextFont {
font: font.clone(),
font_size: 32.0,
weight: FontWeight(400),
..default()
},
),
(
Text::new("Weight 500"),
TextFont {
font: font.clone(),
font_size: 32.0,
weight: FontWeight(500),
..default()
},
),
(
Text::new("Weight 600"),
TextFont {
font: font.clone(),
font_size: 32.0,
weight: FontWeight(600),
..default()
},
),
(
Text::new("Weight 700"),
TextFont {
font: font.clone(),
font_size: 32.0,
weight: FontWeight(700),
..default()
},
),
(
Text::new("Weight 800"),
TextFont {
font: font.clone(),
font_size: 32.0,
weight: FontWeight(800),
..default()
},
),
(
Text::new("Weight 900"),
TextFont {
font: font.clone(),
font_size: 32.0,
weight: FontWeight(900),
..default()
},
),
(
Text::new("Weight 950"),
TextFont {
font: font.clone(),
font_size: 32.0,
weight: FontWeight(950),
..default()
},
)
]
),
],
));
}