Skip to content

Commit 84e1278

Browse files
authored
Update size and metrics after set_rich_text in TextPipeline::update_buffer (#22021)
# Objective Rearrange the order that cosmic text's properties are set for improved performance. ## Solution Update size and metrics after `set_rich_text` in `TextPipeline::update_buffer` ## Testing yellow = this PR, red = main: ``` cargo run --example many_glyphs --features=trace_tracy,debug --release -- --recompute-text ``` <img width="1610" height="605" alt="reorder" src="https://github.com/user-attachments/assets/4819aa79-a147-45ab-8636-3e17f81462b2" /> <img width="1603" height="617" alt="reorder-measure-text" src="https://github.com/user-attachments/assets/eb74569d-79e1-4138-9283-641eae8fd2ab" />
1 parent 89e4193 commit 84e1278

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

crates/bevy_text/src/pipeline.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ impl TextPipeline {
191191

192192
// Update the buffer.
193193
let buffer = &mut computed.buffer;
194-
buffer.set_size(font_system, bounds.width, bounds.height);
195194

196195
buffer.set_wrap(
197196
font_system,
@@ -213,11 +212,10 @@ impl TextPipeline {
213212

214213
// Workaround for alignment not working for unbounded text.
215214
// See https://github.com/pop-os/cosmic-text/issues/343
216-
if bounds.width.is_none() && justify != Justify::Left {
217-
let dimensions = buffer_dimensions(buffer);
218-
// `set_size` causes a re-layout to occur.
219-
buffer.set_size(font_system, Some(dimensions.x), bounds.height);
220-
}
215+
let width = (bounds.width.is_none() && justify != Justify::Left)
216+
.then(|| buffer_dimensions(buffer).x)
217+
.or(bounds.width);
218+
buffer.set_size(font_system, width, bounds.height);
221219

222220
// Recover the spans buffer.
223221
spans.clear();

0 commit comments

Comments
 (0)