Skip to content

Commit

Permalink
UI text extraction refactor (#17805)
Browse files Browse the repository at this point in the history
## 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"
/>
  • Loading branch information
ickshonpe authored Feb 11, 2025
1 parent 7d8504f commit 98dcee2
Showing 1 changed file with 12 additions and 24 deletions.
36 changes: 12 additions & 24 deletions crates/bevy_ui/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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()
Expand All @@ -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(),
Expand Down

0 comments on commit 98dcee2

Please sign in to comment.