Skip to content

Commit 86b2f17

Browse files
committed
Avoid command creation for existing text2d Aabbs
1 parent 1f7a584 commit 86b2f17

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

crates/bevy_text/src/text2d.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use bevy_ecs::{
1010
entity::Entity,
1111
event::EventReader,
1212
prelude::With,
13-
query::{Changed, Or, Without},
13+
query::{Changed, Without},
1414
reflect::ReflectComponent,
1515
system::{Commands, Local, Query, Res, ResMut},
1616
};
@@ -235,26 +235,30 @@ pub fn scale_value(value: f32, factor: f32) -> f32 {
235235
/// Used in system set [`VisibilitySystems::CalculateBounds`](bevy_render::view::VisibilitySystems::CalculateBounds).
236236
pub fn calculate_bounds_text2d(
237237
mut commands: Commands,
238-
text_to_update_aabb: Query<
239-
(Entity, &TextLayoutInfo, &Anchor),
240-
(
241-
Or<(Without<Aabb>, Changed<TextLayoutInfo>)>,
242-
Without<NoFrustumCulling>,
243-
),
238+
mut text_to_update_aabb: Query<
239+
(Entity, &TextLayoutInfo, &Anchor, Option<&mut Aabb>),
240+
(Changed<TextLayoutInfo>, Without<NoFrustumCulling>),
244241
>,
245242
) {
246-
for (entity, layout_info, anchor) in &text_to_update_aabb {
243+
for (entity, layout_info, anchor, aabb) in &mut text_to_update_aabb {
247244
// `Anchor::as_vec` gives us an offset relative to the text2d bounds, by negating it and scaling
248245
// by the logical size we compensate the transform offset in local space to get the center.
249246
let center = (-anchor.as_vec() * layout_info.logical_size)
250247
.extend(0.0)
251248
.into();
252249
// Distance in local space from the center to the x and y limits of the text2d bounds.
253250
let half_extents = (layout_info.logical_size / 2.0).extend(0.0).into();
254-
commands.entity(entity).try_insert(Aabb {
255-
center,
256-
half_extents,
257-
});
251+
if let Some(mut aabb) = aabb {
252+
*aabb = Aabb {
253+
center,
254+
half_extents,
255+
};
256+
} else {
257+
commands.entity(entity).try_insert(Aabb {
258+
center,
259+
half_extents,
260+
});
261+
}
258262
}
259263
}
260264

0 commit comments

Comments
 (0)