From 17a5f1f75e320fabb71e02581b12d2fd77c38c56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hubert=20G=C5=82uchowski?= Date: Thu, 5 Dec 2024 19:15:23 +0100 Subject: [PATCH] Fix incorrect behavior with `LayoutJob::max_rows` --- crates/epaint/src/text/fonts.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/crates/epaint/src/text/fonts.rs b/crates/epaint/src/text/fonts.rs index 1db2050caeb..a681c3f0575 100644 --- a/crates/epaint/src/text/fonts.rs +++ b/crates/epaint/src/text/fonts.rs @@ -849,8 +849,17 @@ impl GalleyCache { // This will prevent us from invalidating cache entries unnecessarily if left_max_rows != usize::MAX { left_max_rows -= galley.rows.len(); + // Ignore extra trailing row, see merging counterpart below for more details. + if end < job.text.len() && !galley.elided { + left_max_rows += 1; + } } + + let elided = galley.elided; galleys.push(galley); + if elided { + break; + } current = end; } @@ -896,10 +905,9 @@ impl GalleyCache { merged_galley.num_vertices += galley.num_vertices; merged_galley.num_indices += galley.num_indices; - if galley.elided { - merged_galley.elided = true; - break; - } + // Note that if `galley.elided` is true this will be the last `Galley` in + // the vector and the loop will end. + merged_galley.elided |= galley.elided; } if merged_galley.job.round_output_size_to_nearest_ui_point {