Skip to content

Commit 323b3b3

Browse files
committed
add ui to example
1 parent 24143c8 commit 323b3b3

File tree

1 file changed

+46
-2
lines changed

1 file changed

+46
-2
lines changed

examples/3d/wireframe.rs

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ fn main() {
1414
..default()
1515
},
1616
}))
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.
1918
// See the associated docs for more details
2019
.insert_resource(WireframeConfig {
2120
global: true,
2221
color: Color::GREEN,
2322
})
23+
.add_plugin(WireframePlugin)
2424
.add_startup_system(setup)
2525
.add_system(update_colors)
2626
.run();
@@ -31,6 +31,7 @@ fn setup(
3131
mut commands: Commands,
3232
mut meshes: ResMut<Assets<Mesh>>,
3333
mut materials: ResMut<Assets<StandardMaterial>>,
34+
asset_server: Res<AssetServer>,
3435
) {
3536
// plane
3637
commands.spawn(PbrBundle {
@@ -78,14 +79,57 @@ fn setup(
7879
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
7980
..default()
8081
});
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+
);
81103
}
82104

83105
/// This system let's you toggle various wireframe settings
84106
fn update_colors(
85107
keyboard_input: Res<Input<KeyCode>>,
86108
mut config: ResMut<WireframeConfig>,
87109
mut wireframe_colors: Query<&mut WireframeColor>,
110+
mut text: Query<&mut Text>,
88111
) {
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+
89133
// Toggle showing a wireframe on all meshes
90134
if keyboard_input.just_pressed(KeyCode::Z) {
91135
info!("toggle global");

0 commit comments

Comments
 (0)