From 5e266f1551d279b0967bbbd45b229bdfbbf1e7de Mon Sep 17 00:00:00 2001 From: Jonathan Johnson Date: Sun, 7 Apr 2024 14:33:50 -0700 Subject: [PATCH] Optimizing label text recaching I had previously had similar logic in here, but I realized I couldn't reliably detect if cosmic_text had done any wrapping or not. After a discussion prompted me to see if recaching was happening while scrolling, I realized I could at least allow the width to be >= the measured text size and <= the requested layout width. This prevents recaching while scrolling. --- src/widgets/label.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/widgets/label.rs b/src/widgets/label.rs index 8d2c226..35560d0 100644 --- a/src/widgets/label.rs +++ b/src/widgets/label.rs @@ -52,7 +52,8 @@ where if cache.text.can_render_to(&context.gfx) && cache.generation == check_generation && cache.color == color - && cache.width == width + && width <= cache.width + && cache.text.size.width <= width && cache.families == current_families => {} _ => { let measured = self.display.map(|text| {