Skip to content

Commit 2f9613f

Browse files
authored
Minor tidying in font_atlas_debug (#17825)
# Objective Tidy up a few little things I noticed while working with this example ## Solution - Fix manual resetting of a repeating timer - Use atlas image size instead of hardcoded value. Atlases are always 512x512 right now, but hopefully not in the future. - Pluralize a variable name for a variable holding a `Vec`
1 parent c34eaf1 commit 2f9613f

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

examples/ui/font_atlas_debug.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,23 @@ fn atlas_render_system(
3939
mut commands: Commands,
4040
mut state: ResMut<State>,
4141
font_atlas_sets: Res<FontAtlasSets>,
42+
images: Res<Assets<Image>>,
4243
) {
4344
if let Some(set) = font_atlas_sets.get(&state.handle) {
44-
if let Some((_size, font_atlas)) = set.iter().next() {
45+
if let Some((_size, font_atlases)) = set.iter().next() {
4546
let x_offset = state.atlas_count as f32;
46-
if state.atlas_count == font_atlas.len() as u32 {
47+
if state.atlas_count == font_atlases.len() as u32 {
4748
return;
4849
}
49-
let font_atlas = &font_atlas[state.atlas_count as usize];
50+
let font_atlas = &font_atlases[state.atlas_count as usize];
51+
let image = images.get(&font_atlas.texture).unwrap();
5052
state.atlas_count += 1;
5153
commands.spawn((
5254
ImageNode::new(font_atlas.texture.clone()),
5355
Node {
5456
position_type: PositionType::Absolute,
5557
top: Val::ZERO,
56-
left: Val::Px(512.0 * x_offset),
58+
left: Val::Px(image.width() as f32 * x_offset),
5759
..default()
5860
},
5961
));
@@ -67,16 +69,16 @@ fn text_update_system(
6769
mut query: Query<&mut Text>,
6870
mut seeded_rng: ResMut<SeededRng>,
6971
) {
70-
if state.timer.tick(time.delta()).finished() {
71-
for mut text in &mut query {
72-
let c = seeded_rng.gen::<u8>() as char;
73-
let string = &mut **text;
74-
if !string.contains(c) {
75-
string.push(c);
76-
}
77-
}
72+
if !state.timer.tick(time.delta()).just_finished() {
73+
return;
74+
}
7875

79-
state.timer.reset();
76+
for mut text in &mut query {
77+
let c = seeded_rng.gen::<u8>() as char;
78+
let string = &mut **text;
79+
if !string.contains(c) {
80+
string.push(c);
81+
}
8082
}
8183
}
8284

0 commit comments

Comments
 (0)