Skip to content

Commit

Permalink
fix(reviewed): fix typos, naming and bug
Browse files Browse the repository at this point in the history
Authored-by: RobWalt <[email protected]>
Reviewed-by: Joona Aalto <[email protected]>
  • Loading branch information
RobWalt committed Feb 6, 2024
1 parent e385f0b commit b5617f1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2618,13 +2618,13 @@ category = "UI (User Interface)"
wasm = true

[[example]]
name = "primitives"
path = "examples/math/primitives.rs"
name = "render-primitives"
path = "examples/math/render-primitives.rs"
doc-scrape-examples = true

[package.metadata.example.primitives]
name = "Math Primitives"
description = "Shows off all math primitives as both Meshes and Gizmos"
[package.metadata.example.render-primitives]
name = "Rendering Primitives"
description = "Shows off rendering for all math primitives as both Meshes and Gizmos"
category = "Math"
wasm = true

Expand Down
27 changes: 17 additions & 10 deletions examples/math/primitives.rs → examples/math/render-primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,19 @@ fn setup_cameras(mut commands: Commands) {
});
}

/// Marker component for header text
#[derive(Debug, Clone, Component, Default, Reflect)]
pub struct HeaderText;

/// Marker component for header node
#[derive(Debug, Clone, Component, Default, Reflect)]
pub struct HeaderNode;

fn update_active_cameras(
state: Res<State<CameraActive>>,
mut camera_2d: Query<(Entity, &mut Camera), With<Camera2d>>,
mut camera_3d: Query<(Entity, &mut Camera), (With<Camera3d>, Without<Camera2d>)>,
mut text: Query<&mut TargetCamera, With<Header>>,
mut text: Query<&mut TargetCamera, With<HeaderNode>>,
) {
let (entity_2d, mut cam_2d) = camera_2d.single_mut();
let (entity_3d, mut cam_3d) = camera_3d.single_mut();
Expand All @@ -289,10 +297,6 @@ fn update_active_cameras(
});
}

/// Marker component for header text
#[derive(Debug, Clone, Component, Default, Reflect)]
pub struct Header;

fn switch_cameras(current: Res<State<CameraActive>>, mut next: ResMut<NextState<CameraActive>>) {
let next_state = match current.get() {
CameraActive::Dim2 => CameraActive::Dim3,
Expand All @@ -319,22 +323,22 @@ fn setup_text(
color: Color::WHITE,
};
let instructions = "Press 'C' to switch between 2D and 3D mode\n\
Press 'Up' or 'Down' to switch to the next/last primitive";
Press 'Up' or 'Down' to switch to the next/previous primitive";
let text = [
TextSection::new("Primitive: ", style.clone()),
TextSection::new(text, style.clone()),
TextSection::new("\n\n", style.clone()),
TextSection::new(instructions, style.clone()),
TextSection::new("\n\n", style.clone()),
TextSection::new(
"(If nothing is displayed, there's not rendering support yet)",
"(If nothing is displayed, there's no rendering support yet)",
style.clone(),
),
];

commands
.spawn((
Header,
HeaderNode,
NodeBundle {
style: Style {
justify_self: JustifySelf::Center,
Expand All @@ -346,13 +350,16 @@ fn setup_text(
TargetCamera(active_camera),
))
.with_children(|parent| {
parent.spawn((TextBundle::from_sections(text).with_text_justify(JustifyText::Center),));
parent.spawn((
HeaderText,
TextBundle::from_sections(text).with_text_justify(JustifyText::Center),
));
});
}

fn update_text(
primitive_state: Res<State<PrimitiveSelected>>,
mut header: Query<&mut Text, With<Header>>,
mut header: Query<&mut Text, With<HeaderText>>,
) {
let new_text = format!("{text}", text = primitive_state.get());
header.iter_mut().for_each(|mut header_text| {
Expand Down

0 comments on commit b5617f1

Please sign in to comment.