Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bevyengine
GitHub Repository: bevyengine/bevy
Path: blob/main/examples/ui/strikethrough.rs
7218 views
1
//! This example illustrates UI text with strikethrough
2
3
use bevy::{
4
color::palettes::css::{GREEN, NAVY, RED},
5
prelude::*,
6
};
7
8
fn main() {
9
App::new()
10
.add_plugins(DefaultPlugins)
11
.add_systems(Startup, setup)
12
.run();
13
}
14
15
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
16
commands.spawn(Camera2d);
17
commands.spawn((
18
Text::new("struck\nstruck"),
19
// Just add the `Strikethrough` component to any `Text`, `Text2d` or `TextSpan` and it's text will be struck through.
20
Strikethrough,
21
TextFont {
22
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
23
font_size: 67.0,
24
..default()
25
},
26
TextLayout::new_with_justify(Justify::Center),
27
Node {
28
position_type: PositionType::Absolute,
29
bottom: px(5),
30
right: px(5),
31
..default()
32
},
33
TextBackgroundColor::BLACK,
34
));
35
36
commands.spawn((
37
Node {
38
flex_direction: FlexDirection::Column,
39
width: Val::Percent(100.),
40
height: Val::Percent(100.),
41
justify_content: JustifyContent::Center,
42
align_items: AlignItems::Center,
43
..Default::default()
44
},
45
children![
46
(
47
Text::new("struck\nstruckstruck\nstruckstuckstruck"),
48
Strikethrough,
49
TextBackgroundColor(GREEN.into()),
50
),
51
(Text::new("underline"), Underline),
52
(
53
Text::new("struck"),
54
Strikethrough,
55
TextBackgroundColor(GREEN.into()),
56
children![
57
(TextSpan::new("underline"), Underline),
58
(TextSpan::new("struck"), Strikethrough,)
59
],
60
),
61
(
62
Text::new("struck struck"),
63
Strikethrough,
64
TextFont {
65
font_size: 67.0,
66
..default()
67
},
68
),
69
(
70
Text::new("2struck\nstruck"),
71
Strikethrough,
72
TextFont {
73
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
74
font_size: 67.0,
75
..default()
76
},
77
BackgroundColor(NAVY.into())
78
),
79
(
80
Text::new(""),
81
children![
82
(
83
TextSpan::new("struck"),
84
Strikethrough,
85
TextFont {
86
font_size: 15.,
87
..default()
88
},
89
TextColor(RED.into()),
90
TextBackgroundColor(Color::BLACK)
91
),
92
(
93
TextSpan::new("\nunderline"),
94
Underline,
95
TextFont {
96
font_size: 30.,
97
..default()
98
},
99
TextColor(RED.into()),
100
TextBackgroundColor(GREEN.into())
101
),
102
(
103
TextSpan::new("\nstruck"),
104
TextFont {
105
font_size: 50.,
106
..default()
107
},
108
Strikethrough,
109
TextColor(RED.into()),
110
TextBackgroundColor(NAVY.into())
111
),
112
(
113
TextSpan::new("underlined and struck"),
114
TextFont {
115
font_size: 70.,
116
..default()
117
},
118
Strikethrough,
119
Underline,
120
TextColor(RED.into()),
121
TextBackgroundColor(NAVY.into())
122
)
123
]
124
),
125
],
126
));
127
}
128
129