UI text extraction refactor (#17805)

## Objective

There's no need for the `span_index` and `color` variables in
`extract_text_shadows` and `extract_text_sections` and we can remove one
of the span index comparisons since text colors are only set per
section.

## Testing

<img width="454" alt="trace"
src="https://github.com/user-attachments/assets/3109d1df-0817-46c2-9889-0459ac93a42c"
/>
This commit is contained in:
ickshonpe 2025-02-11 22:18:47 +00:00 committed by GitHub
parent 7d8504f30e
commit 98dcee2853
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -739,9 +739,6 @@ pub fn extract_text_sections(
let transform = global_transform.affine()
* bevy_math::Affine3A::from_translation((-0.5 * uinode.size()).extend(0.));
let mut color = LinearRgba::WHITE;
let mut current_span = usize::MAX;
for (
i,
PositionedGlyph {
@ -752,20 +749,6 @@ pub fn extract_text_sections(
},
) in text_layout_info.glyphs.iter().enumerate()
{
if *span_index != current_span {
color = text_styles
.get(
computed_block
.entities()
.get(*span_index)
.map(|t| t.entity)
.unwrap_or(Entity::PLACEHOLDER),
)
.map(|text_color| LinearRgba::from(text_color.0))
.unwrap_or_default();
current_span = *span_index;
}
let rect = texture_atlases
.get(&atlas_info.texture_atlas)
.unwrap()
@ -777,8 +760,18 @@ pub fn extract_text_sections(
});
if text_layout_info.glyphs.get(i + 1).is_none_or(|info| {
info.span_index != current_span || info.atlas_info.texture != atlas_info.texture
info.span_index != *span_index || info.atlas_info.texture != atlas_info.texture
}) {
let color = text_styles
.get(
computed_block
.entities()
.get(*span_index)
.map(|t| t.entity)
.unwrap_or(Entity::PLACEHOLDER),
)
.map(|text_color| LinearRgba::from(text_color.0))
.unwrap_or_default();
extracted_uinodes.uinodes.push(ExtractedUiNode {
render_entity: commands.spawn(TemporaryRenderEntity).id(),
stack_index: uinode.stack_index,
@ -850,7 +843,6 @@ pub fn extract_text_shadows(
(-0.5 * uinode.size() + shadow.offset / uinode.inverse_scale_factor()).extend(0.),
);
let mut current_span = usize::MAX;
for (
i,
PositionedGlyph {
@ -861,10 +853,6 @@ pub fn extract_text_shadows(
},
) in text_layout_info.glyphs.iter().enumerate()
{
if *span_index != current_span {
current_span = *span_index;
}
let rect = texture_atlases
.get(&atlas_info.texture_atlas)
.unwrap()
@ -876,7 +864,7 @@ pub fn extract_text_shadows(
});
if text_layout_info.glyphs.get(i + 1).is_none_or(|info| {
info.span_index != current_span || info.atlas_info.texture != atlas_info.texture
info.span_index != *span_index || info.atlas_info.texture != atlas_info.texture
}) {
extracted_uinodes.uinodes.push(ExtractedUiNode {
render_entity: commands.spawn(TemporaryRenderEntity).id(),