mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-02-18 16:33:57 +08:00
smoother updating
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user