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