File tree Expand file tree Collapse file tree 3 files changed +58
-0
lines changed Expand file tree Collapse file tree 3 files changed +58
-0
lines changed Original file line number Diff line number Diff line change @@ -862,6 +862,19 @@ description = "Renders text to multiple windows with different scale factors usi
862
862
category = " 2D Rendering"
863
863
wasm = true
864
864
865
+
866
+ [[example ]]
867
+ name = " system_fonts"
868
+ path = " examples/2d/system_fonts.rs"
869
+ doc-scrape-examples = true
870
+
871
+ [package .metadata .example .system_fonts ]
872
+ name = " System Fonts"
873
+ description = " Uses a system font to display text"
874
+ category = " 2D Rendering"
875
+ # Loading asset folders is not supported in Wasm, but required to create the atlas.
876
+ wasm = false
877
+
865
878
[[example ]]
866
879
name = " texture_atlas"
867
880
path = " examples/2d/texture_atlas.rs"
Original file line number Diff line number Diff line change
1
+ //! Uses a system font to display text
2
+ use bevy:: prelude:: * ;
3
+
4
+ fn main ( ) {
5
+ App :: new ( )
6
+ . add_plugins ( DefaultPlugins )
7
+ . add_systems ( Startup , setup)
8
+ . run ( ) ;
9
+ }
10
+
11
+ fn setup ( mut commands : Commands , mut fonts : ResMut < Assets < Font > > ) {
12
+ commands. spawn ( Camera2d ) ;
13
+
14
+ let font = fonts. add ( Font :: System {
15
+ families : vec ! [
16
+ Family :: Name ( "Liberation Sans" . to_string( ) ) ,
17
+ Family :: Name ( "Ubuntu" . to_string( ) ) ,
18
+ Family :: Name ( "Noto Sans" . to_string( ) ) ,
19
+ ] ,
20
+ weight : Weight :: NORMAL ,
21
+ stretch : Stretch :: Normal ,
22
+ style : Style :: Normal ,
23
+ } ) ;
24
+
25
+ commands. spawn ( (
26
+ Node {
27
+ width : percent ( 100. ) ,
28
+ height : percent ( 100. ) ,
29
+ display : Display :: Flex ,
30
+ padding : UiRect :: all ( px ( 20. ) ) ,
31
+ justify_content : JustifyContent :: Center ,
32
+ ..default ( )
33
+ } ,
34
+ children ! [ (
35
+ Text :: new( "System Font UI Text" ) ,
36
+ TextFont :: default ( ) . with_font( font. clone( ) ) ,
37
+ ) ] ,
38
+ ) ) ;
39
+
40
+ commands. spawn ( (
41
+ Text2d :: new ( "System Font 2D Text" ) ,
42
+ TextFont :: default ( ) . with_font ( font) ,
43
+ ) ) ;
44
+ }
Original file line number Diff line number Diff line change @@ -128,6 +128,7 @@ Example | Description
128
128
[ Sprite Sheet] ( ../examples/2d/sprite_sheet.rs ) | Renders an animated sprite
129
129
[ Sprite Slice] ( ../examples/2d/sprite_slice.rs ) | Showcases slicing sprites into sections that can be scaled independently via the 9-patch technique
130
130
[ Sprite Tile] ( ../examples/2d/sprite_tile.rs ) | Renders a sprite tiled in a grid
131
+ [ System Fonts] ( ../examples/2d/system_fonts.rs ) | Uses a system font to display text
131
132
[ Text 2D] ( ../examples/2d/text2d.rs ) | Generates text in 2D
132
133
[ Texture Atlas] ( ../examples/2d/texture_atlas.rs ) | Generates a texture atlas (sprite sheet) from individual sprites
133
134
[ Tilemap Chunk] ( ../examples/2d/tilemap_chunk.rs ) | Renders a tilemap chunk
You can’t perform that action at this time.
0 commit comments