diff --git a/system/ui/lib/application.py b/system/ui/lib/application.py index 908b8e0cd4..76d6867514 100644 --- a/system/ui/lib/application.py +++ b/system/ui/lib/application.py @@ -8,6 +8,9 @@ DEFAULT_TEXT_SIZE = 60 DEFAULT_FPS = 60 FONT_DIR = os.path.join(BASEDIR, "selfdrive/assets/fonts") +DEBUG_FPS = os.getenv("DEBUG_FPS") == '1' + + class FontWeight(IntEnum): BLACK = 0 BOLD = 1 @@ -58,6 +61,18 @@ class GuiApplication: rl.close_window() + def render(self): + while not rl.window_should_close(): + rl.begin_drawing() + rl.clear_background(rl.BLACK) + + yield + + if DEBUG_FPS: + rl.draw_fps(10, 10) + + rl.end_drawing() + def font(self, font_wight: FontWeight=FontWeight.NORMAL): return self._fonts[font_wight] diff --git a/system/ui/lib/utils.py b/system/ui/lib/utils.py index e6fc2ee0da..77035d0da0 100644 --- a/system/ui/lib/utils.py +++ b/system/ui/lib/utils.py @@ -1,5 +1,6 @@ import pyray as rl + class GuiStyleContext: def __init__(self, styles: list[tuple[int, int, int]]): """styles is a list of tuples (control, prop, new_value)""" diff --git a/system/ui/reset.py b/system/ui/reset.py index 6462b3559e..65665e36c0 100755 --- a/system/ui/reset.py +++ b/system/ui/reset.py @@ -110,12 +110,9 @@ def main(): if mode == ResetMode.FORMAT: reset.start_reset() - while not rl.window_should_close(): - rl.begin_drawing() - rl.clear_background(rl.BLACK) + for _ in gui_app.render(): if not reset.render(rl.Rectangle(45, 200, gui_app.width - 90, gui_app.height - 245)): break - rl.end_drawing() if __name__ == "__main__": diff --git a/system/ui/spinner.py b/system/ui/spinner.py index 24193ff3df..b18a9bd2d1 100755 --- a/system/ui/spinner.py +++ b/system/ui/spinner.py @@ -15,14 +15,17 @@ MARGIN = 200 TEXTURE_SIZE = 360 FONT_SIZE = 80 + def clamp(value, min_value, max_value): return max(min(value, max_value), min_value) + def check_input_non_blocking(): if sys.stdin in select.select([sys.stdin], [], [], 0)[0]: return sys.stdin.readline().strip() return "" + def main(): gui_app.init_window("Spinner") @@ -37,10 +40,7 @@ def main(): spinner_origin = rl.Vector2(TEXTURE_SIZE / 2.0, TEXTURE_SIZE / 2.0) comma_position = rl.Vector2(center.x - TEXTURE_SIZE / 2.0, center.y - TEXTURE_SIZE / 2.0) - while not rl.window_should_close(): - rl.begin_drawing() - rl.clear_background(rl.BLACK) - + for _ in gui_app.render(): # Update rotation rotation = (rotation + ROTATION_RATE) % 360.0 @@ -69,8 +69,6 @@ def main(): rl.draw_text_ex(gui_app.font(), user_input, rl.Vector2(center.x - text_size.x / 2, y_pos), FONT_SIZE, 1.0, rl.WHITE) - rl.end_drawing() - if __name__ == "__main__": main() diff --git a/system/ui/text.py b/system/ui/text.py index 82c19e5b5d..ce8af9ee50 100755 --- a/system/ui/text.py +++ b/system/ui/text.py @@ -44,10 +44,7 @@ def main(): content_rect = rl.Rectangle(0, 0, textarea_rect.width - 20, len(wrapped_lines) * LINE_HEIGHT) scroll_panel = GuiScrollPanel(textarea_rect, content_rect, show_vertical_scroll_bar=True) - while not rl.window_should_close(): - rl.begin_drawing() - rl.clear_background(rl.BLACK) - + for _ in gui_app.render(): scroll = scroll_panel.handle_scroll() rl.begin_scissor_mode(int(textarea_rect.x), int(textarea_rect.y), int(textarea_rect.width), int(textarea_rect.height)) @@ -60,8 +57,6 @@ def main(): if gui_button(button_bounds, "Reboot"): HARDWARE.reboot() - rl.end_drawing() - if __name__ == "__main__": main()