55//! For an example on how to render text as part of a user interface, independent from the world
66//! viewport, you may want to look at `2d/contributors.rs` or `ui/text.rs`.
77
8- use bevy:: { prelude:: * , text:: { Text2dBounds , TextLineBreakBehaviour } } ;
8+ use bevy:: {
9+ prelude:: * ,
10+ text:: { Text2dBounds , TextLineBreakBehaviour } ,
11+ } ;
912
1013fn main ( ) {
1114 App :: new ( )
@@ -63,7 +66,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
6366 ) ) ;
6467 // Demonstrate text wrapping
6568 let slightly_smaller_text_style = TextStyle {
66- font : font ,
69+ font,
6770 font_size : 42.0 ,
6871 color : Color :: WHITE ,
6972 } ;
@@ -81,9 +84,12 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
8184 } )
8285 . with_children ( |builder| {
8386 builder. spawn ( Text2dBundle {
84- text : Text :: from_section ( "this text wraps in the box\n (Unicode linebreaks)" , slightly_smaller_text_style. clone ( ) )
85- . with_alignment ( TextAlignment :: Left )
86- . with_linebreak_behaviour ( TextLineBreakBehaviour :: Unicode ) ,
87+ text : Text :: from_section (
88+ "this text wraps in the box\n (Unicode linebreaks)" ,
89+ slightly_smaller_text_style. clone ( ) ,
90+ )
91+ . with_alignment ( TextAlignment :: Left )
92+ . with_linebreak_behaviour ( TextLineBreakBehaviour :: Unicode ) ,
8793 text_2d_bounds : Text2dBounds {
8894 // Wrap text in the rectangle
8995 size : box_size,
@@ -94,10 +100,9 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
94100 } ) ;
95101 } ) ;
96102
97-
98- let other_box_size = Vec2 :: new ( 300.0 , 200.0 ) ;
99- let other_box_position = Vec2 :: new ( 320.0 , -250.0 ) ;
100- commands
103+ let other_box_size = Vec2 :: new ( 300.0 , 200.0 ) ;
104+ let other_box_position = Vec2 :: new ( 320.0 , -250.0 ) ;
105+ commands
101106 . spawn ( SpriteBundle {
102107 sprite : Sprite {
103108 color : Color :: rgb ( 0.20 , 0.3 , 0.70 ) ,
@@ -109,9 +114,12 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
109114 } )
110115 . with_children ( |builder| {
111116 builder. spawn ( Text2dBundle {
112- text : Text :: from_section ( "this text wraps in the box\n (AnyCharacter linebreaks)" , slightly_smaller_text_style)
113- . with_alignment ( TextAlignment :: Left )
114- . with_linebreak_behaviour ( TextLineBreakBehaviour :: AnyCharacter ) ,
117+ text : Text :: from_section (
118+ "this text wraps in the box\n (AnyCharacter linebreaks)" ,
119+ slightly_smaller_text_style,
120+ )
121+ . with_alignment ( TextAlignment :: Left )
122+ . with_linebreak_behaviour ( TextLineBreakBehaviour :: AnyCharacter ) ,
115123 text_2d_bounds : Text2dBounds {
116124 // Wrap text in the rectangle
117125 size : other_box_size,
0 commit comments