@@ -14,13 +14,13 @@ fn main() {
14
14
..default ( )
15
15
} ,
16
16
} ) )
17
- . add_plugin ( WireframePlugin )
18
- // Wireframes can be configured with this resource
17
+ // Wireframes can be configured with this resource. This can be changed at runtime.
19
18
// See the associated docs for more details
20
19
. insert_resource ( WireframeConfig {
21
20
global : true ,
22
21
color : Color :: GREEN ,
23
22
} )
23
+ . add_plugin ( WireframePlugin )
24
24
. add_startup_system ( setup)
25
25
. add_system ( update_colors)
26
26
. run ( ) ;
@@ -31,6 +31,7 @@ fn setup(
31
31
mut commands : Commands ,
32
32
mut meshes : ResMut < Assets < Mesh > > ,
33
33
mut materials : ResMut < Assets < StandardMaterial > > ,
34
+ asset_server : Res < AssetServer > ,
34
35
) {
35
36
// plane
36
37
commands. spawn ( PbrBundle {
@@ -78,14 +79,57 @@ fn setup(
78
79
transform : Transform :: from_xyz ( -2.0 , 2.5 , 5.0 ) . looking_at ( Vec3 :: ZERO , Vec3 :: Y ) ,
79
80
..default ( )
80
81
} ) ;
82
+
83
+ // Text used to show controls
84
+ commands. spawn (
85
+ TextBundle :: from_section (
86
+ "" ,
87
+ TextStyle {
88
+ font : asset_server. load ( "fonts/FiraMono-Medium.ttf" ) ,
89
+ font_size : 18.0 ,
90
+ color : Color :: WHITE ,
91
+ } ,
92
+ )
93
+ . with_style ( Style {
94
+ position_type : PositionType :: Absolute ,
95
+ position : UiRect {
96
+ top : Val :: Px ( 10.0 ) ,
97
+ left : Val :: Px ( 10.0 ) ,
98
+ ..default ( )
99
+ } ,
100
+ ..default ( )
101
+ } ) ,
102
+ ) ;
81
103
}
82
104
83
105
/// This system let's you toggle various wireframe settings
84
106
fn update_colors (
85
107
keyboard_input : Res < Input < KeyCode > > ,
86
108
mut config : ResMut < WireframeConfig > ,
87
109
mut wireframe_colors : Query < & mut WireframeColor > ,
110
+ mut text : Query < & mut Text > ,
88
111
) {
112
+ let mut text = text. single_mut ( ) ;
113
+ let text = & mut text. sections [ 0 ] . value ;
114
+
115
+ * text = "WireframeConfig\n " . to_string ( ) ;
116
+ text. push_str ( "-------------\n " ) ;
117
+ text. push_str ( & format ! ( "Global: {}\n " , config. global) ) ;
118
+ text. push_str ( & format ! (
119
+ "Color: r={} g={} b={}\n " ,
120
+ config. color. r( ) ,
121
+ config. color. g( ) ,
122
+ config. color. b( )
123
+ ) ) ;
124
+
125
+ text. push_str ( "\n \n " ) ;
126
+
127
+ text. push_str ( "Controls\n " ) ;
128
+ text. push_str ( "---------------\n " ) ;
129
+ text. push_str ( "Z - Toggle global\n " ) ;
130
+ text. push_str ( "X - Change global color\n " ) ;
131
+ text. push_str ( "X - Change color of the center cube wireframe\n " ) ;
132
+
89
133
// Toggle showing a wireframe on all meshes
90
134
if keyboard_input. just_pressed ( KeyCode :: Z ) {
91
135
info ! ( "toggle global" ) ;
0 commit comments