diff --git a/crates/bevy_text/src/text.rs b/crates/bevy_text/src/text.rs index 330f0d977a..1755caa551 100644 --- a/crates/bevy_text/src/text.rs +++ b/crates/bevy_text/src/text.rs @@ -91,6 +91,12 @@ impl ComputedTextBlock { pub fn buffer(&self) -> &CosmicBuffer { &self.buffer } + + /// Flag the text block for rerendering. + /// Automatically unset + pub fn set_needs_rerender(&mut self) { + self.needs_rerender = true; + } } impl Default for ComputedTextBlock { diff --git a/crates/bevy_ui/src/widget/text.rs b/crates/bevy_ui/src/widget/text.rs index 1544a5ff7a..3dc583fdec 100644 --- a/crates/bevy_ui/src/widget/text.rs +++ b/crates/bevy_ui/src/widget/text.rs @@ -33,15 +33,12 @@ use tracing::error; pub struct TextNodeFlags { /// If set then a new measure function for the text node will be created. needs_measure_fn: bool, - /// If set then the text will be recomputed. - needs_recompute: bool, } impl Default for TextNodeFlags { fn default() -> Self { Self { needs_measure_fn: true, - needs_recompute: true, } } } @@ -245,7 +242,7 @@ fn create_text_measure<'a>( // Text measure func created successfully, so set `TextNodeFlags` to schedule a recompute text_flags.needs_measure_fn = false; - text_flags.needs_recompute = true; + computed.set_needs_rerender(); } Err(TextError::NoSuchFont) => { // Try again next frame @@ -319,7 +316,7 @@ fn queue_text( inverse_scale_factor: f32, block: &TextLayout, node: Ref, - mut text_flags: Mut, + text_flags: &TextNodeFlags, text_layout_info: Mut, computed: &mut ComputedTextBlock, text_reader: &mut TextUiReader, @@ -356,7 +353,7 @@ fn queue_text( ) { Err(TextError::NoSuchFont) => { // There was an error processing the text layout, try again next frame - text_flags.needs_recompute = true; + computed.set_needs_rerender(); } Err(e @ (TextError::FailedToAddGlyph(_) | TextError::FailedToGetGlyphImage(_))) => { panic!("Fatal error when processing text: {e}."); @@ -364,7 +361,6 @@ fn queue_text( Ok(()) => { text_layout_info.size.x = scale_value(text_layout_info.size.x, inverse_scale_factor); text_layout_info.size.y = scale_value(text_layout_info.size.y, inverse_scale_factor); - text_flags.needs_recompute = false; } } } @@ -388,7 +384,7 @@ pub fn text_system( Ref, &TextLayout, &mut TextLayoutInfo, - &mut TextNodeFlags, + &TextNodeFlags, &mut ComputedTextBlock, )>, mut text_reader: TextUiReader, @@ -396,7 +392,7 @@ pub fn text_system( mut swash_cache: ResMut, ) { for (entity, node, block, text_layout_info, text_flags, mut computed) in &mut text_query { - if node.is_changed() || text_flags.needs_recompute { + if node.is_changed() || computed.needs_rerender() { queue_text( entity, &fonts,