Skip to content

Commit

Permalink
add ui to example
Browse files Browse the repository at this point in the history
  • Loading branch information
IceSentry committed Jan 15, 2023
1 parent 24143c8 commit 323b3b3
Showing 1 changed file with 46 additions and 2 deletions.
48 changes: 46 additions & 2 deletions examples/3d/wireframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ fn main() {
..default()
},
}))
.add_plugin(WireframePlugin)
// Wireframes can be configured with this resource
// Wireframes can be configured with this resource. This can be changed at runtime.
// See the associated docs for more details
.insert_resource(WireframeConfig {
global: true,
color: Color::GREEN,
})
.add_plugin(WireframePlugin)
.add_startup_system(setup)
.add_system(update_colors)
.run();
Expand All @@ -31,6 +31,7 @@ fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
asset_server: Res<AssetServer>,
) {
// plane
commands.spawn(PbrBundle {
Expand Down Expand Up @@ -78,14 +79,57 @@ fn setup(
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});

// Text used to show controls
commands.spawn(
TextBundle::from_section(
"",
TextStyle {
font: asset_server.load("fonts/FiraMono-Medium.ttf"),
font_size: 18.0,
color: Color::WHITE,
},
)
.with_style(Style {
position_type: PositionType::Absolute,
position: UiRect {
top: Val::Px(10.0),
left: Val::Px(10.0),
..default()
},
..default()
}),
);
}

/// This system let's you toggle various wireframe settings
fn update_colors(
keyboard_input: Res<Input<KeyCode>>,
mut config: ResMut<WireframeConfig>,
mut wireframe_colors: Query<&mut WireframeColor>,
mut text: Query<&mut Text>,
) {
let mut text = text.single_mut();
let text = &mut text.sections[0].value;

*text = "WireframeConfig\n".to_string();
text.push_str("-------------\n");
text.push_str(&format!("Global: {}\n", config.global));
text.push_str(&format!(
"Color: r={} g={} b={}\n",
config.color.r(),
config.color.g(),
config.color.b()
));

text.push_str("\n\n");

text.push_str("Controls\n");
text.push_str("---------------\n");
text.push_str("Z - Toggle global\n");
text.push_str("X - Change global color\n");
text.push_str("X - Change color of the center cube wireframe\n");

// Toggle showing a wireframe on all meshes
if keyboard_input.just_pressed(KeyCode::Z) {
info!("toggle global");
Expand Down

0 comments on commit 323b3b3

Please sign in to comment.