From 142663c490b8ec88770fc0d8bc16cfcfff3f7a62 Mon Sep 17 00:00:00 2001 From: discountchubbs Date: Sat, 22 Nov 2025 20:12:44 -0800 Subject: [PATCH] smoother updating --- system/ui/sunnypilot/widgets/progress_bar.py | 22 ++++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/system/ui/sunnypilot/widgets/progress_bar.py b/system/ui/sunnypilot/widgets/progress_bar.py index 3506b7a301..051073f030 100644 --- a/system/ui/sunnypilot/widgets/progress_bar.py +++ b/system/ui/sunnypilot/widgets/progress_bar.py @@ -22,24 +22,28 @@ class ProgressBarAction(ItemAction): def _render(self, rect: rl.Rectangle): font_size = 40 text_size = measure_text_cached(self._font, self.text, font_size) - padding = 30 bar_width = text_size.x + 2 * padding - bar_height = 60 + text_x = (bar_width - text_size.x) / 2 - bar_x = rect.x + rect.width - bar_width - bar_y = rect.y + (rect.height - bar_height) / 2 - bar_rect = rl.Rectangle(bar_x, bar_y, bar_width, bar_height) + if self.show_progress and len(parts := self.text.split(' - ', 1)) == 2: + prefix = parts[0] + max_prefix_w = measure_text_cached(self._font, "100%", font_size).x + current_prefix_w = measure_text_cached(self._font, prefix, font_size).x + + bar_width = (text_size.x - current_prefix_w + max_prefix_w) + 2 * padding + text_x = padding + (max_prefix_w - current_prefix_w) + + bar_height = 60 + bar_rect = rl.Rectangle(rect.x + rect.width - bar_width, rect.y + (rect.height - bar_height) / 2, bar_width, bar_height) if self.show_progress: inner_rect = rl.Rectangle(bar_rect.x + 4, bar_rect.y + 4, bar_rect.width - 8, bar_rect.height - 8) if inner_rect.width > 0: - fill_width = inner_rect.width * (self.progress / 100.0) + fill_width = max(0, min(inner_rect.width, inner_rect.width * (self.progress / 100.0))) rl.draw_rectangle_rounded(rl.Rectangle(inner_rect.x, inner_rect.y, fill_width, inner_rect.height), 0.2, 10, rl.Color(30, 121, 232, 255)) - text_x = bar_rect.x + (bar_rect.width - text_size.x) / 2 - text_y = bar_rect.y + (bar_rect.height - text_size.y) / 2 - rl.draw_text_ex(self._font, self.text, rl.Vector2(text_x, text_y), font_size, 0, self.text_color) + rl.draw_text_ex(self._font, self.text, rl.Vector2(bar_rect.x + text_x, bar_rect.y + (bar_height - text_size.y) / 2), font_size, 0, self.text_color) def progress_item(title):