From f70592b7e98af2b593f27efeae577041bdc13f83 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Sun, 8 Jun 2025 22:16:17 -0700 Subject: [PATCH] raylib: format from today's prs --- selfdrive/ui/layouts/settings/device.py | 1 - selfdrive/ui/layouts/settings/software.py | 4 ++-- selfdrive/ui/widgets/exp_mode_button.py | 4 ++-- system/ui/lib/button.py | 1 - system/ui/lib/list_view.py | 9 ++++++--- system/ui/widgets/confirm_dialog.py | 1 - system/ui/widgets/option_dialog.py | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/selfdrive/ui/layouts/settings/device.py b/selfdrive/ui/layouts/settings/device.py index 741e0b0aa8..22eb6895c1 100644 --- a/selfdrive/ui/layouts/settings/device.py +++ b/selfdrive/ui/layouts/settings/device.py @@ -11,7 +11,6 @@ from openpilot.system.ui.lib.list_view import ListView, text_item, button_item from openpilot.system.ui.widgets.option_dialog import MultiOptionDialog from openpilot.system.ui.widgets.confirm_dialog import confirm_dialog, alert_dialog - # Description constants DESCRIPTIONS = { 'pair_device': "Pair your device with comma connect (connect.comma.ai) and claim your comma prime offer.", diff --git a/selfdrive/ui/layouts/settings/software.py b/selfdrive/ui/layouts/settings/software.py index 3eb80e0661..4e594d29a4 100644 --- a/selfdrive/ui/layouts/settings/software.py +++ b/selfdrive/ui/layouts/settings/software.py @@ -30,11 +30,11 @@ class SoftwareLayout(Widget): def _on_select_branch(self): pass def _on_uninstall(self): - def handle_uninstall_confirmation(result): + def handle_uninstall_confirmation(result): if result == DialogResult.CONFIRM: self._params.put_bool("DoUninstall", True) - gui_app.set_modal_overlay( + gui_app.set_modal_overlay( lambda: confirm_dialog("Are you sure you want to uninstall?", "Uninstall"), callback=handle_uninstall_confirmation, ) diff --git a/selfdrive/ui/widgets/exp_mode_button.py b/selfdrive/ui/widgets/exp_mode_button.py index d3ed4f012d..3c87aa9b28 100644 --- a/selfdrive/ui/widgets/exp_mode_button.py +++ b/selfdrive/ui/widgets/exp_mode_button.py @@ -30,7 +30,7 @@ class ExperimentalModeButton(Widget): def _draw_gradient_background(self, rect): start_color, end_color = self._get_gradient_colors() rl.draw_rectangle_gradient_h(int(rect.x), int(rect.y), int(rect.width), int(rect.height), - start_color, end_color) + start_color, end_color) def _handle_interaction(self, rect): mouse_pos = rl.get_mouse_position() @@ -59,7 +59,7 @@ class ExperimentalModeButton(Widget): # Draw text label (left aligned) text = "EXPERIMENTAL MODE ON" if self.experimental_mode else "CHILL MODE ON" text_x = rect.x + self.horizontal_padding - text_y = rect.y + rect.height / 2 - 45//2 # Center vertically + text_y = rect.y + rect.height / 2 - 45 // 2 # Center vertically rl.draw_text_ex(gui_app.font(FontWeight.NORMAL), text, rl.Vector2(int(text_x), int(text_y)), 45, 0, rl.Color(0, 0, 0, 255)) diff --git a/system/ui/lib/button.py b/system/ui/lib/button.py index df4f93fc85..121e7f86fa 100644 --- a/system/ui/lib/button.py +++ b/system/ui/lib/button.py @@ -24,7 +24,6 @@ DEFAULT_BUTTON_FONT_SIZE = 60 BUTTON_DISABLED_TEXT_COLOR = rl.Color(228, 228, 228, 51) ACTION_BUTTON_FONT_SIZE = 48 - BUTTON_TEXT_COLOR = { ButtonStyle.NORMAL: rl.Color(228, 228, 228, 255), ButtonStyle.PRIMARY: rl.Color(228, 228, 228, 255), diff --git a/system/ui/lib/list_view.py b/system/ui/lib/list_view.py index d68e71a682..fa53cff54e 100644 --- a/system/ui/lib/list_view.py +++ b/system/ui/lib/list_view.py @@ -10,7 +10,6 @@ from openpilot.system.ui.lib.wrap_text import wrap_text from openpilot.system.ui.lib.button import gui_button, ButtonStyle from openpilot.system.ui.lib.toggle import Toggle, WIDTH as TOGGLE_WIDTH, HEIGHT as TOGGLE_HEIGHT - ITEM_BASE_HEIGHT = 170 LINE_PADDING = 40 LINE_COLOR = rl.GRAY @@ -31,6 +30,7 @@ BUTTON_FONT_WEIGHT = FontWeight.MEDIUM TEXT_PADDING = 20 + def _resolve_value(value, default=""): return value() if callable(value) else (value or default) @@ -191,7 +191,7 @@ class ListView(Widget): rl.begin_scissor_mode(int(rect.x), int(rect.y), int(rect.width), int(rect.height)) for i, item in enumerate(self._items): - y = int(item.rect.y + scroll_offset.y) + y = int(item.rect.y + scroll_offset.y) if y + item.rect.height <= rect.y or y >= rect.y + rect.height: continue @@ -245,7 +245,7 @@ class ListView(Widget): item_height = item.get_item_height(self._font, content_width) item.rect = rl.Rectangle(container_rect.x, container_rect.y + current_y, container_rect.width, item_height) current_y += item_height - return current_y # total height of all items + return current_y # total height of all items def _handle_mouse_interaction(self, rect: rl.Rectangle, scroll_offset: rl.Vector2): mouse_pos = rl.get_mouse_position() @@ -293,16 +293,19 @@ class ListView(Widget): def simple_item(title: str, callback: Callable | None = None) -> ListItem: return ListItem(title=title, callback=callback) + def toggle_item(title: str, description: str | Callable[[], str] | None = None, initial_state: bool = False, callback: Callable | None = None, icon: str = "", enabled: bool | Callable[[], bool] = True) -> ListItem: action = ToggleAction(initial_state=initial_state, enabled=enabled) return ListItem(title=title, description=description, action_item=action, icon=icon, callback=callback) + def button_item(title: str, button_text: str | Callable[[], str], description: str | Callable[[], str] | None = None, callback: Callable | None = None, enabled: bool | Callable[[], bool] = True) -> ListItem: action = ButtonAction(text=button_text, enabled=enabled) return ListItem(title=title, description=description, action_item=action, callback=callback) + def text_item(title: str, value: str | Callable[[], str], description: str | Callable[[], str] | None = None, callback: Callable | None = None, enabled: bool | Callable[[], bool] = True) -> ListItem: action = TextAction(text=value, color=rl.Color(170, 170, 170, 255), enabled=enabled) diff --git a/system/ui/widgets/confirm_dialog.py b/system/ui/widgets/confirm_dialog.py index 777d0a7a31..88816e3566 100644 --- a/system/ui/widgets/confirm_dialog.py +++ b/system/ui/widgets/confirm_dialog.py @@ -3,7 +3,6 @@ from openpilot.system.ui.lib.application import gui_app, DialogResult, FontWeigh from openpilot.system.ui.lib.button import gui_button, ButtonStyle from openpilot.system.ui.lib.label import gui_text_box - DIALOG_WIDTH = 1520 DIALOG_HEIGHT = 600 BUTTON_HEIGHT = 160 diff --git a/system/ui/widgets/option_dialog.py b/system/ui/widgets/option_dialog.py index 22bdc6ae6f..6dbc24ee37 100644 --- a/system/ui/widgets/option_dialog.py +++ b/system/ui/widgets/option_dialog.py @@ -64,7 +64,7 @@ class MultiOptionDialog(Widget): return 0 if gui_button(rl.Rectangle(content_rect.x + button_w + BUTTON_SPACING, button_y, button_w, BUTTON_HEIGHT), - "Select", is_enabled=self.selection != self.current, button_style=ButtonStyle.PRIMARY): + "Select", is_enabled=self.selection != self.current, button_style=ButtonStyle.PRIMARY): return 1 return -1