strikethrough_and_underline/
strikethrough_and_underline.rs1use bevy::{
4 color::palettes::css::{GREEN, NAVY, RED, YELLOW},
5 prelude::*,
6};
7
8fn main() {
9 App::new()
10 .add_plugins(DefaultPlugins)
11 .add_systems(Startup, setup)
12 .run();
13}
14
15fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
16 commands.spawn(Camera2d);
17 commands.spawn((
18 Text::new("struck\nstruck"),
19 Strikethrough,
21 TextFont {
22 font: asset_server.load("fonts/FiraSans-Bold.ttf").into(),
23 font_size: FontSize::Px(67.0),
24 ..default()
25 },
26 TextLayout::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: percent(100),
40 height: 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 StrikethroughColor(RED.into()),
50 TextBackgroundColor(GREEN.into()),
51 ),
52 (Text::new("underline"), Underline),
54 (
55 Text::new("struck"),
56 Strikethrough,
57 TextBackgroundColor(GREEN.into()),
58 children![
59 (TextSpan::new("underline"), Underline),
60 (TextSpan::new("struck"), Strikethrough,)
61 ],
62 ),
63 (
64 Text::new("struck struck"),
65 Strikethrough,
66 TextFont {
67 font_size: FontSize::Px(67.0),
68 ..default()
69 },
70 ),
71 (
72 Text::new("2struck\nstruck"),
73 Strikethrough,
74 TextFont {
75 font: asset_server.load("fonts/FiraSans-Bold.ttf").into(),
76 font_size: FontSize::Px(67.0),
77 ..default()
78 },
79 BackgroundColor(NAVY.into())
80 ),
81 (
82 Text::new(""),
83 children![
84 (
85 TextSpan::new("struck"),
86 Strikethrough,
87 TextFont {
88 font_size: FontSize::Px(15.),
89 ..default()
90 },
91 TextColor(RED.into()),
92 TextBackgroundColor(Color::BLACK)
93 ),
94 (
95 TextSpan::new("\nunderline"),
96 Underline,
97 UnderlineColor(YELLOW.into()),
98 TextFont {
99 font_size: FontSize::Px(30.),
100 ..default()
101 },
102 TextColor(RED.into()),
103 TextBackgroundColor(GREEN.into())
104 ),
105 (
106 TextSpan::new("\nstruck"),
107 TextFont {
108 font_size: FontSize::Px(50.),
109 ..default()
110 },
111 Strikethrough,
112 TextColor(RED.into()),
113 TextBackgroundColor(NAVY.into())
114 ),
115 (
116 TextSpan::new("underlined and struck"),
117 TextFont {
118 font_size: FontSize::Px(70.),
119 ..default()
120 },
121 Strikethrough,
122 Underline,
123 TextColor(RED.into()),
124 TextBackgroundColor(NAVY.into()),
125 StrikethroughColor(Color::WHITE),
126 UnderlineColor(Color::WHITE),
127 )
128 ]
129 ),
130 ],
131 ));
132}