Skip to content

Commit 07d06ae

Browse files
authored
Only regenerate text measure funcs on changes to the scale factor, not the camera or target size (#20538)
# Objective `measure_text_system` should only remeasure text nodes on changes to scale factor and their text, not the target camera or target size. ## Solution Instead of checking if the `ComputedUiTargetCamera` component has changed, compare the computed target scale factor to the scale factor from the previous frame stored in `ComputedNode`.
1 parent d95313b commit 07d06ae

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

crates/bevy_ui/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ impl Plugin for UiPlugin {
188188
ui_stack_system
189189
.in_set(UiSystems::Stack)
190190
// These systems don't care about stack index
191+
.ambiguous_with(widget::measure_text_system)
191192
.ambiguous_with(update_clipping_system)
192193
.ambiguous_with(ui_layout_system)
193194
.ambiguous_with(widget::update_viewport_render_target_size)

crates/bevy_ui/src/widget/text.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,17 +276,22 @@ pub fn measure_text_system(
276276
&mut ContentSize,
277277
&mut TextNodeFlags,
278278
&mut ComputedTextBlock,
279-
Ref<ComputedUiTargetCamera>,
279+
&ComputedUiTargetCamera,
280+
&ComputedNode,
280281
),
281282
With<Node>,
282283
>,
283284
mut text_reader: TextUiReader,
284285
mut text_pipeline: ResMut<TextPipeline>,
285286
mut font_system: ResMut<CosmicFontSystem>,
286287
) {
287-
for (entity, block, content_size, text_flags, computed, computed_target) in &mut text_query {
288+
for (entity, block, content_size, text_flags, computed, computed_target, computed_node) in
289+
&mut text_query
290+
{
288291
// Note: the ComputedTextBlock::needs_rerender bool is cleared in create_text_measure().
289-
if computed_target.is_changed()
292+
// 1e-5 epsilon to ignore tiny scale factor float errors
293+
if 1e-5
294+
< (computed_target.scale_factor() - computed_node.inverse_scale_factor.recip()).abs()
290295
|| computed.needs_rerender()
291296
|| text_flags.needs_measure_fn
292297
|| content_size.is_added()

0 commit comments

Comments
 (0)