From 47d848293b54a6adf83c964120ed74dfbdf58359 Mon Sep 17 00:00:00 2001 From: nayan Date: Sat, 15 Nov 2025 09:28:43 -0500 Subject: [PATCH 01/32] param to control stock vs sp ui --- common/params_keys.h | 1 + 1 file changed, 1 insertion(+) diff --git a/common/params_keys.h b/common/params_keys.h index 38578d7ddc..fe08062987 100644 --- a/common/params_keys.h +++ b/common/params_keys.h @@ -173,6 +173,7 @@ inline static std::unordered_map keys = { {"ShowAdvancedControls", {PERSISTENT | BACKUP, BOOL, "0"}}, {"ShowTurnSignals", {PERSISTENT | BACKUP, BOOL, "0"}}, {"StandstillTimer", {PERSISTENT | BACKUP, BOOL, "0"}}, + {"sunnypilot_ui", {PERSISTENT, BOOL, "1"}}, {"TrueVEgoUI", {PERSISTENT | BACKUP, BOOL, "0"}}, // MADS params From 121b304fe0dcd8bfad02a05aaba6d3e0c9d3029e Mon Sep 17 00:00:00 2001 From: nayan Date: Sat, 15 Nov 2025 09:28:58 -0500 Subject: [PATCH 02/32] init styles --- system/ui/sunnypilot/lib/styles.py | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 system/ui/sunnypilot/lib/styles.py diff --git a/system/ui/sunnypilot/lib/styles.py b/system/ui/sunnypilot/lib/styles.py new file mode 100644 index 0000000000..851a52817d --- /dev/null +++ b/system/ui/sunnypilot/lib/styles.py @@ -0,0 +1,35 @@ +import pyray as rl +from dataclasses import dataclass + +@dataclass +class Default: + # Base Colors + BASE_BG_COLOR = rl.Color(57, 57, 57, 255) # Grey + ON_BG_COLOR = rl.Color(28, 101, 186, 255) # Blue + OFF_BG_COLOR = BASE_BG_COLOR + ON_HOVER_BG_COLOR = rl.Color(17, 78, 150, 255) # Dark Blue + OFF_HOVER_BG_COLOR = rl.Color(21, 21, 21, 255) # Dark gray + DISABLED_ON_BG_COLOR = rl.Color(37, 70, 107, 255) # Dull Blue + DISABLED_OFF_BG_COLOR = rl.Color(39, 39, 39, 255) # Grey + ITEM_TEXT_COLOR = rl.WHITE + ITEM_DISABLED_TEXT_COLOR = rl.Color(88, 88, 88, 255) + ITEM_DESC_TEXT_COLOR = rl.Color(128, 128, 128, 255) + + # Widget/Control Base Dimensions + ITEM_BASE_HEIGHT = 170 + ITEM_PADDING = 20 + ITEM_TEXT_FONT_SIZE = 50 + ITEM_DESC_FONT_SIZE = 40 + ITEM_DESC_V_OFFSET = 150 + + # Toggle Control + TOGGLE_HEIGHT = 100 + TOGGLE_WIDTH = int(TOGGLE_HEIGHT * 1.75) + TOGGLE_BG_HEIGHT = TOGGLE_HEIGHT - 20 + + TOGGLE_ON_COLOR = ON_BG_COLOR + TOGGLE_OFF_COLOR = OFF_BG_COLOR + TOGGLE_KNOB_COLOR = rl.WHITE + TOGGLE_DISABLED_ON_COLOR = DISABLED_ON_BG_COLOR + TOGGLE_DISABLED_OFF_COLOR = DISABLED_OFF_BG_COLOR + TOGGLE_DISABLED_KNOB_COLOR = rl.Color(88, 88, 88, 255) # Lighter Grey From 9c5acf61c047c81fd17bd02e9354225aabf5f7e8 Mon Sep 17 00:00:00 2001 From: nayan Date: Sat, 15 Nov 2025 09:29:07 -0500 Subject: [PATCH 03/32] SP Toggles --- selfdrive/ui/layouts/settings/developer.py | 3 + selfdrive/ui/layouts/settings/toggles.py | 3 + system/ui/sunnypilot/widgets/list_view.py | 97 ++++++++++++++++++++ system/ui/sunnypilot/widgets/toggle.py | 100 +++++++++++++++++++++ 4 files changed, 203 insertions(+) create mode 100644 system/ui/sunnypilot/widgets/list_view.py create mode 100644 system/ui/sunnypilot/widgets/toggle.py diff --git a/selfdrive/ui/layouts/settings/developer.py b/selfdrive/ui/layouts/settings/developer.py index 9ea1019f54..af00d98e73 100644 --- a/selfdrive/ui/layouts/settings/developer.py +++ b/selfdrive/ui/layouts/settings/developer.py @@ -9,6 +9,9 @@ from openpilot.system.ui.lib.application import gui_app from openpilot.system.ui.lib.multilang import tr, tr_noop from openpilot.system.ui.widgets import DialogResult +if Params().get_bool("sunnypilot_ui"): + from openpilot.system.ui.sunnypilot.widgets.list_view import toggle_item_sp as toggle_item + # Description constants DESCRIPTIONS = { 'enable_adb': tr_noop( diff --git a/selfdrive/ui/layouts/settings/toggles.py b/selfdrive/ui/layouts/settings/toggles.py index 3a1265e0fe..06005c5f84 100644 --- a/selfdrive/ui/layouts/settings/toggles.py +++ b/selfdrive/ui/layouts/settings/toggles.py @@ -9,6 +9,9 @@ from openpilot.system.ui.lib.multilang import tr, tr_noop from openpilot.system.ui.widgets import DialogResult from openpilot.selfdrive.ui.ui_state import ui_state +if Params().get_bool("sunnypilot_ui"): + from openpilot.system.ui.sunnypilot.widgets.list_view import toggle_item_sp as toggle_item + PERSONALITY_TO_INT = log.LongitudinalPersonality.schema.enumerants # Description constants diff --git a/system/ui/sunnypilot/widgets/list_view.py b/system/ui/sunnypilot/widgets/list_view.py new file mode 100644 index 0000000000..9d3e973c63 --- /dev/null +++ b/system/ui/sunnypilot/widgets/list_view.py @@ -0,0 +1,97 @@ +import pyray as rl + +from collections.abc import Callable +from openpilot.system.ui.lib.text_measure import measure_text_cached +from openpilot.system.ui.sunnypilot.widgets.toggle import ToggleSP +from openpilot.system.ui.widgets.list_view import ListItem, ToggleAction, ItemAction + + +import openpilot.system.ui.sunnypilot.lib.styles as styles +style = styles.Default + + +class ToggleActionSP(ToggleAction): + def __init__(self, initial_state: bool = False, width: int = style.TOGGLE_WIDTH, enabled: bool | Callable[[], bool] = True, param: str | None = None): + ToggleAction.__init__(self, initial_state, width, enabled) + self.toggle = ToggleSP(initial_state=initial_state, param=param) + +class ListItemSP(ListItem): + def __init__(self, title: str = "", icon: str | None = None, description: str | Callable[[], str] | None = None, + description_visible: bool = False, callback: Callable | None = None, + action_item: ItemAction | None = None): + ListItem.__init__(self, title, icon, description, description_visible, callback, action_item) + + def get_right_item_rect(self, item_rect: rl.Rectangle) -> rl.Rectangle: + if not self.action_item: + return rl.Rectangle(0, 0, 0, 0) + + right_width = self.action_item.rect.width + if right_width == 0: # Full width action (like DualButtonAction) + return rl.Rectangle(item_rect.x + style.ITEM_PADDING, item_rect.y, + item_rect.width - (style.ITEM_PADDING * 2), style.ITEM_BASE_HEIGHT) + + action_width = self.action_item.rect.width + if isinstance(self.action_item, ToggleAction): + action_x = item_rect.x + else: + action_x = item_rect.x + item_rect.width - action_width + action_y = item_rect.y + return rl.Rectangle(action_x, action_y, action_width, style.ITEM_BASE_HEIGHT) + + def _render(self, _): + content_x = self._rect.x + style.ITEM_PADDING + text_x = content_x + left_action_item = isinstance(self.action_item, ToggleAction) + + if left_action_item: + left_rect = rl.Rectangle( + content_x, + self._rect.y + (style.ITEM_BASE_HEIGHT - style.TOGGLE_HEIGHT) // 2, + style.TOGGLE_WIDTH, + style.TOGGLE_HEIGHT + ) + text_x = left_rect.x + left_rect.width + style.ITEM_PADDING + + # Draw title + if self.title: + text_size = measure_text_cached(self._font, self.title, style.ITEM_TEXT_FONT_SIZE) + item_y = self._rect.y + (style.ITEM_BASE_HEIGHT - text_size.y) // 2 + rl.draw_text_ex(self._font, self.title, rl.Vector2(text_x, item_y), style.ITEM_TEXT_FONT_SIZE, 0, style.ITEM_TEXT_COLOR) + + # Render toggle and handle callback + if self.action_item.render(left_rect) and self.action_item.enabled: + if self.callback: + self.callback() + + else: + if self.title: + # Draw main text + text_size = measure_text_cached(self._font, self.title, style.ITEM_TEXT_FONT_SIZE) + item_y = self._rect.y + (style.ITEM_BASE_HEIGHT - text_size.y) // 2 + rl.draw_text_ex(self._font, self.title, rl.Vector2(text_x, item_y), style.ITEM_TEXT_FONT_SIZE, 0, style.ITEM_TEXT_COLOR) + + # Draw right item if present + if self.action_item: + right_rect = self.get_right_item_rect(self._rect) + right_rect.y = self._rect.y + if self.action_item.render(right_rect) and self.action_item.enabled: + # Right item was clicked/activated + if self.callback: + self.callback() + + # Draw description if visible + if self.description_visible: + content_width = int(self._rect.width - style.ITEM_PADDING * 2) + description_height = self._html_renderer.get_total_height(content_width) + description_rect = rl.Rectangle( + self._rect.x + style.ITEM_PADDING, + self._rect.y + style.ITEM_DESC_V_OFFSET, + content_width, + description_height + ) + self._html_renderer.render(description_rect) + +def toggle_item_sp(title: str, description: str | Callable[[], str] | None = None, initial_state: bool = False, + callback: Callable | None = None, icon: str = "", enabled: bool | Callable[[], bool] = True, param: str | None = None) -> ListItem: + action = ToggleActionSP(initial_state=initial_state, enabled=enabled, param=param) + return ListItemSP(title=title, description=description, action_item=action, icon=icon, callback=callback) diff --git a/system/ui/sunnypilot/widgets/toggle.py b/system/ui/sunnypilot/widgets/toggle.py new file mode 100644 index 0000000000..a62e51d758 --- /dev/null +++ b/system/ui/sunnypilot/widgets/toggle.py @@ -0,0 +1,100 @@ +import pyray as rl +from openpilot.common.params import Params +from openpilot.system.ui.lib.application import MousePos +from openpilot.system.ui.widgets.toggle import Toggle +import openpilot.system.ui.sunnypilot.lib.styles as styles + +style = styles.Default + +class ToggleSP(Toggle): + def __init__(self, initial_state=False, param: str | None = None): + self.param_key = param + self.params = Params() + if self.param_key: + initial_state = self.params.get_bool(self.param_key) + Toggle.__init__(self, initial_state) + + def _handle_mouse_release(self, mouse_pos: MousePos): + super()._handle_mouse_release(mouse_pos) + if self._enabled and self.param_key: + self.params.put_bool(self.param_key, self._state) + + def _render(self, rect: rl.Rectangle): + self.update() + if self._enabled: + bg_color = self._blend_color(style.TOGGLE_OFF_COLOR, style.TOGGLE_ON_COLOR, self._progress) + knob_color = style.TOGGLE_KNOB_COLOR + else: + bg_color = self._blend_color(style.TOGGLE_DISABLED_OFF_COLOR, style.TOGGLE_DISABLED_ON_COLOR, self._progress) + knob_color = style.TOGGLE_DISABLED_KNOB_COLOR + + # Draw background + bg_rect = rl.Rectangle(self._rect.x, self._rect.y, style.TOGGLE_WIDTH, style.TOGGLE_BG_HEIGHT) + + # Draw outline first + outline_color = style.TOGGLE_ON_COLOR + if not self._enabled: + # Use a more subtle color for disabled state + outline_color = rl.Color(outline_color.r // 2, outline_color.g // 2, outline_color.b // 2, 255) + + # Draw outline by drawing a slightly larger rounded rectangle behind the background + outline_rect = rl.Rectangle(bg_rect.x - 2, bg_rect.y - 2, bg_rect.width + 4, bg_rect.height + 4) + rl.draw_rectangle_rounded(outline_rect, 1.0, 10, outline_color) + + # Draw actual background + rl.draw_rectangle_rounded(bg_rect, 1.0, 10, bg_color) + + # Draw knob to sit inside the background + knob_padding = 5 + knob_radius = style.TOGGLE_BG_HEIGHT / 2 - knob_padding + + left_edge = bg_rect.x + knob_padding + right_edge = bg_rect.x + bg_rect.width - knob_padding + + knob_travel_distance = right_edge - left_edge - 2 * knob_radius + min_knob_x = left_edge + knob_radius + knob_x = min_knob_x + knob_travel_distance * self._progress + knob_y = self._rect.y + style.TOGGLE_BG_HEIGHT / 2 + + rl.draw_circle(int(knob_x), int(knob_y), knob_radius, knob_color) + + symbol_size = knob_radius / 2 + + if self._state and (self._enabled or self._progress > 0.5): + # Draw checkmark when toggle is ON + start_x = knob_x - symbol_size * 0.8 + start_y = knob_y + mid_x = knob_x - symbol_size * 0.1 + mid_y = knob_y + symbol_size * 0.6 + end_x = knob_x + symbol_size * 0.8 + end_y = knob_y - symbol_size * 0.5 + + rl.draw_line_ex( + rl.Vector2(int(start_x), int(start_y)), + rl.Vector2(int(mid_x), int(mid_y)), + 3, + style.TOGGLE_ON_COLOR + ) + rl.draw_line_ex( + rl.Vector2(int(mid_x), int(mid_y)), + rl.Vector2(int(end_x), int(end_y)), + 3, + style.TOGGLE_ON_COLOR + ) + else: + # Draw X when toggle is OFF + x_size_factor = 0.65 + x_offset = symbol_size * x_size_factor + + rl.draw_line_ex( + rl.Vector2(int(knob_x - x_offset), int(knob_y - x_offset)), + rl.Vector2(int(knob_x + x_offset), int(knob_y + x_offset)), + 3, + style.TOGGLE_OFF_COLOR + ) + rl.draw_line_ex( + rl.Vector2(int(knob_x + x_offset), int(knob_y - x_offset)), + rl.Vector2(int(knob_x - x_offset), int(knob_y + x_offset)), + 3, + style.TOGGLE_OFF_COLOR + ) From 0c37a385967c201d7db6e23ca3506bc21a22d698 Mon Sep 17 00:00:00 2001 From: nayan Date: Sat, 15 Nov 2025 09:42:12 -0500 Subject: [PATCH 04/32] Lint --- system/ui/sunnypilot/widgets/list_view.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/ui/sunnypilot/widgets/list_view.py b/system/ui/sunnypilot/widgets/list_view.py index 9d3e973c63..c7043db531 100644 --- a/system/ui/sunnypilot/widgets/list_view.py +++ b/system/ui/sunnypilot/widgets/list_view.py @@ -16,7 +16,7 @@ class ToggleActionSP(ToggleAction): self.toggle = ToggleSP(initial_state=initial_state, param=param) class ListItemSP(ListItem): - def __init__(self, title: str = "", icon: str | None = None, description: str | Callable[[], str] | None = None, + def __init__(self, title: str | Callable[[], str] = "", icon: str | None = None, description: str | Callable[[], str] | None = None, description_visible: bool = False, callback: Callable | None = None, action_item: ItemAction | None = None): ListItem.__init__(self, title, icon, description, description_visible, callback, action_item) @@ -91,7 +91,7 @@ class ListItemSP(ListItem): ) self._html_renderer.render(description_rect) -def toggle_item_sp(title: str, description: str | Callable[[], str] | None = None, initial_state: bool = False, +def toggle_item_sp(title: str | Callable[[], str], description: str | Callable[[], str] | None = None, initial_state: bool = False, callback: Callable | None = None, icon: str = "", enabled: bool | Callable[[], bool] = True, param: str | None = None) -> ListItem: action = ToggleActionSP(initial_state=initial_state, enabled=enabled, param=param) return ListItemSP(title=title, description=description, action_item=action, icon=icon, callback=callback) From 3946e643f68fdb5784a2b42839162903a5f4a592 Mon Sep 17 00:00:00 2001 From: nayan Date: Sat, 15 Nov 2025 20:24:20 -0500 Subject: [PATCH 05/32] optimizations --- system/ui/sunnypilot/lib/styles.py | 31 +++++++++++--------- system/ui/sunnypilot/widgets/list_view.py | 5 +--- system/ui/sunnypilot/widgets/toggle.py | 35 ++++++++++------------- 3 files changed, 34 insertions(+), 37 deletions(-) diff --git a/system/ui/sunnypilot/lib/styles.py b/system/ui/sunnypilot/lib/styles.py index 851a52817d..28d50f48d7 100644 --- a/system/ui/sunnypilot/lib/styles.py +++ b/system/ui/sunnypilot/lib/styles.py @@ -2,19 +2,7 @@ import pyray as rl from dataclasses import dataclass @dataclass -class Default: - # Base Colors - BASE_BG_COLOR = rl.Color(57, 57, 57, 255) # Grey - ON_BG_COLOR = rl.Color(28, 101, 186, 255) # Blue - OFF_BG_COLOR = BASE_BG_COLOR - ON_HOVER_BG_COLOR = rl.Color(17, 78, 150, 255) # Dark Blue - OFF_HOVER_BG_COLOR = rl.Color(21, 21, 21, 255) # Dark gray - DISABLED_ON_BG_COLOR = rl.Color(37, 70, 107, 255) # Dull Blue - DISABLED_OFF_BG_COLOR = rl.Color(39, 39, 39, 255) # Grey - ITEM_TEXT_COLOR = rl.WHITE - ITEM_DISABLED_TEXT_COLOR = rl.Color(88, 88, 88, 255) - ITEM_DESC_TEXT_COLOR = rl.Color(128, 128, 128, 255) - +class Base: # Widget/Control Base Dimensions ITEM_BASE_HEIGHT = 170 ITEM_PADDING = 20 @@ -27,9 +15,26 @@ class Default: TOGGLE_WIDTH = int(TOGGLE_HEIGHT * 1.75) TOGGLE_BG_HEIGHT = TOGGLE_HEIGHT - 20 +@dataclass +class SP_Default(Base): + # Base Colors + BASE_BG_COLOR = rl.Color(57, 57, 57, 255) # Grey + ON_BG_COLOR = rl.Color(28, 101, 186, 255) # Blue + OFF_BG_COLOR = BASE_BG_COLOR + ON_HOVER_BG_COLOR = rl.Color(17, 78, 150, 255) # Dark Blue + OFF_HOVER_BG_COLOR = rl.Color(21, 21, 21, 255) # Dark gray + DISABLED_ON_BG_COLOR = rl.Color(37, 70, 107, 255) # Dull Blue + DISABLED_OFF_BG_COLOR = rl.Color(39, 39, 39, 255) # Grey + ITEM_TEXT_COLOR = rl.WHITE + ITEM_DISABLED_TEXT_COLOR = rl.Color(88, 88, 88, 255) + ITEM_DESC_TEXT_COLOR = rl.Color(128, 128, 128, 255) + + # Toggle Control TOGGLE_ON_COLOR = ON_BG_COLOR TOGGLE_OFF_COLOR = OFF_BG_COLOR TOGGLE_KNOB_COLOR = rl.WHITE TOGGLE_DISABLED_ON_COLOR = DISABLED_ON_BG_COLOR TOGGLE_DISABLED_OFF_COLOR = DISABLED_OFF_BG_COLOR TOGGLE_DISABLED_KNOB_COLOR = rl.Color(88, 88, 88, 255) # Lighter Grey + +style = SP_Default diff --git a/system/ui/sunnypilot/widgets/list_view.py b/system/ui/sunnypilot/widgets/list_view.py index c7043db531..6020ab71cb 100644 --- a/system/ui/sunnypilot/widgets/list_view.py +++ b/system/ui/sunnypilot/widgets/list_view.py @@ -4,10 +4,7 @@ from collections.abc import Callable from openpilot.system.ui.lib.text_measure import measure_text_cached from openpilot.system.ui.sunnypilot.widgets.toggle import ToggleSP from openpilot.system.ui.widgets.list_view import ListItem, ToggleAction, ItemAction - - -import openpilot.system.ui.sunnypilot.lib.styles as styles -style = styles.Default +from openpilot.system.ui.sunnypilot.lib.styles import style class ToggleActionSP(ToggleAction): diff --git a/system/ui/sunnypilot/widgets/toggle.py b/system/ui/sunnypilot/widgets/toggle.py index a62e51d758..7d3847d3f0 100644 --- a/system/ui/sunnypilot/widgets/toggle.py +++ b/system/ui/sunnypilot/widgets/toggle.py @@ -2,9 +2,11 @@ import pyray as rl from openpilot.common.params import Params from openpilot.system.ui.lib.application import MousePos from openpilot.system.ui.widgets.toggle import Toggle -import openpilot.system.ui.sunnypilot.lib.styles as styles +from openpilot.system.ui.sunnypilot.lib.styles import style -style = styles.Default +KNOB_PADDING = 5 +KNOB_RADIUS = style.TOGGLE_BG_HEIGHT / 2 - KNOB_PADDING +SYMBOL_SIZE = KNOB_RADIUS / 2 class ToggleSP(Toggle): def __init__(self, initial_state=False, param: str | None = None): @@ -44,30 +46,24 @@ class ToggleSP(Toggle): # Draw actual background rl.draw_rectangle_rounded(bg_rect, 1.0, 10, bg_color) - # Draw knob to sit inside the background - knob_padding = 5 - knob_radius = style.TOGGLE_BG_HEIGHT / 2 - knob_padding + left_edge = bg_rect.x + KNOB_PADDING + right_edge = bg_rect.x + bg_rect.width - KNOB_PADDING - left_edge = bg_rect.x + knob_padding - right_edge = bg_rect.x + bg_rect.width - knob_padding - - knob_travel_distance = right_edge - left_edge - 2 * knob_radius - min_knob_x = left_edge + knob_radius + knob_travel_distance = right_edge - left_edge - 2 * KNOB_RADIUS + min_knob_x = left_edge + KNOB_RADIUS knob_x = min_knob_x + knob_travel_distance * self._progress knob_y = self._rect.y + style.TOGGLE_BG_HEIGHT / 2 - rl.draw_circle(int(knob_x), int(knob_y), knob_radius, knob_color) - - symbol_size = knob_radius / 2 + rl.draw_circle(int(knob_x), int(knob_y), KNOB_RADIUS, knob_color) if self._state and (self._enabled or self._progress > 0.5): # Draw checkmark when toggle is ON - start_x = knob_x - symbol_size * 0.8 + start_x = knob_x - SYMBOL_SIZE * 0.8 start_y = knob_y - mid_x = knob_x - symbol_size * 0.1 - mid_y = knob_y + symbol_size * 0.6 - end_x = knob_x + symbol_size * 0.8 - end_y = knob_y - symbol_size * 0.5 + mid_x = knob_x - SYMBOL_SIZE * 0.1 + mid_y = knob_y + SYMBOL_SIZE * 0.6 + end_x = knob_x + SYMBOL_SIZE * 0.8 + end_y = knob_y - SYMBOL_SIZE * 0.5 rl.draw_line_ex( rl.Vector2(int(start_x), int(start_y)), @@ -83,8 +79,7 @@ class ToggleSP(Toggle): ) else: # Draw X when toggle is OFF - x_size_factor = 0.65 - x_offset = symbol_size * x_size_factor + x_offset = SYMBOL_SIZE * 0.65 rl.draw_line_ex( rl.Vector2(int(knob_x - x_offset), int(knob_y - x_offset)), From 4110749cb01bdd48c59725337216e4c5be9c11d3 Mon Sep 17 00:00:00 2001 From: nayan Date: Sat, 15 Nov 2025 11:29:04 -0500 Subject: [PATCH 06/32] Panels. With Icons. And Scroller. --- selfdrive/ui/layouts/main.py | 3 + .../ui/sunnypilot/layouts/settings/cruise.py | 24 +++ .../ui/sunnypilot/layouts/settings/device.py | 5 + .../ui/sunnypilot/layouts/settings/display.py | 24 +++ .../ui/sunnypilot/layouts/settings/models.py | 24 +++ .../sunnypilot/layouts/settings/navigation.py | 24 +++ .../ui/sunnypilot/layouts/settings/osm.py | 24 +++ .../sunnypilot/layouts/settings/settings.py | 189 ++++++++++++++++++ .../sunnypilot/layouts/settings/steering.py | 24 +++ .../sunnypilot/layouts/settings/sunnylink.py | 24 +++ .../ui/sunnypilot/layouts/settings/trips.py | 24 +++ .../ui/sunnypilot/layouts/settings/vehicle.py | 24 +++ .../ui/sunnypilot/layouts/settings/visuals.py | 24 +++ .../assets/offroad/icon_firehose.png | 3 + .../selfdrive/assets/offroad/icon_home.png | 3 + 15 files changed, 443 insertions(+) create mode 100644 selfdrive/ui/sunnypilot/layouts/settings/cruise.py create mode 100644 selfdrive/ui/sunnypilot/layouts/settings/device.py create mode 100644 selfdrive/ui/sunnypilot/layouts/settings/display.py create mode 100644 selfdrive/ui/sunnypilot/layouts/settings/models.py create mode 100644 selfdrive/ui/sunnypilot/layouts/settings/navigation.py create mode 100644 selfdrive/ui/sunnypilot/layouts/settings/osm.py create mode 100644 selfdrive/ui/sunnypilot/layouts/settings/settings.py create mode 100644 selfdrive/ui/sunnypilot/layouts/settings/steering.py create mode 100644 selfdrive/ui/sunnypilot/layouts/settings/sunnylink.py create mode 100644 selfdrive/ui/sunnypilot/layouts/settings/trips.py create mode 100644 selfdrive/ui/sunnypilot/layouts/settings/vehicle.py create mode 100644 selfdrive/ui/sunnypilot/layouts/settings/visuals.py create mode 100644 sunnypilot/selfdrive/assets/offroad/icon_firehose.png create mode 100644 sunnypilot/selfdrive/assets/offroad/icon_home.png diff --git a/selfdrive/ui/layouts/main.py b/selfdrive/ui/layouts/main.py index 702854f98a..e965888fde 100644 --- a/selfdrive/ui/layouts/main.py +++ b/selfdrive/ui/layouts/main.py @@ -10,6 +10,9 @@ from openpilot.selfdrive.ui.ui_state import device, ui_state from openpilot.system.ui.widgets import Widget from openpilot.selfdrive.ui.layouts.onboarding import OnboardingWindow +from openpilot.common.params import Params +if Params().get_bool("sunnypilot_ui"): + from openpilot.selfdrive.ui.sunnypilot.layouts.settings.settings import SettingsLayoutSP as SettingsLayout class MainState(IntEnum): HOME = 0 diff --git a/selfdrive/ui/sunnypilot/layouts/settings/cruise.py b/selfdrive/ui/sunnypilot/layouts/settings/cruise.py new file mode 100644 index 0000000000..b8e2a1344b --- /dev/null +++ b/selfdrive/ui/sunnypilot/layouts/settings/cruise.py @@ -0,0 +1,24 @@ +from openpilot.system.ui.widgets.scroller import Scroller +from openpilot.system.ui.widgets import Widget +from openpilot.common.params import Params + + +class CruiseLayout(Widget): + def __init__(self): + super().__init__() + + self._params = Params() + items = self._initialize_items() + self._scroller = Scroller(items, line_separator=True, spacing=0) + + def _initialize_items(self): + + items = [ + ] + return items + + def _render(self, rect): + self._scroller.render(rect) + + def show_event(self): + self._scroller.show_event() diff --git a/selfdrive/ui/sunnypilot/layouts/settings/device.py b/selfdrive/ui/sunnypilot/layouts/settings/device.py new file mode 100644 index 0000000000..85aa79c8e8 --- /dev/null +++ b/selfdrive/ui/sunnypilot/layouts/settings/device.py @@ -0,0 +1,5 @@ +from openpilot.selfdrive.ui.layouts.settings.device import DeviceLayout + +class DeviceLayoutSP(DeviceLayout): + def __init__(self): + DeviceLayout.__init__(self) diff --git a/selfdrive/ui/sunnypilot/layouts/settings/display.py b/selfdrive/ui/sunnypilot/layouts/settings/display.py new file mode 100644 index 0000000000..1cbea6c9fa --- /dev/null +++ b/selfdrive/ui/sunnypilot/layouts/settings/display.py @@ -0,0 +1,24 @@ +from openpilot.system.ui.widgets.scroller import Scroller +from openpilot.system.ui.widgets import Widget +from openpilot.common.params import Params + + +class DisplayLayout(Widget): + def __init__(self): + super().__init__() + + self._params = Params() + items = self._initialize_items() + self._scroller = Scroller(items, line_separator=True, spacing=0) + + def _initialize_items(self): + items = [ + + ] + return items + + def _render(self, rect): + self._scroller.render(rect) + + def show_event(self): + self._scroller.show_event() diff --git a/selfdrive/ui/sunnypilot/layouts/settings/models.py b/selfdrive/ui/sunnypilot/layouts/settings/models.py new file mode 100644 index 0000000000..1f0107aa9b --- /dev/null +++ b/selfdrive/ui/sunnypilot/layouts/settings/models.py @@ -0,0 +1,24 @@ +from openpilot.system.ui.widgets.scroller import Scroller +from openpilot.system.ui.widgets import Widget +from openpilot.common.params import Params + + +class ModelsLayout(Widget): + def __init__(self): + super().__init__() + + self._params = Params() + items = self._initialize_items() + self._scroller = Scroller(items, line_separator=True, spacing=0) + + def _initialize_items(self): + items = [ + + ] + return items + + def _render(self, rect): + self._scroller.render(rect) + + def show_event(self): + self._scroller.show_event() diff --git a/selfdrive/ui/sunnypilot/layouts/settings/navigation.py b/selfdrive/ui/sunnypilot/layouts/settings/navigation.py new file mode 100644 index 0000000000..eec1367b69 --- /dev/null +++ b/selfdrive/ui/sunnypilot/layouts/settings/navigation.py @@ -0,0 +1,24 @@ +from openpilot.system.ui.widgets.scroller import Scroller +from openpilot.system.ui.widgets import Widget +from openpilot.common.params import Params + + +class NavigationLayout(Widget): + def __init__(self): + super().__init__() + + self._params = Params() + items = self._initialize_items() + self._scroller = Scroller(items, line_separator=True, spacing=0) + + def _initialize_items(self): + items = [ + + ] + return items + + def _render(self, rect): + self._scroller.render(rect) + + def show_event(self): + self._scroller.show_event() diff --git a/selfdrive/ui/sunnypilot/layouts/settings/osm.py b/selfdrive/ui/sunnypilot/layouts/settings/osm.py new file mode 100644 index 0000000000..62f9b6d858 --- /dev/null +++ b/selfdrive/ui/sunnypilot/layouts/settings/osm.py @@ -0,0 +1,24 @@ +from openpilot.system.ui.widgets.scroller import Scroller +from openpilot.system.ui.widgets import Widget +from openpilot.common.params import Params + + +class OSMLayout(Widget): + def __init__(self): + super().__init__() + + self._params = Params() + items = self._initialize_items() + self._scroller = Scroller(items, line_separator=True, spacing=0) + + def _initialize_items(self): + items = [ + + ] + return items + + def _render(self, rect): + self._scroller.render(rect) + + def show_event(self): + self._scroller.show_event() diff --git a/selfdrive/ui/sunnypilot/layouts/settings/settings.py b/selfdrive/ui/sunnypilot/layouts/settings/settings.py new file mode 100644 index 0000000000..adca958ff8 --- /dev/null +++ b/selfdrive/ui/sunnypilot/layouts/settings/settings.py @@ -0,0 +1,189 @@ +import pyray as rl +from dataclasses import dataclass +from enum import IntEnum +from openpilot.selfdrive.ui.layouts.settings import settings as OP +from openpilot.selfdrive.ui.layouts.settings.developer import DeveloperLayout +from openpilot.selfdrive.ui.sunnypilot.layouts.settings.device import DeviceLayoutSP +from openpilot.selfdrive.ui.layouts.settings.firehose import FirehoseLayout +from openpilot.selfdrive.ui.layouts.settings.software import SoftwareLayout +from openpilot.selfdrive.ui.layouts.settings.toggles import TogglesLayout +from openpilot.system.ui.lib.application import gui_app,MousePos +from openpilot.system.ui.lib.multilang import tr_noop +from openpilot.system.ui.widgets.scroller import Scroller +from openpilot.system.ui.lib.text_measure import measure_text_cached +from openpilot.system.ui.widgets.network import NetworkUI +from openpilot.system.ui.lib.wifi_manager import WifiManager +from openpilot.system.ui.widgets import Widget +from openpilot.selfdrive.ui.sunnypilot.layouts.settings.models import ModelsLayout +from openpilot.selfdrive.ui.sunnypilot.layouts.settings.sunnylink import SunnylinkLayout +from openpilot.selfdrive.ui.sunnypilot.layouts.settings.osm import OSMLayout +from openpilot.selfdrive.ui.sunnypilot.layouts.settings.trips import TripsLayout +from openpilot.selfdrive.ui.sunnypilot.layouts.settings.vehicle import VehicleLayout +from openpilot.selfdrive.ui.sunnypilot.layouts.settings.steering import SteeringLayout +from openpilot.selfdrive.ui.sunnypilot.layouts.settings.cruise import CruiseLayout +from openpilot.selfdrive.ui.sunnypilot.layouts.settings.visuals import VisualsLayout +from openpilot.selfdrive.ui.sunnypilot.layouts.settings.display import DisplayLayout +from openpilot.selfdrive.ui.sunnypilot.layouts.settings.navigation import NavigationLayout + +OP.PANEL_COLOR = rl.Color(10, 10, 10, 255) +ICON_SIZE = 70 + +OP.PanelType = IntEnum( # type: ignore + "PanelType", + [es.name for es in OP.PanelType] + [ + "SUNNYLINK", + "MODELS", + "STEERING", + "CRUISE", + "VISUALS", + "DISPLAY", + "OSM", + "NAVIGATION", + "TRIPS", + "VEHICLE", + ], + start=0, + ) + +@dataclass +class PanelInfo(OP.PanelInfo): + icon: str = "" + + +class SettingsLayoutSP(OP.SettingsLayout): + def __init__(self): + OP.SettingsLayout.__init__(self) + self._nav_items: list[Widget] = [] + + # Create sidebar scroller + self._sidebar_scroller = Scroller([], spacing=0, line_separator = False, pad_end=False) + + # Panel configuration + wifi_manager = WifiManager() + wifi_manager.set_active(False) + + self._panels = { + OP.PanelType.DEVICE: PanelInfo(tr_noop("Device"), DeviceLayoutSP(), icon="../../sunnypilot/selfdrive/assets/offroad/icon_home.png"), + OP.PanelType.NETWORK: PanelInfo(tr_noop("Network"), NetworkUI(wifi_manager), icon="icons/network.png"), + OP.PanelType.SUNNYLINK: PanelInfo(tr_noop("sunnylink"), SunnylinkLayout(), icon="icons/shell.png"), + OP.PanelType.TOGGLES: PanelInfo(tr_noop("Toggles"), TogglesLayout(), icon="../../sunnypilot/selfdrive/assets/offroad/icon_toggle.png"), + OP.PanelType.SOFTWARE: PanelInfo(tr_noop("Software"), SoftwareLayout(), icon="../../sunnypilot/selfdrive/assets/offroad/icon_software.png"), + OP.PanelType.MODELS: PanelInfo(tr_noop("Models"), ModelsLayout(), icon="../../sunnypilot/selfdrive/assets/offroad/icon_models.png"), + OP.PanelType.STEERING: PanelInfo(tr_noop("Steering"), SteeringLayout(), icon="../../sunnypilot/selfdrive/assets/offroad/icon_lateral.png"), + OP.PanelType.CRUISE: PanelInfo(tr_noop("Cruise"), CruiseLayout(), icon="icons/speed_limit.png"), + OP.PanelType.VISUALS: PanelInfo(tr_noop("Visuals"), VisualsLayout(), icon="../../sunnypilot/selfdrive/assets/offroad/icon_visuals.png"), + OP.PanelType.DISPLAY: PanelInfo(tr_noop("Display"), DisplayLayout(), icon="../../sunnypilot/selfdrive/assets/offroad/icon_display.png"), + OP.PanelType.OSM: PanelInfo(tr_noop("OSM"), OSMLayout(), icon="../../sunnypilot/selfdrive/assets/offroad/icon_map.png"), + OP.PanelType.NAVIGATION: PanelInfo(tr_noop("Navigation"), NavigationLayout(), icon="../../sunnypilot/selfdrive/assets/offroad/icon_map.png"), + OP.PanelType.TRIPS: PanelInfo(tr_noop("Trips"), TripsLayout(), icon="../../sunnypilot/selfdrive/assets/offroad/icon_trips.png"), + OP.PanelType.VEHICLE: PanelInfo(tr_noop("Vehicle"), VehicleLayout(), icon="../../sunnypilot/selfdrive/assets/offroad/icon_vehicle.png"), + OP.PanelType.FIREHOSE: PanelInfo(tr_noop("Firehose"), FirehoseLayout(), icon="../../sunnypilot/selfdrive/assets/offroad/icon_firehose.png"), + OP.PanelType.DEVELOPER: PanelInfo(tr_noop("Developer"), DeveloperLayout(), icon="icons/shell.png"), + } + + def _create_nav_button(self, panel_type: OP.PanelType, panel_info: PanelInfo) -> Widget: + class NavButton(Widget): + def __init__(self, parent, p_type, p_info): + super().__init__() + self.parent = parent + self.panel_type = p_type + self.panel_info = p_info + + def _render(self, rect): + is_selected = self.panel_type == self.parent._current_panel + text_color = OP.TEXT_SELECTED if is_selected else OP.TEXT_NORMAL + content_x = rect.x + 90 + text_size = measure_text_cached(self.parent._font_medium, self.panel_info.name, 65) + + # Draw background if selected + if is_selected: + self.container_rect = rl.Rectangle( + content_x - 20, rect.y, OP.SIDEBAR_WIDTH - 70, OP.NAV_BTN_HEIGHT + ) + rl.draw_rectangle_rounded(self.container_rect, 0.2, 5, OP.CLOSE_BTN_COLOR) + + if self.panel_info.icon: + icon_texture = gui_app.texture(self.panel_info.icon, ICON_SIZE, ICON_SIZE, keep_aspect_ratio=True) + rl.draw_texture(icon_texture, int(content_x), int(rect.y + (OP.NAV_BTN_HEIGHT - icon_texture.height) / 2), rl.WHITE) + content_x += ICON_SIZE + 20 + + # Draw button text (right-aligned) + text_pos = rl.Vector2( + content_x, + rect.y + (OP.NAV_BTN_HEIGHT - text_size.y) / 2 + ) + rl.draw_text_ex(self.parent._font_medium, self.panel_info.name, text_pos, 55, 0, text_color) + + # Store button rect for click detection + self.panel_info.button_rect = rect + + return NavButton(self, panel_type, panel_info) + + def _draw_sidebar(self, rect: rl.Rectangle): + rl.draw_rectangle_rec(rect, OP.SIDEBAR_COLOR) + + # Close button + close_btn_rect = rl.Rectangle( + rect.x + (rect.width - OP.CLOSE_BTN_SIZE) / 2, rect.y + 60, OP.CLOSE_BTN_SIZE, OP.CLOSE_BTN_SIZE + ) + + pressed = (rl.is_mouse_button_down(rl.MouseButton.MOUSE_BUTTON_LEFT) and + rl.check_collision_point_rec(rl.get_mouse_position(), close_btn_rect)) + close_color = OP.CLOSE_BTN_PRESSED if pressed else OP.CLOSE_BTN_COLOR + rl.draw_rectangle_rounded(close_btn_rect, 1.0, 20, close_color) + + icon_color = rl.Color(255, 255, 255, 255) if not pressed else rl.Color(220, 220, 220, 255) + icon_dest = rl.Rectangle( + close_btn_rect.x + (close_btn_rect.width - self._close_icon.width) / 2, + close_btn_rect.y + (close_btn_rect.height - self._close_icon.height) / 2, + self._close_icon.width, + self._close_icon.height, + ) + rl.draw_texture_pro( + self._close_icon, + rl.Rectangle(0, 0, self._close_icon.width, self._close_icon.height), + icon_dest, + rl.Vector2(0, 0), + 0, + icon_color, + ) + + # Store close button rect for click detection + self._close_btn_rect = close_btn_rect + + # Navigation buttons with scroller + if not self._nav_items: + for panel_type, panel_info in self._panels.items(): + nav_button = self._create_nav_button(panel_type, panel_info) + nav_button.rect.width = rect.width - 100 # Full width minus padding + nav_button.rect.height = OP.NAV_BTN_HEIGHT + self._nav_items.append(nav_button) + self._sidebar_scroller.add_widget(nav_button) + + # Draw navigation section with scroller + nav_rect = rl.Rectangle( + rect.x, + rect.y + 300, # Starting Y position for nav items + rect.width, + rect.height - 300 # Remaining height after close button + ) + + if self._nav_items: + self._sidebar_scroller.render(nav_rect) + return + + + def _handle_mouse_release(self, mouse_pos: MousePos) -> bool: + # Check close button + if rl.check_collision_point_rec(mouse_pos, self._close_btn_rect): + if self._close_callback: + self._close_callback() + return True + + # Check navigation buttons + for panel_type, panel_info in self._panels.items(): + if rl.check_collision_point_rec(mouse_pos, panel_info.button_rect) and self._sidebar_scroller.scroll_panel.is_touch_valid(): + self.set_current_panel(panel_type) + return True + + return False diff --git a/selfdrive/ui/sunnypilot/layouts/settings/steering.py b/selfdrive/ui/sunnypilot/layouts/settings/steering.py new file mode 100644 index 0000000000..f8ae00fcca --- /dev/null +++ b/selfdrive/ui/sunnypilot/layouts/settings/steering.py @@ -0,0 +1,24 @@ +from openpilot.system.ui.widgets.scroller import Scroller +from openpilot.system.ui.widgets import Widget +from openpilot.common.params import Params + + +class SteeringLayout(Widget): + def __init__(self): + super().__init__() + + self._params = Params() + items = self._initialize_items() + self._scroller = Scroller(items, line_separator=True, spacing=0) + + def _initialize_items(self): + items = [ + + ] + return items + + def _render(self, rect): + self._scroller.render(rect) + + def show_event(self): + self._scroller.show_event() diff --git a/selfdrive/ui/sunnypilot/layouts/settings/sunnylink.py b/selfdrive/ui/sunnypilot/layouts/settings/sunnylink.py new file mode 100644 index 0000000000..068679ec67 --- /dev/null +++ b/selfdrive/ui/sunnypilot/layouts/settings/sunnylink.py @@ -0,0 +1,24 @@ +from openpilot.system.ui.widgets.scroller import Scroller +from openpilot.system.ui.widgets import Widget +from openpilot.common.params import Params + + +class SunnylinkLayout(Widget): + def __init__(self): + super().__init__() + + self._params = Params() + items = self._initialize_items() + self._scroller = Scroller(items, line_separator=True, spacing=0) + + def _initialize_items(self): + items = [ + + ] + return items + + def _render(self, rect): + self._scroller.render(rect) + + def show_event(self): + self._scroller.show_event() diff --git a/selfdrive/ui/sunnypilot/layouts/settings/trips.py b/selfdrive/ui/sunnypilot/layouts/settings/trips.py new file mode 100644 index 0000000000..091bd8f987 --- /dev/null +++ b/selfdrive/ui/sunnypilot/layouts/settings/trips.py @@ -0,0 +1,24 @@ +from openpilot.system.ui.widgets.scroller import Scroller +from openpilot.system.ui.widgets import Widget +from openpilot.common.params import Params + + +class TripsLayout(Widget): + def __init__(self): + super().__init__() + + self._params = Params() + items = self._initialize_items() + self._scroller = Scroller(items, line_separator=True, spacing=0) + + def _initialize_items(self): + items = [ + + ] + return items + + def _render(self, rect): + self._scroller.render(rect) + + def show_event(self): + self._scroller.show_event() diff --git a/selfdrive/ui/sunnypilot/layouts/settings/vehicle.py b/selfdrive/ui/sunnypilot/layouts/settings/vehicle.py new file mode 100644 index 0000000000..7d7a6f5fe8 --- /dev/null +++ b/selfdrive/ui/sunnypilot/layouts/settings/vehicle.py @@ -0,0 +1,24 @@ +from openpilot.system.ui.widgets.scroller import Scroller +from openpilot.system.ui.widgets import Widget +from openpilot.common.params import Params + + +class VehicleLayout(Widget): + def __init__(self): + super().__init__() + + self._params = Params() + items = self._initialize_items() + self._scroller = Scroller(items, line_separator=True, spacing=0) + + def _initialize_items(self): + items = [ + + ] + return items + + def _render(self, rect): + self._scroller.render(rect) + + def show_event(self): + self._scroller.show_event() diff --git a/selfdrive/ui/sunnypilot/layouts/settings/visuals.py b/selfdrive/ui/sunnypilot/layouts/settings/visuals.py new file mode 100644 index 0000000000..dba68c912f --- /dev/null +++ b/selfdrive/ui/sunnypilot/layouts/settings/visuals.py @@ -0,0 +1,24 @@ +from openpilot.system.ui.widgets.scroller import Scroller +from openpilot.system.ui.widgets import Widget +from openpilot.common.params import Params + + +class VisualsLayout(Widget): + def __init__(self): + super().__init__() + + self._params = Params() + items = self._initialize_items() + self._scroller = Scroller(items, line_separator=True, spacing=0) + + def _initialize_items(self): + items = [ + + ] + return items + + def _render(self, rect): + self._scroller.render(rect) + + def show_event(self): + self._scroller.show_event() diff --git a/sunnypilot/selfdrive/assets/offroad/icon_firehose.png b/sunnypilot/selfdrive/assets/offroad/icon_firehose.png new file mode 100644 index 0000000000..d579937f3f --- /dev/null +++ b/sunnypilot/selfdrive/assets/offroad/icon_firehose.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a258a022f0ab90368327d899ed4fb85b47dd0e35c93508e35851d9c3184528c0 +size 36382 diff --git a/sunnypilot/selfdrive/assets/offroad/icon_home.png b/sunnypilot/selfdrive/assets/offroad/icon_home.png new file mode 100644 index 0000000000..1229af846d --- /dev/null +++ b/sunnypilot/selfdrive/assets/offroad/icon_home.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8623dbc5c7dd043a91d98777cb423cfd116014ed6390af6d7d00c1f8dea3c6e8 +size 1181 From deda1329a2df3bc5fcab503d000956e37f67f85e Mon Sep 17 00:00:00 2001 From: nayan Date: Sat, 15 Nov 2025 21:36:22 -0500 Subject: [PATCH 07/32] patience, grasshopper --- selfdrive/ui/sunnypilot/layouts/settings/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selfdrive/ui/sunnypilot/layouts/settings/settings.py b/selfdrive/ui/sunnypilot/layouts/settings/settings.py index adca958ff8..329608d577 100644 --- a/selfdrive/ui/sunnypilot/layouts/settings/settings.py +++ b/selfdrive/ui/sunnypilot/layouts/settings/settings.py @@ -74,7 +74,7 @@ class SettingsLayoutSP(OP.SettingsLayout): OP.PanelType.VISUALS: PanelInfo(tr_noop("Visuals"), VisualsLayout(), icon="../../sunnypilot/selfdrive/assets/offroad/icon_visuals.png"), OP.PanelType.DISPLAY: PanelInfo(tr_noop("Display"), DisplayLayout(), icon="../../sunnypilot/selfdrive/assets/offroad/icon_display.png"), OP.PanelType.OSM: PanelInfo(tr_noop("OSM"), OSMLayout(), icon="../../sunnypilot/selfdrive/assets/offroad/icon_map.png"), - OP.PanelType.NAVIGATION: PanelInfo(tr_noop("Navigation"), NavigationLayout(), icon="../../sunnypilot/selfdrive/assets/offroad/icon_map.png"), + #OP.PanelType.NAVIGATION: PanelInfo(tr_noop("Navigation"), NavigationLayout(), icon="../../sunnypilot/selfdrive/assets/offroad/icon_map.png"), OP.PanelType.TRIPS: PanelInfo(tr_noop("Trips"), TripsLayout(), icon="../../sunnypilot/selfdrive/assets/offroad/icon_trips.png"), OP.PanelType.VEHICLE: PanelInfo(tr_noop("Vehicle"), VehicleLayout(), icon="../../sunnypilot/selfdrive/assets/offroad/icon_vehicle.png"), OP.PanelType.FIREHOSE: PanelInfo(tr_noop("Firehose"), FirehoseLayout(), icon="../../sunnypilot/selfdrive/assets/offroad/icon_firehose.png"), From 51d0666c85a801b2731d120dd7c098aae2f4f9ea Mon Sep 17 00:00:00 2001 From: nayan Date: Sat, 15 Nov 2025 22:49:39 -0500 Subject: [PATCH 08/32] more patience, grasshopper --- selfdrive/ui/sunnypilot/layouts/settings/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selfdrive/ui/sunnypilot/layouts/settings/settings.py b/selfdrive/ui/sunnypilot/layouts/settings/settings.py index 329608d577..6bf8218bf0 100644 --- a/selfdrive/ui/sunnypilot/layouts/settings/settings.py +++ b/selfdrive/ui/sunnypilot/layouts/settings/settings.py @@ -23,7 +23,7 @@ from openpilot.selfdrive.ui.sunnypilot.layouts.settings.steering import Steering from openpilot.selfdrive.ui.sunnypilot.layouts.settings.cruise import CruiseLayout from openpilot.selfdrive.ui.sunnypilot.layouts.settings.visuals import VisualsLayout from openpilot.selfdrive.ui.sunnypilot.layouts.settings.display import DisplayLayout -from openpilot.selfdrive.ui.sunnypilot.layouts.settings.navigation import NavigationLayout +#from openpilot.selfdrive.ui.sunnypilot.layouts.settings.navigation import NavigationLayout OP.PANEL_COLOR = rl.Color(10, 10, 10, 255) ICON_SIZE = 70 From 362e9ce04becc1ef1d16d2f23daa01cb2d5303c4 Mon Sep 17 00:00:00 2001 From: nayan Date: Sun, 16 Nov 2025 09:53:28 -0500 Subject: [PATCH 09/32] sp raylib preview --- selfdrive/ui/tests/test_ui/raylib_screenshots.py | 1 + 1 file changed, 1 insertion(+) diff --git a/selfdrive/ui/tests/test_ui/raylib_screenshots.py b/selfdrive/ui/tests/test_ui/raylib_screenshots.py index f36ad1badb..009c940d1e 100755 --- a/selfdrive/ui/tests/test_ui/raylib_screenshots.py +++ b/selfdrive/ui/tests/test_ui/raylib_screenshots.py @@ -292,6 +292,7 @@ def create_screenshots(): with OpenpilotPrefix(): params = Params() params.put("DongleId", "123456789012345") + params.put_bool("sunnypilot_ui", True) # Set branch name params.put("UpdaterCurrentDescription", VERSION) From e4e10d4b87d0bdf4fe2e766122935e5ee3706a5b Mon Sep 17 00:00:00 2001 From: nayan Date: Sun, 16 Nov 2025 11:15:22 -0500 Subject: [PATCH 10/32] fix callback --- system/ui/sunnypilot/widgets/list_view.py | 9 +++++---- system/ui/sunnypilot/widgets/toggle.py | 5 +++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/system/ui/sunnypilot/widgets/list_view.py b/system/ui/sunnypilot/widgets/list_view.py index 6020ab71cb..2260a0ba4c 100644 --- a/system/ui/sunnypilot/widgets/list_view.py +++ b/system/ui/sunnypilot/widgets/list_view.py @@ -8,9 +8,10 @@ from openpilot.system.ui.sunnypilot.lib.styles import style class ToggleActionSP(ToggleAction): - def __init__(self, initial_state: bool = False, width: int = style.TOGGLE_WIDTH, enabled: bool | Callable[[], bool] = True, param: str | None = None): - ToggleAction.__init__(self, initial_state, width, enabled) - self.toggle = ToggleSP(initial_state=initial_state, param=param) + def __init__(self, initial_state: bool = False, width: int = style.TOGGLE_WIDTH, enabled: bool | Callable[[], bool] = True, + callback: Callable[[bool], None] | None = None, param: str | None = None): + ToggleAction.__init__(self, initial_state, width, enabled, callback) + self.toggle = ToggleSP(initial_state=initial_state, callback=callback, param=param) class ListItemSP(ListItem): def __init__(self, title: str | Callable[[], str] = "", icon: str | None = None, description: str | Callable[[], str] | None = None, @@ -90,5 +91,5 @@ class ListItemSP(ListItem): def toggle_item_sp(title: str | Callable[[], str], description: str | Callable[[], str] | None = None, initial_state: bool = False, callback: Callable | None = None, icon: str = "", enabled: bool | Callable[[], bool] = True, param: str | None = None) -> ListItem: - action = ToggleActionSP(initial_state=initial_state, enabled=enabled, param=param) + action = ToggleActionSP(initial_state=initial_state, enabled=enabled, callback=callback, param=param) return ListItemSP(title=title, description=description, action_item=action, icon=icon, callback=callback) diff --git a/system/ui/sunnypilot/widgets/toggle.py b/system/ui/sunnypilot/widgets/toggle.py index 7d3847d3f0..84e3f9b4f2 100644 --- a/system/ui/sunnypilot/widgets/toggle.py +++ b/system/ui/sunnypilot/widgets/toggle.py @@ -1,4 +1,5 @@ import pyray as rl +from collections.abc import Callable from openpilot.common.params import Params from openpilot.system.ui.lib.application import MousePos from openpilot.system.ui.widgets.toggle import Toggle @@ -9,12 +10,12 @@ KNOB_RADIUS = style.TOGGLE_BG_HEIGHT / 2 - KNOB_PADDING SYMBOL_SIZE = KNOB_RADIUS / 2 class ToggleSP(Toggle): - def __init__(self, initial_state=False, param: str | None = None): + def __init__(self, initial_state=False, callback: Callable[[bool], None] | None = None, param: str | None = None): self.param_key = param self.params = Params() if self.param_key: initial_state = self.params.get_bool(self.param_key) - Toggle.__init__(self, initial_state) + Toggle.__init__(self, initial_state, callback) def _handle_mouse_release(self, mouse_pos: MousePos): super()._handle_mouse_release(mouse_pos) From 423a7d2ed0249e12743c2b36e1053d5a446f8d33 Mon Sep 17 00:00:00 2001 From: nayan Date: Sun, 16 Nov 2025 11:15:28 -0500 Subject: [PATCH 11/32] fix ui preview --- selfdrive/ui/tests/test_ui/raylib_screenshots.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selfdrive/ui/tests/test_ui/raylib_screenshots.py b/selfdrive/ui/tests/test_ui/raylib_screenshots.py index 009c940d1e..a26c27bcb9 100755 --- a/selfdrive/ui/tests/test_ui/raylib_screenshots.py +++ b/selfdrive/ui/tests/test_ui/raylib_screenshots.py @@ -148,7 +148,7 @@ def setup_experimental_mode_description(click, pm: PubMaster): def setup_openpilot_long_confirmation_dialog(click, pm: PubMaster): setup_settings_developer(click, pm) - click(2000, 960) # toggle openpilot longitudinal control + click(650, 960) # toggle openpilot longitudinal control def setup_onroad(click, pm: PubMaster): From a9e57f0a769f97f985fcf6fa5a468da4ff05d2d1 Mon Sep 17 00:00:00 2001 From: nayan Date: Sun, 16 Nov 2025 12:47:37 -0500 Subject: [PATCH 12/32] add ui previews --- .../ui/tests/test_ui/raylib_screenshots.py | 138 +++++++++++++----- 1 file changed, 99 insertions(+), 39 deletions(-) diff --git a/selfdrive/ui/tests/test_ui/raylib_screenshots.py b/selfdrive/ui/tests/test_ui/raylib_screenshots.py index a26c27bcb9..673d3d4947 100755 --- a/selfdrive/ui/tests/test_ui/raylib_screenshots.py +++ b/selfdrive/ui/tests/test_ui/raylib_screenshots.py @@ -40,47 +40,47 @@ def put_update_params(params: Params): params.put("UpdaterTargetBranch", BRANCH_NAME) -def setup_homescreen(click, pm: PubMaster): +def setup_homescreen(click, pm: PubMaster, scroll=None): pass -def setup_homescreen_update_available(click, pm: PubMaster): +def setup_homescreen_update_available(click, pm: PubMaster, scroll=None): params = Params() params.put_bool("UpdateAvailable", True) put_update_params(params) setup_offroad_alert(click, pm) -def setup_settings(click, pm: PubMaster): +def setup_settings(click, pm: PubMaster, scroll=None): click(100, 100) -def close_settings(click, pm: PubMaster): +def close_settings(click, pm: PubMaster, scroll=None): click(240, 216) -def setup_settings_network(click, pm: PubMaster): +def setup_settings_network(click, pm: PubMaster, scroll=None): setup_settings(click, pm) click(278, 450) -def setup_settings_network_advanced(click, pm: PubMaster): - setup_settings_network(click, pm) +def setup_settings_network_advanced(click, pm: PubMaster, scroll=None): + setup_settings_network(click, pm, scroll=scroll) click(1880, 100) -def setup_settings_toggles(click, pm: PubMaster): - setup_settings(click, pm) - click(278, 600) - - -def setup_settings_software(click, pm: PubMaster): - put_update_params(Params()) +def setup_settings_toggles(click, pm: PubMaster, scroll=None): setup_settings(click, pm) click(278, 720) -def setup_settings_software_download(click, pm: PubMaster): +def setup_settings_software(click, pm: PubMaster, scroll=None): + put_update_params(Params()) + setup_settings(click, pm) + click(278, 845) + + +def setup_settings_software_download(click, pm: PubMaster, scroll=None): params = Params() # setup_settings_software but with "DOWNLOAD" button to test long text params.put("UpdaterState", "idle") @@ -88,13 +88,13 @@ def setup_settings_software_download(click, pm: PubMaster): setup_settings_software(click, pm) -def setup_settings_software_release_notes(click, pm: PubMaster): - setup_settings_software(click, pm) +def setup_settings_software_release_notes(click, pm: PubMaster, scroll=None): + setup_settings_software(click, pm, scroll=scroll) click(588, 110) # expand description for current version -def setup_settings_software_branch_switcher(click, pm: PubMaster): - setup_settings_software(click, pm) +def setup_settings_software_branch_switcher(click, pm: PubMaster, scroll=None): + setup_settings_software(click, pm, scroll=scroll) params = Params() params.put("UpdaterAvailableBranches", f"master,nightly,release,{BRANCH_NAME}") params.put("GitBranch", BRANCH_NAME) # should be on top @@ -102,30 +102,32 @@ def setup_settings_software_branch_switcher(click, pm: PubMaster): click(1984, 449) -def setup_settings_firehose(click, pm: PubMaster): +def setup_settings_firehose(click, pm: PubMaster, scroll=None): setup_settings(click, pm) - click(278, 845) + scroll(-1000, 278, 950) + click(278, 950) -def setup_settings_developer(click, pm: PubMaster): +def setup_settings_developer(click, pm: PubMaster, scroll=None): CP = car.CarParams() CP.alphaLongitudinalAvailable = True # show alpha long control toggle Params().put("CarParamsPersistent", CP.to_bytes()) setup_settings(click, pm) - click(278, 950) + scroll(-1000, 278, 950) + click(278, 1040) -def setup_keyboard(click, pm: PubMaster): - setup_settings_developer(click, pm) +def setup_keyboard(click, pm: PubMaster, scroll=None): + setup_settings_developer(click, pm, scroll=scroll) click(1930, 470) -def setup_pair_device(click, pm: PubMaster): +def setup_pair_device(click, pm: PubMaster, scroll=None): click(1950, 800) -def setup_offroad_alert(click, pm: PubMaster): +def setup_offroad_alert(click, pm: PubMaster, scroll=None): put_update_params(Params()) set_offroad_alert("Offroad_TemperatureTooHigh", True, extra_text='99C') set_offroad_alert("Offroad_ExcessiveActuation", True, extra_text='longitudinal') @@ -136,22 +138,63 @@ def setup_offroad_alert(click, pm: PubMaster): close_settings(click, pm) -def setup_confirmation_dialog(click, pm: PubMaster): +def setup_confirmation_dialog(click, pm: PubMaster, scroll=None): setup_settings(click, pm) click(1985, 791) # reset calibration -def setup_experimental_mode_description(click, pm: PubMaster): +def setup_experimental_mode_description(click, pm: PubMaster, scroll=None): setup_settings_toggles(click, pm) click(1200, 280) # expand description for experimental mode -def setup_openpilot_long_confirmation_dialog(click, pm: PubMaster): - setup_settings_developer(click, pm) +def setup_openpilot_long_confirmation_dialog(click, pm: PubMaster, scroll=None): + setup_settings_developer(click, pm, scroll=scroll) click(650, 960) # toggle openpilot longitudinal control +def setup_settings_sunnylink(click, pm: PubMaster, scroll=None): + setup_settings(click, pm) + click(278, 600) -def setup_onroad(click, pm: PubMaster): +def setup_settings_models(click, pm: PubMaster, scroll=None): + setup_settings(click, pm) + click(278, 950) + +def setup_settings_steering(click, pm: PubMaster, scroll=None): + setup_settings(click, pm) + click(278, 1040) + +def setup_settings_cruise(click, pm: PubMaster, scroll=None): + setup_settings(click, pm) + scroll(-40, 278, 950) + click(278, 1040) + +def setup_settings_visuals(click, pm: PubMaster, scroll=None): + setup_settings(click, pm) + scroll(-1000, 278, 950) + click(278, 330) + +def setup_settings_display(click, pm: PubMaster, scroll=None): + setup_settings(click, pm) + scroll(-1000, 278, 950) + click(278, 450) + +def setup_settings_osm(click, pm: PubMaster, scroll=None): + setup_settings(click, pm) + scroll(-1000, 278, 950) + click(278, 600) + +def setup_settings_trips(click, pm: PubMaster, scroll=None): + setup_settings(click, pm) + scroll(-1000, 278, 950) + click(278, 720) + +def setup_settings_vehicle(click, pm: PubMaster, scroll=None): + setup_settings(click, pm) + scroll(-1000, 278, 950) + click(278, 845) + +def setup_onroad(click, pm: PubMaster, scroll=None): ds = messaging.new_message('deviceState') ds.deviceState.started = True @@ -172,7 +215,7 @@ def setup_onroad(click, pm: PubMaster): time.sleep(0.05) -def setup_onroad_sidebar(click, pm: PubMaster): +def setup_onroad_sidebar(click, pm: PubMaster, scroll=None): setup_onroad(click, pm) click(100, 100) # open sidebar @@ -191,23 +234,23 @@ def setup_onroad_alert(click, pm: PubMaster, size: log.SelfdriveState.AlertSize, time.sleep(0.05) -def setup_onroad_small_alert(click, pm: PubMaster): +def setup_onroad_small_alert(click, pm: PubMaster, scroll=None): setup_onroad_alert(click, pm, AlertSize.small, "Small Alert", "This is a small alert", AlertStatus.normal) -def setup_onroad_medium_alert(click, pm: PubMaster): +def setup_onroad_medium_alert(click, pm: PubMaster, scroll=None): setup_onroad_alert(click, pm, AlertSize.mid, "Medium Alert", "This is a medium alert", AlertStatus.userPrompt) -def setup_onroad_full_alert(click, pm: PubMaster): +def setup_onroad_full_alert(click, pm: PubMaster, scroll=None): setup_onroad_alert(click, pm, AlertSize.full, "DISENGAGE IMMEDIATELY", "Driver Distracted", AlertStatus.critical) -def setup_onroad_full_alert_multiline(click, pm: PubMaster): +def setup_onroad_full_alert_multiline(click, pm: PubMaster, scroll=None): setup_onroad_alert(click, pm, AlertSize.full, "Reverse\nGear", "", AlertStatus.normal) -def setup_onroad_full_alert_long_text(click, pm: PubMaster): +def setup_onroad_full_alert_long_text(click, pm: PubMaster, scroll=None): setup_onroad_alert(click, pm, AlertSize.full, "TAKE CONTROL IMMEDIATELY", "Calibration Invalid: Remount Device & Recalibrate", AlertStatus.userPrompt) @@ -242,6 +285,19 @@ CASES = { "onroad_full_alert_long_text": setup_onroad_full_alert_long_text, } +# sunnypilot cases +CASES.update({ + "settings_sunnylink": setup_settings_sunnylink, + "settings_models": setup_settings_models, + "settings_steering": setup_settings_steering, + "settings_cruise": setup_settings_cruise, + "settings_visuals": setup_settings_visuals, + "settings_display": setup_settings_display, + "settings_osm": setup_settings_osm, + "settings_trips": setup_settings_trips, + "settings_vehicle": setup_settings_vehicle, +}) + class TestUI: def __init__(self): @@ -274,11 +330,15 @@ class TestUI: time.sleep(0.01) pyautogui.mouseUp(self.ui.left + x, self.ui.top + y, *args, **kwargs) + def scroll(self, clicks, x, y, *args, **kwargs): + pyautogui.scroll(clicks, self.ui.left + x, self.ui.top + y, *args, **kwargs) + time.sleep(UI_DELAY) + @with_processes(["ui"]) def test_ui(self, name, setup_case): self.setup() time.sleep(UI_DELAY) # wait for UI to start - setup_case(self.click, self.pm) + setup_case(self.click, self.pm, self.scroll) self.screenshot(name) From eb94abaa14a355d65a281b7225180c144677d5fd Mon Sep 17 00:00:00 2001 From: nayan Date: Wed, 19 Nov 2025 23:44:05 -0500 Subject: [PATCH 13/32] better padding --- system/ui/sunnypilot/lib/styles.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/ui/sunnypilot/lib/styles.py b/system/ui/sunnypilot/lib/styles.py index 28d50f48d7..2c694a1f38 100644 --- a/system/ui/sunnypilot/lib/styles.py +++ b/system/ui/sunnypilot/lib/styles.py @@ -5,7 +5,7 @@ from dataclasses import dataclass class Base: # Widget/Control Base Dimensions ITEM_BASE_HEIGHT = 170 - ITEM_PADDING = 20 + ITEM_PADDING = 30 ITEM_TEXT_FONT_SIZE = 50 ITEM_DESC_FONT_SIZE = 40 ITEM_DESC_V_OFFSET = 150 From 1e0564b4844acafbb733bfb7ae55b4ed0c93dd07 Mon Sep 17 00:00:00 2001 From: nayan Date: Thu, 20 Nov 2025 08:05:20 -0500 Subject: [PATCH 14/32] this --- system/ui/sunnypilot/lib/styles.py | 2 +- system/ui/sunnypilot/widgets/list_view.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/system/ui/sunnypilot/lib/styles.py b/system/ui/sunnypilot/lib/styles.py index 2c694a1f38..28d50f48d7 100644 --- a/system/ui/sunnypilot/lib/styles.py +++ b/system/ui/sunnypilot/lib/styles.py @@ -5,7 +5,7 @@ from dataclasses import dataclass class Base: # Widget/Control Base Dimensions ITEM_BASE_HEIGHT = 170 - ITEM_PADDING = 30 + ITEM_PADDING = 20 ITEM_TEXT_FONT_SIZE = 50 ITEM_DESC_FONT_SIZE = 40 ITEM_DESC_V_OFFSET = 150 diff --git a/system/ui/sunnypilot/widgets/list_view.py b/system/ui/sunnypilot/widgets/list_view.py index 2260a0ba4c..7e118f7506 100644 --- a/system/ui/sunnypilot/widgets/list_view.py +++ b/system/ui/sunnypilot/widgets/list_view.py @@ -48,7 +48,7 @@ class ListItemSP(ListItem): style.TOGGLE_WIDTH, style.TOGGLE_HEIGHT ) - text_x = left_rect.x + left_rect.width + style.ITEM_PADDING + text_x = left_rect.x + left_rect.width + style.ITEM_PADDING * 1.5 # Draw title if self.title: From 5b03369a8f1f3450a82097da369302bdddf10fc9 Mon Sep 17 00:00:00 2001 From: nayan Date: Thu, 20 Nov 2025 17:56:26 -0500 Subject: [PATCH 15/32] listitem -> listitemsp --- system/ui/sunnypilot/widgets/list_view.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/ui/sunnypilot/widgets/list_view.py b/system/ui/sunnypilot/widgets/list_view.py index 7e118f7506..219118298e 100644 --- a/system/ui/sunnypilot/widgets/list_view.py +++ b/system/ui/sunnypilot/widgets/list_view.py @@ -90,6 +90,6 @@ class ListItemSP(ListItem): self._html_renderer.render(description_rect) def toggle_item_sp(title: str | Callable[[], str], description: str | Callable[[], str] | None = None, initial_state: bool = False, - callback: Callable | None = None, icon: str = "", enabled: bool | Callable[[], bool] = True, param: str | None = None) -> ListItem: + callback: Callable | None = None, icon: str = "", enabled: bool | Callable[[], bool] = True, param: str | None = None) -> ListItemSP: action = ToggleActionSP(initial_state=initial_state, enabled=enabled, callback=callback, param=param) return ListItemSP(title=title, description=description, action_item=action, icon=icon, callback=callback) From 7032e4a9727783136c14c7c38ea11092e25a19be Mon Sep 17 00:00:00 2001 From: nayan Date: Thu, 20 Nov 2025 18:00:44 -0500 Subject: [PATCH 16/32] add show_description method --- system/ui/sunnypilot/widgets/list_view.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/system/ui/sunnypilot/widgets/list_view.py b/system/ui/sunnypilot/widgets/list_view.py index 219118298e..86dbde2797 100644 --- a/system/ui/sunnypilot/widgets/list_view.py +++ b/system/ui/sunnypilot/widgets/list_view.py @@ -19,6 +19,9 @@ class ListItemSP(ListItem): action_item: ItemAction | None = None): ListItem.__init__(self, title, icon, description, description_visible, callback, action_item) + def show_description(self, show: bool): + self._set_description_visible(show) + def get_right_item_rect(self, item_rect: rl.Rectangle) -> rl.Rectangle: if not self.action_item: return rl.Rectangle(0, 0, 0, 0) From e6f5aae2464cea37804eeef87c0aa7793bc6fa89 Mon Sep 17 00:00:00 2001 From: nayan Date: Thu, 20 Nov 2025 18:05:12 -0500 Subject: [PATCH 17/32] =?UTF-8?q?remove=20padding=20from=20line=20separato?= =?UTF-8?q?r.=20like,=20WHY=3F=20=F0=9F=98=A9=F0=9F=98=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- system/ui/widgets/scroller.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/ui/widgets/scroller.py b/system/ui/widgets/scroller.py index a843010d56..eec75c8592 100644 --- a/system/ui/widgets/scroller.py +++ b/system/ui/widgets/scroller.py @@ -17,8 +17,8 @@ class LineSeparator(Widget): self._rect.width = parent_rect.width def _render(self, _): - rl.draw_line(int(self._rect.x) + LINE_PADDING, int(self._rect.y), - int(self._rect.x + self._rect.width) - LINE_PADDING, int(self._rect.y), + rl.draw_line(int(self._rect.x), int(self._rect.y), + int(self._rect.x + self._rect.width), int(self._rect.y), LINE_COLOR) From 2717d9735017409be0a77d936d5853fb16b39f19 Mon Sep 17 00:00:00 2001 From: nayan Date: Fri, 21 Nov 2025 15:20:31 -0500 Subject: [PATCH 18/32] scroller -> scroller_tici --- selfdrive/ui/sunnypilot/layouts/settings/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selfdrive/ui/sunnypilot/layouts/settings/settings.py b/selfdrive/ui/sunnypilot/layouts/settings/settings.py index 6bf8218bf0..7460219530 100644 --- a/selfdrive/ui/sunnypilot/layouts/settings/settings.py +++ b/selfdrive/ui/sunnypilot/layouts/settings/settings.py @@ -9,7 +9,7 @@ from openpilot.selfdrive.ui.layouts.settings.software import SoftwareLayout from openpilot.selfdrive.ui.layouts.settings.toggles import TogglesLayout from openpilot.system.ui.lib.application import gui_app,MousePos from openpilot.system.ui.lib.multilang import tr_noop -from openpilot.system.ui.widgets.scroller import Scroller +from openpilot.system.ui.widgets.scroller_tici import Scroller from openpilot.system.ui.lib.text_measure import measure_text_cached from openpilot.system.ui.widgets.network import NetworkUI from openpilot.system.ui.lib.wifi_manager import WifiManager From 48d33e98e7d4cbc4b616a58faa8a70bb883eb714 Mon Sep 17 00:00:00 2001 From: nayan Date: Fri, 21 Nov 2025 15:27:51 -0500 Subject: [PATCH 19/32] scroller -> scroller_tici --- selfdrive/ui/sunnypilot/layouts/settings/cruise.py | 2 +- selfdrive/ui/sunnypilot/layouts/settings/display.py | 2 +- selfdrive/ui/sunnypilot/layouts/settings/models.py | 2 +- selfdrive/ui/sunnypilot/layouts/settings/navigation.py | 2 +- selfdrive/ui/sunnypilot/layouts/settings/osm.py | 2 +- selfdrive/ui/sunnypilot/layouts/settings/steering.py | 2 +- selfdrive/ui/sunnypilot/layouts/settings/sunnylink.py | 2 +- selfdrive/ui/sunnypilot/layouts/settings/trips.py | 2 +- selfdrive/ui/sunnypilot/layouts/settings/vehicle.py | 2 +- selfdrive/ui/sunnypilot/layouts/settings/visuals.py | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/selfdrive/ui/sunnypilot/layouts/settings/cruise.py b/selfdrive/ui/sunnypilot/layouts/settings/cruise.py index b8e2a1344b..049f0e0de4 100644 --- a/selfdrive/ui/sunnypilot/layouts/settings/cruise.py +++ b/selfdrive/ui/sunnypilot/layouts/settings/cruise.py @@ -1,4 +1,4 @@ -from openpilot.system.ui.widgets.scroller import Scroller +from openpilot.system.ui.widgets.scroller_tici import Scroller from openpilot.system.ui.widgets import Widget from openpilot.common.params import Params diff --git a/selfdrive/ui/sunnypilot/layouts/settings/display.py b/selfdrive/ui/sunnypilot/layouts/settings/display.py index 1cbea6c9fa..706410dbfa 100644 --- a/selfdrive/ui/sunnypilot/layouts/settings/display.py +++ b/selfdrive/ui/sunnypilot/layouts/settings/display.py @@ -1,4 +1,4 @@ -from openpilot.system.ui.widgets.scroller import Scroller +from openpilot.system.ui.widgets.scroller_tici import Scroller from openpilot.system.ui.widgets import Widget from openpilot.common.params import Params diff --git a/selfdrive/ui/sunnypilot/layouts/settings/models.py b/selfdrive/ui/sunnypilot/layouts/settings/models.py index 1f0107aa9b..ca064bcae9 100644 --- a/selfdrive/ui/sunnypilot/layouts/settings/models.py +++ b/selfdrive/ui/sunnypilot/layouts/settings/models.py @@ -1,4 +1,4 @@ -from openpilot.system.ui.widgets.scroller import Scroller +from openpilot.system.ui.widgets.scroller_tici import Scroller from openpilot.system.ui.widgets import Widget from openpilot.common.params import Params diff --git a/selfdrive/ui/sunnypilot/layouts/settings/navigation.py b/selfdrive/ui/sunnypilot/layouts/settings/navigation.py index eec1367b69..a1654f0e32 100644 --- a/selfdrive/ui/sunnypilot/layouts/settings/navigation.py +++ b/selfdrive/ui/sunnypilot/layouts/settings/navigation.py @@ -1,4 +1,4 @@ -from openpilot.system.ui.widgets.scroller import Scroller +from openpilot.system.ui.widgets.scroller_tici import Scroller from openpilot.system.ui.widgets import Widget from openpilot.common.params import Params diff --git a/selfdrive/ui/sunnypilot/layouts/settings/osm.py b/selfdrive/ui/sunnypilot/layouts/settings/osm.py index 62f9b6d858..a8c18b3d59 100644 --- a/selfdrive/ui/sunnypilot/layouts/settings/osm.py +++ b/selfdrive/ui/sunnypilot/layouts/settings/osm.py @@ -1,4 +1,4 @@ -from openpilot.system.ui.widgets.scroller import Scroller +from openpilot.system.ui.widgets.scroller_tici import Scroller from openpilot.system.ui.widgets import Widget from openpilot.common.params import Params diff --git a/selfdrive/ui/sunnypilot/layouts/settings/steering.py b/selfdrive/ui/sunnypilot/layouts/settings/steering.py index f8ae00fcca..d76b802fbf 100644 --- a/selfdrive/ui/sunnypilot/layouts/settings/steering.py +++ b/selfdrive/ui/sunnypilot/layouts/settings/steering.py @@ -1,4 +1,4 @@ -from openpilot.system.ui.widgets.scroller import Scroller +from openpilot.system.ui.widgets.scroller_tici import Scroller from openpilot.system.ui.widgets import Widget from openpilot.common.params import Params diff --git a/selfdrive/ui/sunnypilot/layouts/settings/sunnylink.py b/selfdrive/ui/sunnypilot/layouts/settings/sunnylink.py index 068679ec67..ae44acd2bd 100644 --- a/selfdrive/ui/sunnypilot/layouts/settings/sunnylink.py +++ b/selfdrive/ui/sunnypilot/layouts/settings/sunnylink.py @@ -1,4 +1,4 @@ -from openpilot.system.ui.widgets.scroller import Scroller +from openpilot.system.ui.widgets.scroller_tici import Scroller from openpilot.system.ui.widgets import Widget from openpilot.common.params import Params diff --git a/selfdrive/ui/sunnypilot/layouts/settings/trips.py b/selfdrive/ui/sunnypilot/layouts/settings/trips.py index 091bd8f987..60cb25872b 100644 --- a/selfdrive/ui/sunnypilot/layouts/settings/trips.py +++ b/selfdrive/ui/sunnypilot/layouts/settings/trips.py @@ -1,4 +1,4 @@ -from openpilot.system.ui.widgets.scroller import Scroller +from openpilot.system.ui.widgets.scroller_tici import Scroller from openpilot.system.ui.widgets import Widget from openpilot.common.params import Params diff --git a/selfdrive/ui/sunnypilot/layouts/settings/vehicle.py b/selfdrive/ui/sunnypilot/layouts/settings/vehicle.py index 7d7a6f5fe8..fe2e150ea9 100644 --- a/selfdrive/ui/sunnypilot/layouts/settings/vehicle.py +++ b/selfdrive/ui/sunnypilot/layouts/settings/vehicle.py @@ -1,4 +1,4 @@ -from openpilot.system.ui.widgets.scroller import Scroller +from openpilot.system.ui.widgets.scroller_tici import Scroller from openpilot.system.ui.widgets import Widget from openpilot.common.params import Params diff --git a/selfdrive/ui/sunnypilot/layouts/settings/visuals.py b/selfdrive/ui/sunnypilot/layouts/settings/visuals.py index dba68c912f..fe43c6cb58 100644 --- a/selfdrive/ui/sunnypilot/layouts/settings/visuals.py +++ b/selfdrive/ui/sunnypilot/layouts/settings/visuals.py @@ -1,4 +1,4 @@ -from openpilot.system.ui.widgets.scroller import Scroller +from openpilot.system.ui.widgets.scroller_tici import Scroller from openpilot.system.ui.widgets import Widget from openpilot.common.params import Params From 91f2bf345956e0710e75a4f94a440d0986a0dc1d Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Fri, 21 Nov 2025 16:23:01 -0500 Subject: [PATCH 20/32] ui: `GuiApplicationExt` --- system/ui/lib/application.py | 4 +++- system/ui/sunnypilot/lib/application.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 system/ui/sunnypilot/lib/application.py diff --git a/system/ui/lib/application.py b/system/ui/lib/application.py index e3370a5f74..7271127838 100644 --- a/system/ui/lib/application.py +++ b/system/ui/lib/application.py @@ -19,6 +19,8 @@ from openpilot.system.hardware import HARDWARE, PC from openpilot.system.ui.lib.multilang import multilang from openpilot.common.realtime import Ratekeeper +from openpilot.system.ui.sunnypilot.lib.application import GuiApplicationExt + _DEFAULT_FPS = int(os.getenv("FPS", {'tizi': 20}.get(HARDWARE.get_device_type(), 60))) FPS_LOG_INTERVAL = 5 # Seconds between logging FPS drops FPS_DROP_THRESHOLD = 0.9 # FPS drop threshold for triggering a warning @@ -186,7 +188,7 @@ class MouseState: self._prev_mouse_event[slot] = ev -class GuiApplication: +class GuiApplication(GuiApplicationExt): def __init__(self, width: int | None = None, height: int | None = None): self._fonts: dict[FontWeight, rl.Font] = {} self._width = width if width is not None else GuiApplication._default_width() diff --git a/system/ui/sunnypilot/lib/application.py b/system/ui/sunnypilot/lib/application.py new file mode 100644 index 0000000000..b39bf31e9d --- /dev/null +++ b/system/ui/sunnypilot/lib/application.py @@ -0,0 +1,15 @@ +""" +Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors. + +This file is part of sunnypilot and is licensed under the MIT License. +See the LICENSE.md file in the root directory for more details. +""" +import os + +SUNNYPILOT_UI = os.getenv("SUNNYPILOT_UI", "1") == "1" + + +class GuiApplicationExt: + @staticmethod + def sunnypilot_ui() -> bool: + return SUNNYPILOT_UI From a33497ed19a413931ea4053c4903f15f2ae71d50 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Fri, 21 Nov 2025 16:42:49 -0500 Subject: [PATCH 21/32] add to readme --- system/ui/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/system/ui/README.md b/system/ui/README.md index f81cb5573a..796d298626 100644 --- a/system/ui/README.md +++ b/system/ui/README.md @@ -10,6 +10,7 @@ Quick start: * set `BURN_IN=1` to get a burn-in heatmap version of the UI * set `GRID=50` to show a 50-pixel alignment grid overlay * set `MAGIC_DEBUG=1` to show every dropped frames (only on device) +* set `SUNNYPILOT_UI=0` to run the stock UI instead of the sunnypilot UI * https://www.raylib.com/cheatsheet/cheatsheet.html * https://electronstudio.github.io/raylib-python-cffi/README.html#quickstart From ed775185f2434f2383bf68887805be3260c24eef Mon Sep 17 00:00:00 2001 From: nayan Date: Fri, 21 Nov 2025 17:49:27 -0500 Subject: [PATCH 22/32] use gui_app.sunnypilot_ui() --- common/params_keys.h | 1 - selfdrive/ui/layouts/settings/developer.py | 2 +- selfdrive/ui/layouts/settings/toggles.py | 2 +- selfdrive/ui/tests/test_ui/raylib_screenshots.py | 1 - 4 files changed, 2 insertions(+), 4 deletions(-) diff --git a/common/params_keys.h b/common/params_keys.h index fe08062987..38578d7ddc 100644 --- a/common/params_keys.h +++ b/common/params_keys.h @@ -173,7 +173,6 @@ inline static std::unordered_map keys = { {"ShowAdvancedControls", {PERSISTENT | BACKUP, BOOL, "0"}}, {"ShowTurnSignals", {PERSISTENT | BACKUP, BOOL, "0"}}, {"StandstillTimer", {PERSISTENT | BACKUP, BOOL, "0"}}, - {"sunnypilot_ui", {PERSISTENT, BOOL, "1"}}, {"TrueVEgoUI", {PERSISTENT | BACKUP, BOOL, "0"}}, // MADS params diff --git a/selfdrive/ui/layouts/settings/developer.py b/selfdrive/ui/layouts/settings/developer.py index d133a992ad..f47cd310ca 100644 --- a/selfdrive/ui/layouts/settings/developer.py +++ b/selfdrive/ui/layouts/settings/developer.py @@ -9,7 +9,7 @@ from openpilot.system.ui.lib.application import gui_app from openpilot.system.ui.lib.multilang import tr, tr_noop from openpilot.system.ui.widgets import DialogResult -if Params().get_bool("sunnypilot_ui"): +if gui_app.sunnypilot_ui(): from openpilot.system.ui.sunnypilot.widgets.list_view import toggle_item_sp as toggle_item # Description constants diff --git a/selfdrive/ui/layouts/settings/toggles.py b/selfdrive/ui/layouts/settings/toggles.py index 86c27aa7c8..b7f176e24f 100644 --- a/selfdrive/ui/layouts/settings/toggles.py +++ b/selfdrive/ui/layouts/settings/toggles.py @@ -9,7 +9,7 @@ from openpilot.system.ui.lib.multilang import tr, tr_noop from openpilot.system.ui.widgets import DialogResult from openpilot.selfdrive.ui.ui_state import ui_state -if Params().get_bool("sunnypilot_ui"): +if gui_app.sunnypilot_ui(): from openpilot.system.ui.sunnypilot.widgets.list_view import toggle_item_sp as toggle_item PERSONALITY_TO_INT = log.LongitudinalPersonality.schema.enumerants diff --git a/selfdrive/ui/tests/test_ui/raylib_screenshots.py b/selfdrive/ui/tests/test_ui/raylib_screenshots.py index 3cc5b01541..d3de616cc0 100755 --- a/selfdrive/ui/tests/test_ui/raylib_screenshots.py +++ b/selfdrive/ui/tests/test_ui/raylib_screenshots.py @@ -294,7 +294,6 @@ def create_screenshots(): with OpenpilotPrefix(): params = Params() params.put("DongleId", "123456789012345") - params.put_bool("sunnypilot_ui", True) # Set branch name params.put("UpdaterCurrentDescription", VERSION) From 5d3f95d420e97e9ea2d128d6f17564eb194611db Mon Sep 17 00:00:00 2001 From: nayan Date: Fri, 21 Nov 2025 18:08:19 -0500 Subject: [PATCH 23/32] use gui_app.sunnypilot_ui() --- selfdrive/ui/layouts/main.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/selfdrive/ui/layouts/main.py b/selfdrive/ui/layouts/main.py index e965888fde..11b9965d78 100644 --- a/selfdrive/ui/layouts/main.py +++ b/selfdrive/ui/layouts/main.py @@ -10,8 +10,7 @@ from openpilot.selfdrive.ui.ui_state import device, ui_state from openpilot.system.ui.widgets import Widget from openpilot.selfdrive.ui.layouts.onboarding import OnboardingWindow -from openpilot.common.params import Params -if Params().get_bool("sunnypilot_ui"): +if gui_app.sunnypilot_ui(): from openpilot.selfdrive.ui.sunnypilot.layouts.settings.settings import SettingsLayoutSP as SettingsLayout class MainState(IntEnum): From f5adcb4082daf2ae254db464c6521bece1696a1c Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Fri, 21 Nov 2025 23:01:15 -0500 Subject: [PATCH 24/32] lint --- system/ui/sunnypilot/lib/styles.py | 28 +++++--- system/ui/sunnypilot/widgets/list_view.py | 12 +++- system/ui/sunnypilot/widgets/toggle.py | 88 ++++++++++++----------- 3 files changed, 77 insertions(+), 51 deletions(-) diff --git a/system/ui/sunnypilot/lib/styles.py b/system/ui/sunnypilot/lib/styles.py index 28d50f48d7..e53aa3eedd 100644 --- a/system/ui/sunnypilot/lib/styles.py +++ b/system/ui/sunnypilot/lib/styles.py @@ -1,6 +1,14 @@ -import pyray as rl +""" +Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors. + +This file is part of sunnypilot and is licensed under the MIT License. +See the LICENSE.md file in the root directory for more details. +""" from dataclasses import dataclass +import pyray as rl + + @dataclass class Base: # Widget/Control Base Dimensions @@ -15,16 +23,17 @@ class Base: TOGGLE_WIDTH = int(TOGGLE_HEIGHT * 1.75) TOGGLE_BG_HEIGHT = TOGGLE_HEIGHT - 20 + @dataclass -class SP_Default(Base): +class DefaultStyleSP(Base): # Base Colors - BASE_BG_COLOR = rl.Color(57, 57, 57, 255) # Grey - ON_BG_COLOR = rl.Color(28, 101, 186, 255) # Blue + BASE_BG_COLOR = rl.Color(57, 57, 57, 255) # Grey + ON_BG_COLOR = rl.Color(28, 101, 186, 255) # Blue OFF_BG_COLOR = BASE_BG_COLOR - ON_HOVER_BG_COLOR = rl.Color(17, 78, 150, 255) # Dark Blue + ON_HOVER_BG_COLOR = rl.Color(17, 78, 150, 255) # Dark Blue OFF_HOVER_BG_COLOR = rl.Color(21, 21, 21, 255) # Dark gray - DISABLED_ON_BG_COLOR = rl.Color(37, 70, 107, 255) # Dull Blue - DISABLED_OFF_BG_COLOR = rl.Color(39, 39, 39, 255) # Grey + DISABLED_ON_BG_COLOR = rl.Color(37, 70, 107, 255) # Dull Blue + DISABLED_OFF_BG_COLOR = rl.Color(39, 39, 39, 255) # Grey ITEM_TEXT_COLOR = rl.WHITE ITEM_DISABLED_TEXT_COLOR = rl.Color(88, 88, 88, 255) ITEM_DESC_TEXT_COLOR = rl.Color(128, 128, 128, 255) @@ -35,6 +44,7 @@ class SP_Default(Base): TOGGLE_KNOB_COLOR = rl.WHITE TOGGLE_DISABLED_ON_COLOR = DISABLED_ON_BG_COLOR TOGGLE_DISABLED_OFF_COLOR = DISABLED_OFF_BG_COLOR - TOGGLE_DISABLED_KNOB_COLOR = rl.Color(88, 88, 88, 255) # Lighter Grey + TOGGLE_DISABLED_KNOB_COLOR = rl.Color(88, 88, 88, 255) # Lighter Grey -style = SP_Default + +style = DefaultStyleSP diff --git a/system/ui/sunnypilot/widgets/list_view.py b/system/ui/sunnypilot/widgets/list_view.py index 86dbde2797..dcf8f6019d 100644 --- a/system/ui/sunnypilot/widgets/list_view.py +++ b/system/ui/sunnypilot/widgets/list_view.py @@ -1,6 +1,12 @@ -import pyray as rl +""" +Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors. +This file is part of sunnypilot and is licensed under the MIT License. +See the LICENSE.md file in the root directory for more details. +""" from collections.abc import Callable + +import pyray as rl from openpilot.system.ui.lib.text_measure import measure_text_cached from openpilot.system.ui.sunnypilot.widgets.toggle import ToggleSP from openpilot.system.ui.widgets.list_view import ListItem, ToggleAction, ItemAction @@ -13,6 +19,7 @@ class ToggleActionSP(ToggleAction): ToggleAction.__init__(self, initial_state, width, enabled, callback) self.toggle = ToggleSP(initial_state=initial_state, callback=callback, param=param) + class ListItemSP(ListItem): def __init__(self, title: str | Callable[[], str] = "", icon: str | None = None, description: str | Callable[[], str] | None = None, description_visible: bool = False, callback: Callable | None = None, @@ -92,7 +99,8 @@ class ListItemSP(ListItem): ) self._html_renderer.render(description_rect) + def toggle_item_sp(title: str | Callable[[], str], description: str | Callable[[], str] | None = None, initial_state: bool = False, - callback: Callable | None = None, icon: str = "", enabled: bool | Callable[[], bool] = True, param: str | None = None) -> ListItemSP: + callback: Callable | None = None, icon: str = "", enabled: bool | Callable[[], bool] = True, param: str | None = None) -> ListItemSP: action = ToggleActionSP(initial_state=initial_state, enabled=enabled, callback=callback, param=param) return ListItemSP(title=title, description=description, action_item=action, icon=icon, callback=callback) diff --git a/system/ui/sunnypilot/widgets/toggle.py b/system/ui/sunnypilot/widgets/toggle.py index 84e3f9b4f2..22439d1a29 100644 --- a/system/ui/sunnypilot/widgets/toggle.py +++ b/system/ui/sunnypilot/widgets/toggle.py @@ -1,5 +1,12 @@ -import pyray as rl +""" +Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors. + +This file is part of sunnypilot and is licensed under the MIT License. +See the LICENSE.md file in the root directory for more details. +""" from collections.abc import Callable + +import pyray as rl from openpilot.common.params import Params from openpilot.system.ui.lib.application import MousePos from openpilot.system.ui.widgets.toggle import Toggle @@ -9,18 +16,19 @@ KNOB_PADDING = 5 KNOB_RADIUS = style.TOGGLE_BG_HEIGHT / 2 - KNOB_PADDING SYMBOL_SIZE = KNOB_RADIUS / 2 + class ToggleSP(Toggle): def __init__(self, initial_state=False, callback: Callable[[bool], None] | None = None, param: str | None = None): self.param_key = param self.params = Params() if self.param_key: - initial_state = self.params.get_bool(self.param_key) + initial_state = self.params.get_bool(self.param_key) Toggle.__init__(self, initial_state, callback) def _handle_mouse_release(self, mouse_pos: MousePos): - super()._handle_mouse_release(mouse_pos) - if self._enabled and self.param_key: - self.params.put_bool(self.param_key, self._state) + super()._handle_mouse_release(mouse_pos) + if self._enabled and self.param_key: + self.params.put_bool(self.param_key, self._state) def _render(self, rect: rl.Rectangle): self.update() @@ -37,8 +45,8 @@ class ToggleSP(Toggle): # Draw outline first outline_color = style.TOGGLE_ON_COLOR if not self._enabled: - # Use a more subtle color for disabled state - outline_color = rl.Color(outline_color.r // 2, outline_color.g // 2, outline_color.b // 2, 255) + # Use a more subtle color for disabled state + outline_color = rl.Color(outline_color.r // 2, outline_color.g // 2, outline_color.b // 2, 255) # Draw outline by drawing a slightly larger rounded rectangle behind the background outline_rect = rl.Rectangle(bg_rect.x - 2, bg_rect.y - 2, bg_rect.width + 4, bg_rect.height + 4) @@ -58,39 +66,39 @@ class ToggleSP(Toggle): rl.draw_circle(int(knob_x), int(knob_y), KNOB_RADIUS, knob_color) if self._state and (self._enabled or self._progress > 0.5): - # Draw checkmark when toggle is ON - start_x = knob_x - SYMBOL_SIZE * 0.8 - start_y = knob_y - mid_x = knob_x - SYMBOL_SIZE * 0.1 - mid_y = knob_y + SYMBOL_SIZE * 0.6 - end_x = knob_x + SYMBOL_SIZE * 0.8 - end_y = knob_y - SYMBOL_SIZE * 0.5 + # Draw checkmark when toggle is ON + start_x = knob_x - SYMBOL_SIZE * 0.8 + start_y = knob_y + mid_x = knob_x - SYMBOL_SIZE * 0.1 + mid_y = knob_y + SYMBOL_SIZE * 0.6 + end_x = knob_x + SYMBOL_SIZE * 0.8 + end_y = knob_y - SYMBOL_SIZE * 0.5 - rl.draw_line_ex( - rl.Vector2(int(start_x), int(start_y)), - rl.Vector2(int(mid_x), int(mid_y)), - 3, - style.TOGGLE_ON_COLOR - ) - rl.draw_line_ex( - rl.Vector2(int(mid_x), int(mid_y)), - rl.Vector2(int(end_x), int(end_y)), - 3, - style.TOGGLE_ON_COLOR - ) + rl.draw_line_ex( + rl.Vector2(int(start_x), int(start_y)), + rl.Vector2(int(mid_x), int(mid_y)), + 3, + style.TOGGLE_ON_COLOR + ) + rl.draw_line_ex( + rl.Vector2(int(mid_x), int(mid_y)), + rl.Vector2(int(end_x), int(end_y)), + 3, + style.TOGGLE_ON_COLOR + ) else: - # Draw X when toggle is OFF - x_offset = SYMBOL_SIZE * 0.65 + # Draw X when toggle is OFF + x_offset = SYMBOL_SIZE * 0.65 - rl.draw_line_ex( - rl.Vector2(int(knob_x - x_offset), int(knob_y - x_offset)), - rl.Vector2(int(knob_x + x_offset), int(knob_y + x_offset)), - 3, - style.TOGGLE_OFF_COLOR - ) - rl.draw_line_ex( - rl.Vector2(int(knob_x + x_offset), int(knob_y - x_offset)), - rl.Vector2(int(knob_x - x_offset), int(knob_y + x_offset)), - 3, - style.TOGGLE_OFF_COLOR - ) + rl.draw_line_ex( + rl.Vector2(int(knob_x - x_offset), int(knob_y - x_offset)), + rl.Vector2(int(knob_x + x_offset), int(knob_y + x_offset)), + 3, + style.TOGGLE_OFF_COLOR + ) + rl.draw_line_ex( + rl.Vector2(int(knob_x + x_offset), int(knob_y - x_offset)), + rl.Vector2(int(knob_x - x_offset), int(knob_y + x_offset)), + 3, + style.TOGGLE_OFF_COLOR + ) From 554239013c2480ee316a2a97dae3e5a5f993b016 Mon Sep 17 00:00:00 2001 From: nayan Date: Fri, 21 Nov 2025 23:20:08 -0500 Subject: [PATCH 25/32] no fancy toggles :( --- system/ui/sunnypilot/lib/styles.py | 4 +-- system/ui/sunnypilot/widgets/toggle.py | 50 +------------------------- system/ui/widgets/network.py | 3 ++ 3 files changed, 6 insertions(+), 51 deletions(-) diff --git a/system/ui/sunnypilot/lib/styles.py b/system/ui/sunnypilot/lib/styles.py index e53aa3eedd..a232ac192d 100644 --- a/system/ui/sunnypilot/lib/styles.py +++ b/system/ui/sunnypilot/lib/styles.py @@ -19,7 +19,7 @@ class Base: ITEM_DESC_V_OFFSET = 150 # Toggle Control - TOGGLE_HEIGHT = 100 + TOGGLE_HEIGHT = 120 TOGGLE_WIDTH = int(TOGGLE_HEIGHT * 1.75) TOGGLE_BG_HEIGHT = TOGGLE_HEIGHT - 20 @@ -29,7 +29,7 @@ class DefaultStyleSP(Base): # Base Colors BASE_BG_COLOR = rl.Color(57, 57, 57, 255) # Grey ON_BG_COLOR = rl.Color(28, 101, 186, 255) # Blue - OFF_BG_COLOR = BASE_BG_COLOR + OFF_BG_COLOR = rl.Color(70, 70, 70, 255) # Lighter Grey ON_HOVER_BG_COLOR = rl.Color(17, 78, 150, 255) # Dark Blue OFF_HOVER_BG_COLOR = rl.Color(21, 21, 21, 255) # Dark gray DISABLED_ON_BG_COLOR = rl.Color(37, 70, 107, 255) # Dull Blue diff --git a/system/ui/sunnypilot/widgets/toggle.py b/system/ui/sunnypilot/widgets/toggle.py index 22439d1a29..46b390f773 100644 --- a/system/ui/sunnypilot/widgets/toggle.py +++ b/system/ui/sunnypilot/widgets/toggle.py @@ -14,7 +14,6 @@ from openpilot.system.ui.sunnypilot.lib.styles import style KNOB_PADDING = 5 KNOB_RADIUS = style.TOGGLE_BG_HEIGHT / 2 - KNOB_PADDING -SYMBOL_SIZE = KNOB_RADIUS / 2 class ToggleSP(Toggle): @@ -32,6 +31,7 @@ class ToggleSP(Toggle): def _render(self, rect: rl.Rectangle): self.update() + self._rect.y -= style.ITEM_PADDING / 2 if self._enabled: bg_color = self._blend_color(style.TOGGLE_OFF_COLOR, style.TOGGLE_ON_COLOR, self._progress) knob_color = style.TOGGLE_KNOB_COLOR @@ -42,16 +42,6 @@ class ToggleSP(Toggle): # Draw background bg_rect = rl.Rectangle(self._rect.x, self._rect.y, style.TOGGLE_WIDTH, style.TOGGLE_BG_HEIGHT) - # Draw outline first - outline_color = style.TOGGLE_ON_COLOR - if not self._enabled: - # Use a more subtle color for disabled state - outline_color = rl.Color(outline_color.r // 2, outline_color.g // 2, outline_color.b // 2, 255) - - # Draw outline by drawing a slightly larger rounded rectangle behind the background - outline_rect = rl.Rectangle(bg_rect.x - 2, bg_rect.y - 2, bg_rect.width + 4, bg_rect.height + 4) - rl.draw_rectangle_rounded(outline_rect, 1.0, 10, outline_color) - # Draw actual background rl.draw_rectangle_rounded(bg_rect, 1.0, 10, bg_color) @@ -64,41 +54,3 @@ class ToggleSP(Toggle): knob_y = self._rect.y + style.TOGGLE_BG_HEIGHT / 2 rl.draw_circle(int(knob_x), int(knob_y), KNOB_RADIUS, knob_color) - - if self._state and (self._enabled or self._progress > 0.5): - # Draw checkmark when toggle is ON - start_x = knob_x - SYMBOL_SIZE * 0.8 - start_y = knob_y - mid_x = knob_x - SYMBOL_SIZE * 0.1 - mid_y = knob_y + SYMBOL_SIZE * 0.6 - end_x = knob_x + SYMBOL_SIZE * 0.8 - end_y = knob_y - SYMBOL_SIZE * 0.5 - - rl.draw_line_ex( - rl.Vector2(int(start_x), int(start_y)), - rl.Vector2(int(mid_x), int(mid_y)), - 3, - style.TOGGLE_ON_COLOR - ) - rl.draw_line_ex( - rl.Vector2(int(mid_x), int(mid_y)), - rl.Vector2(int(end_x), int(end_y)), - 3, - style.TOGGLE_ON_COLOR - ) - else: - # Draw X when toggle is OFF - x_offset = SYMBOL_SIZE * 0.65 - - rl.draw_line_ex( - rl.Vector2(int(knob_x - x_offset), int(knob_y - x_offset)), - rl.Vector2(int(knob_x + x_offset), int(knob_y + x_offset)), - 3, - style.TOGGLE_OFF_COLOR - ) - rl.draw_line_ex( - rl.Vector2(int(knob_x + x_offset), int(knob_y - x_offset)), - rl.Vector2(int(knob_x - x_offset), int(knob_y + x_offset)), - 3, - style.TOGGLE_OFF_COLOR - ) diff --git a/system/ui/widgets/network.py b/system/ui/widgets/network.py index f41a04c249..fa47d35536 100644 --- a/system/ui/widgets/network.py +++ b/system/ui/widgets/network.py @@ -15,6 +15,9 @@ from openpilot.system.ui.widgets.label import gui_label from openpilot.system.ui.widgets.scroller_tici import Scroller from openpilot.system.ui.widgets.list_view import ButtonAction, ListItem, MultipleButtonAction, ToggleAction, button_item, text_item +if gui_app.sunnypilot_ui(): + from openpilot.system.ui.sunnypilot.widgets.list_view import ToggleActionSP as ToggleAction + # These are only used for AdvancedNetworkSettings, standalone apps just need WifiManagerUI try: from openpilot.common.params import Params From bd55d151d793cc1ab7fd2961d2f93f609ac725bf Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Fri, 21 Nov 2025 23:21:13 -0500 Subject: [PATCH 26/32] match them --- selfdrive/ui/layouts/main.py | 1 + selfdrive/ui/sunnypilot/layouts/settings/cruise.py | 8 +++++++- selfdrive/ui/sunnypilot/layouts/settings/display.py | 8 +++++++- selfdrive/ui/sunnypilot/layouts/settings/models.py | 8 +++++++- selfdrive/ui/sunnypilot/layouts/settings/navigation.py | 8 +++++++- selfdrive/ui/sunnypilot/layouts/settings/osm.py | 8 +++++++- selfdrive/ui/sunnypilot/layouts/settings/steering.py | 8 +++++++- selfdrive/ui/sunnypilot/layouts/settings/sunnylink.py | 8 +++++++- selfdrive/ui/sunnypilot/layouts/settings/trips.py | 8 +++++++- selfdrive/ui/sunnypilot/layouts/settings/vehicle.py | 8 +++++++- selfdrive/ui/sunnypilot/layouts/settings/visuals.py | 8 +++++++- 11 files changed, 71 insertions(+), 10 deletions(-) diff --git a/selfdrive/ui/layouts/main.py b/selfdrive/ui/layouts/main.py index 11b9965d78..a020a63b55 100644 --- a/selfdrive/ui/layouts/main.py +++ b/selfdrive/ui/layouts/main.py @@ -13,6 +13,7 @@ from openpilot.selfdrive.ui.layouts.onboarding import OnboardingWindow if gui_app.sunnypilot_ui(): from openpilot.selfdrive.ui.sunnypilot.layouts.settings.settings import SettingsLayoutSP as SettingsLayout + class MainState(IntEnum): HOME = 0 SETTINGS = 1 diff --git a/selfdrive/ui/sunnypilot/layouts/settings/cruise.py b/selfdrive/ui/sunnypilot/layouts/settings/cruise.py index 049f0e0de4..9439c588d3 100644 --- a/selfdrive/ui/sunnypilot/layouts/settings/cruise.py +++ b/selfdrive/ui/sunnypilot/layouts/settings/cruise.py @@ -1,6 +1,12 @@ +""" +Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors. + +This file is part of sunnypilot and is licensed under the MIT License. +See the LICENSE.md file in the root directory for more details. +""" +from openpilot.common.params import Params from openpilot.system.ui.widgets.scroller_tici import Scroller from openpilot.system.ui.widgets import Widget -from openpilot.common.params import Params class CruiseLayout(Widget): diff --git a/selfdrive/ui/sunnypilot/layouts/settings/display.py b/selfdrive/ui/sunnypilot/layouts/settings/display.py index 706410dbfa..d1d0a661b1 100644 --- a/selfdrive/ui/sunnypilot/layouts/settings/display.py +++ b/selfdrive/ui/sunnypilot/layouts/settings/display.py @@ -1,6 +1,12 @@ +""" +Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors. + +This file is part of sunnypilot and is licensed under the MIT License. +See the LICENSE.md file in the root directory for more details. +""" +from openpilot.common.params import Params from openpilot.system.ui.widgets.scroller_tici import Scroller from openpilot.system.ui.widgets import Widget -from openpilot.common.params import Params class DisplayLayout(Widget): diff --git a/selfdrive/ui/sunnypilot/layouts/settings/models.py b/selfdrive/ui/sunnypilot/layouts/settings/models.py index ca064bcae9..add437b127 100644 --- a/selfdrive/ui/sunnypilot/layouts/settings/models.py +++ b/selfdrive/ui/sunnypilot/layouts/settings/models.py @@ -1,6 +1,12 @@ +""" +Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors. + +This file is part of sunnypilot and is licensed under the MIT License. +See the LICENSE.md file in the root directory for more details. +""" +from openpilot.common.params import Params from openpilot.system.ui.widgets.scroller_tici import Scroller from openpilot.system.ui.widgets import Widget -from openpilot.common.params import Params class ModelsLayout(Widget): diff --git a/selfdrive/ui/sunnypilot/layouts/settings/navigation.py b/selfdrive/ui/sunnypilot/layouts/settings/navigation.py index a1654f0e32..1f44775bb3 100644 --- a/selfdrive/ui/sunnypilot/layouts/settings/navigation.py +++ b/selfdrive/ui/sunnypilot/layouts/settings/navigation.py @@ -1,6 +1,12 @@ +""" +Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors. + +This file is part of sunnypilot and is licensed under the MIT License. +See the LICENSE.md file in the root directory for more details. +""" +from openpilot.common.params import Params from openpilot.system.ui.widgets.scroller_tici import Scroller from openpilot.system.ui.widgets import Widget -from openpilot.common.params import Params class NavigationLayout(Widget): diff --git a/selfdrive/ui/sunnypilot/layouts/settings/osm.py b/selfdrive/ui/sunnypilot/layouts/settings/osm.py index a8c18b3d59..d57a0de9d8 100644 --- a/selfdrive/ui/sunnypilot/layouts/settings/osm.py +++ b/selfdrive/ui/sunnypilot/layouts/settings/osm.py @@ -1,6 +1,12 @@ +""" +Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors. + +This file is part of sunnypilot and is licensed under the MIT License. +See the LICENSE.md file in the root directory for more details. +""" +from openpilot.common.params import Params from openpilot.system.ui.widgets.scroller_tici import Scroller from openpilot.system.ui.widgets import Widget -from openpilot.common.params import Params class OSMLayout(Widget): diff --git a/selfdrive/ui/sunnypilot/layouts/settings/steering.py b/selfdrive/ui/sunnypilot/layouts/settings/steering.py index d76b802fbf..ac67eb9163 100644 --- a/selfdrive/ui/sunnypilot/layouts/settings/steering.py +++ b/selfdrive/ui/sunnypilot/layouts/settings/steering.py @@ -1,6 +1,12 @@ +""" +Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors. + +This file is part of sunnypilot and is licensed under the MIT License. +See the LICENSE.md file in the root directory for more details. +""" +from openpilot.common.params import Params from openpilot.system.ui.widgets.scroller_tici import Scroller from openpilot.system.ui.widgets import Widget -from openpilot.common.params import Params class SteeringLayout(Widget): diff --git a/selfdrive/ui/sunnypilot/layouts/settings/sunnylink.py b/selfdrive/ui/sunnypilot/layouts/settings/sunnylink.py index ae44acd2bd..b1e12c17ab 100644 --- a/selfdrive/ui/sunnypilot/layouts/settings/sunnylink.py +++ b/selfdrive/ui/sunnypilot/layouts/settings/sunnylink.py @@ -1,6 +1,12 @@ +""" +Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors. + +This file is part of sunnypilot and is licensed under the MIT License. +See the LICENSE.md file in the root directory for more details. +""" +from openpilot.common.params import Params from openpilot.system.ui.widgets.scroller_tici import Scroller from openpilot.system.ui.widgets import Widget -from openpilot.common.params import Params class SunnylinkLayout(Widget): diff --git a/selfdrive/ui/sunnypilot/layouts/settings/trips.py b/selfdrive/ui/sunnypilot/layouts/settings/trips.py index 60cb25872b..a318cebeb0 100644 --- a/selfdrive/ui/sunnypilot/layouts/settings/trips.py +++ b/selfdrive/ui/sunnypilot/layouts/settings/trips.py @@ -1,6 +1,12 @@ +""" +Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors. + +This file is part of sunnypilot and is licensed under the MIT License. +See the LICENSE.md file in the root directory for more details. +""" +from openpilot.common.params import Params from openpilot.system.ui.widgets.scroller_tici import Scroller from openpilot.system.ui.widgets import Widget -from openpilot.common.params import Params class TripsLayout(Widget): diff --git a/selfdrive/ui/sunnypilot/layouts/settings/vehicle.py b/selfdrive/ui/sunnypilot/layouts/settings/vehicle.py index fe2e150ea9..d04816a411 100644 --- a/selfdrive/ui/sunnypilot/layouts/settings/vehicle.py +++ b/selfdrive/ui/sunnypilot/layouts/settings/vehicle.py @@ -1,6 +1,12 @@ +""" +Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors. + +This file is part of sunnypilot and is licensed under the MIT License. +See the LICENSE.md file in the root directory for more details. +""" +from openpilot.common.params import Params from openpilot.system.ui.widgets.scroller_tici import Scroller from openpilot.system.ui.widgets import Widget -from openpilot.common.params import Params class VehicleLayout(Widget): diff --git a/selfdrive/ui/sunnypilot/layouts/settings/visuals.py b/selfdrive/ui/sunnypilot/layouts/settings/visuals.py index fe43c6cb58..1036af3e5f 100644 --- a/selfdrive/ui/sunnypilot/layouts/settings/visuals.py +++ b/selfdrive/ui/sunnypilot/layouts/settings/visuals.py @@ -1,6 +1,12 @@ +""" +Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors. + +This file is part of sunnypilot and is licensed under the MIT License. +See the LICENSE.md file in the root directory for more details. +""" +from openpilot.common.params import Params from openpilot.system.ui.widgets.scroller_tici import Scroller from openpilot.system.ui.widgets import Widget -from openpilot.common.params import Params class VisualsLayout(Widget): From 6dfd075ea8b86480672b5cb2440c0c0f7223daf1 Mon Sep 17 00:00:00 2001 From: nayan Date: Fri, 21 Nov 2025 23:27:10 -0500 Subject: [PATCH 27/32] mici scroller - no touchy --- system/ui/widgets/scroller.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/ui/widgets/scroller.py b/system/ui/widgets/scroller.py index 9d300750e8..9a04e84257 100644 --- a/system/ui/widgets/scroller.py +++ b/system/ui/widgets/scroller.py @@ -28,8 +28,8 @@ class LineSeparator(Widget): self._rect.width = parent_rect.width def _render(self, _): - rl.draw_line(int(self._rect.x), int(self._rect.y), - int(self._rect.x + self._rect.width), int(self._rect.y), + rl.draw_line(int(self._rect.x) + LINE_PADDING, int(self._rect.y), + int(self._rect.x + self._rect.width) - LINE_PADDING, int(self._rect.y), LINE_COLOR) From 457b6634fd0f3144170e050db370b24dc5401a64 Mon Sep 17 00:00:00 2001 From: Nayan Date: Fri, 21 Nov 2025 23:37:03 -0500 Subject: [PATCH 28/32] ui: sunnypilot toggle style (#1475) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * param to control stock vs sp ui * init styles * SP Toggles * Lint * optimizations * sp raylib preview * fix callback * fix ui preview * better padding * this * listitem -> listitemsp * add show_description method * remove padding from line separator. like, WHY? 😩😩 * ui: `GuiApplicationExt` * add to readme * use gui_app.sunnypilot_ui() * lint * no fancy toggles :( * mici scroller - no touchy --------- Co-authored-by: Jason Wen --- selfdrive/ui/layouts/settings/developer.py | 3 + selfdrive/ui/layouts/settings/toggles.py | 3 + .../ui/tests/test_ui/raylib_screenshots.py | 2 +- system/ui/sunnypilot/lib/styles.py | 50 +++++++++ system/ui/sunnypilot/widgets/list_view.py | 106 ++++++++++++++++++ system/ui/sunnypilot/widgets/toggle.py | 56 +++++++++ system/ui/widgets/network.py | 3 + 7 files changed, 222 insertions(+), 1 deletion(-) create mode 100644 system/ui/sunnypilot/lib/styles.py create mode 100644 system/ui/sunnypilot/widgets/list_view.py create mode 100644 system/ui/sunnypilot/widgets/toggle.py diff --git a/selfdrive/ui/layouts/settings/developer.py b/selfdrive/ui/layouts/settings/developer.py index 646c817508..f47cd310ca 100644 --- a/selfdrive/ui/layouts/settings/developer.py +++ b/selfdrive/ui/layouts/settings/developer.py @@ -9,6 +9,9 @@ from openpilot.system.ui.lib.application import gui_app from openpilot.system.ui.lib.multilang import tr, tr_noop from openpilot.system.ui.widgets import DialogResult +if gui_app.sunnypilot_ui(): + from openpilot.system.ui.sunnypilot.widgets.list_view import toggle_item_sp as toggle_item + # Description constants DESCRIPTIONS = { 'enable_adb': tr_noop( diff --git a/selfdrive/ui/layouts/settings/toggles.py b/selfdrive/ui/layouts/settings/toggles.py index 7fae2dfd24..b7f176e24f 100644 --- a/selfdrive/ui/layouts/settings/toggles.py +++ b/selfdrive/ui/layouts/settings/toggles.py @@ -9,6 +9,9 @@ from openpilot.system.ui.lib.multilang import tr, tr_noop from openpilot.system.ui.widgets import DialogResult from openpilot.selfdrive.ui.ui_state import ui_state +if gui_app.sunnypilot_ui(): + from openpilot.system.ui.sunnypilot.widgets.list_view import toggle_item_sp as toggle_item + PERSONALITY_TO_INT = log.LongitudinalPersonality.schema.enumerants # Description constants diff --git a/selfdrive/ui/tests/test_ui/raylib_screenshots.py b/selfdrive/ui/tests/test_ui/raylib_screenshots.py index 481ac111be..d3de616cc0 100755 --- a/selfdrive/ui/tests/test_ui/raylib_screenshots.py +++ b/selfdrive/ui/tests/test_ui/raylib_screenshots.py @@ -149,7 +149,7 @@ def setup_experimental_mode_description(click, pm: PubMaster): def setup_openpilot_long_confirmation_dialog(click, pm: PubMaster): setup_settings_developer(click, pm) - click(2000, 960) # toggle openpilot longitudinal control + click(650, 960) # toggle openpilot longitudinal control def setup_onroad(click, pm: PubMaster): diff --git a/system/ui/sunnypilot/lib/styles.py b/system/ui/sunnypilot/lib/styles.py new file mode 100644 index 0000000000..a232ac192d --- /dev/null +++ b/system/ui/sunnypilot/lib/styles.py @@ -0,0 +1,50 @@ +""" +Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors. + +This file is part of sunnypilot and is licensed under the MIT License. +See the LICENSE.md file in the root directory for more details. +""" +from dataclasses import dataclass + +import pyray as rl + + +@dataclass +class Base: + # Widget/Control Base Dimensions + ITEM_BASE_HEIGHT = 170 + ITEM_PADDING = 20 + ITEM_TEXT_FONT_SIZE = 50 + ITEM_DESC_FONT_SIZE = 40 + ITEM_DESC_V_OFFSET = 150 + + # Toggle Control + TOGGLE_HEIGHT = 120 + TOGGLE_WIDTH = int(TOGGLE_HEIGHT * 1.75) + TOGGLE_BG_HEIGHT = TOGGLE_HEIGHT - 20 + + +@dataclass +class DefaultStyleSP(Base): + # Base Colors + BASE_BG_COLOR = rl.Color(57, 57, 57, 255) # Grey + ON_BG_COLOR = rl.Color(28, 101, 186, 255) # Blue + OFF_BG_COLOR = rl.Color(70, 70, 70, 255) # Lighter Grey + ON_HOVER_BG_COLOR = rl.Color(17, 78, 150, 255) # Dark Blue + OFF_HOVER_BG_COLOR = rl.Color(21, 21, 21, 255) # Dark gray + DISABLED_ON_BG_COLOR = rl.Color(37, 70, 107, 255) # Dull Blue + DISABLED_OFF_BG_COLOR = rl.Color(39, 39, 39, 255) # Grey + ITEM_TEXT_COLOR = rl.WHITE + ITEM_DISABLED_TEXT_COLOR = rl.Color(88, 88, 88, 255) + ITEM_DESC_TEXT_COLOR = rl.Color(128, 128, 128, 255) + + # Toggle Control + TOGGLE_ON_COLOR = ON_BG_COLOR + TOGGLE_OFF_COLOR = OFF_BG_COLOR + TOGGLE_KNOB_COLOR = rl.WHITE + TOGGLE_DISABLED_ON_COLOR = DISABLED_ON_BG_COLOR + TOGGLE_DISABLED_OFF_COLOR = DISABLED_OFF_BG_COLOR + TOGGLE_DISABLED_KNOB_COLOR = rl.Color(88, 88, 88, 255) # Lighter Grey + + +style = DefaultStyleSP diff --git a/system/ui/sunnypilot/widgets/list_view.py b/system/ui/sunnypilot/widgets/list_view.py new file mode 100644 index 0000000000..dcf8f6019d --- /dev/null +++ b/system/ui/sunnypilot/widgets/list_view.py @@ -0,0 +1,106 @@ +""" +Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors. + +This file is part of sunnypilot and is licensed under the MIT License. +See the LICENSE.md file in the root directory for more details. +""" +from collections.abc import Callable + +import pyray as rl +from openpilot.system.ui.lib.text_measure import measure_text_cached +from openpilot.system.ui.sunnypilot.widgets.toggle import ToggleSP +from openpilot.system.ui.widgets.list_view import ListItem, ToggleAction, ItemAction +from openpilot.system.ui.sunnypilot.lib.styles import style + + +class ToggleActionSP(ToggleAction): + def __init__(self, initial_state: bool = False, width: int = style.TOGGLE_WIDTH, enabled: bool | Callable[[], bool] = True, + callback: Callable[[bool], None] | None = None, param: str | None = None): + ToggleAction.__init__(self, initial_state, width, enabled, callback) + self.toggle = ToggleSP(initial_state=initial_state, callback=callback, param=param) + + +class ListItemSP(ListItem): + def __init__(self, title: str | Callable[[], str] = "", icon: str | None = None, description: str | Callable[[], str] | None = None, + description_visible: bool = False, callback: Callable | None = None, + action_item: ItemAction | None = None): + ListItem.__init__(self, title, icon, description, description_visible, callback, action_item) + + def show_description(self, show: bool): + self._set_description_visible(show) + + def get_right_item_rect(self, item_rect: rl.Rectangle) -> rl.Rectangle: + if not self.action_item: + return rl.Rectangle(0, 0, 0, 0) + + right_width = self.action_item.rect.width + if right_width == 0: # Full width action (like DualButtonAction) + return rl.Rectangle(item_rect.x + style.ITEM_PADDING, item_rect.y, + item_rect.width - (style.ITEM_PADDING * 2), style.ITEM_BASE_HEIGHT) + + action_width = self.action_item.rect.width + if isinstance(self.action_item, ToggleAction): + action_x = item_rect.x + else: + action_x = item_rect.x + item_rect.width - action_width + action_y = item_rect.y + return rl.Rectangle(action_x, action_y, action_width, style.ITEM_BASE_HEIGHT) + + def _render(self, _): + content_x = self._rect.x + style.ITEM_PADDING + text_x = content_x + left_action_item = isinstance(self.action_item, ToggleAction) + + if left_action_item: + left_rect = rl.Rectangle( + content_x, + self._rect.y + (style.ITEM_BASE_HEIGHT - style.TOGGLE_HEIGHT) // 2, + style.TOGGLE_WIDTH, + style.TOGGLE_HEIGHT + ) + text_x = left_rect.x + left_rect.width + style.ITEM_PADDING * 1.5 + + # Draw title + if self.title: + text_size = measure_text_cached(self._font, self.title, style.ITEM_TEXT_FONT_SIZE) + item_y = self._rect.y + (style.ITEM_BASE_HEIGHT - text_size.y) // 2 + rl.draw_text_ex(self._font, self.title, rl.Vector2(text_x, item_y), style.ITEM_TEXT_FONT_SIZE, 0, style.ITEM_TEXT_COLOR) + + # Render toggle and handle callback + if self.action_item.render(left_rect) and self.action_item.enabled: + if self.callback: + self.callback() + + else: + if self.title: + # Draw main text + text_size = measure_text_cached(self._font, self.title, style.ITEM_TEXT_FONT_SIZE) + item_y = self._rect.y + (style.ITEM_BASE_HEIGHT - text_size.y) // 2 + rl.draw_text_ex(self._font, self.title, rl.Vector2(text_x, item_y), style.ITEM_TEXT_FONT_SIZE, 0, style.ITEM_TEXT_COLOR) + + # Draw right item if present + if self.action_item: + right_rect = self.get_right_item_rect(self._rect) + right_rect.y = self._rect.y + if self.action_item.render(right_rect) and self.action_item.enabled: + # Right item was clicked/activated + if self.callback: + self.callback() + + # Draw description if visible + if self.description_visible: + content_width = int(self._rect.width - style.ITEM_PADDING * 2) + description_height = self._html_renderer.get_total_height(content_width) + description_rect = rl.Rectangle( + self._rect.x + style.ITEM_PADDING, + self._rect.y + style.ITEM_DESC_V_OFFSET, + content_width, + description_height + ) + self._html_renderer.render(description_rect) + + +def toggle_item_sp(title: str | Callable[[], str], description: str | Callable[[], str] | None = None, initial_state: bool = False, + callback: Callable | None = None, icon: str = "", enabled: bool | Callable[[], bool] = True, param: str | None = None) -> ListItemSP: + action = ToggleActionSP(initial_state=initial_state, enabled=enabled, callback=callback, param=param) + return ListItemSP(title=title, description=description, action_item=action, icon=icon, callback=callback) diff --git a/system/ui/sunnypilot/widgets/toggle.py b/system/ui/sunnypilot/widgets/toggle.py new file mode 100644 index 0000000000..46b390f773 --- /dev/null +++ b/system/ui/sunnypilot/widgets/toggle.py @@ -0,0 +1,56 @@ +""" +Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors. + +This file is part of sunnypilot and is licensed under the MIT License. +See the LICENSE.md file in the root directory for more details. +""" +from collections.abc import Callable + +import pyray as rl +from openpilot.common.params import Params +from openpilot.system.ui.lib.application import MousePos +from openpilot.system.ui.widgets.toggle import Toggle +from openpilot.system.ui.sunnypilot.lib.styles import style + +KNOB_PADDING = 5 +KNOB_RADIUS = style.TOGGLE_BG_HEIGHT / 2 - KNOB_PADDING + + +class ToggleSP(Toggle): + def __init__(self, initial_state=False, callback: Callable[[bool], None] | None = None, param: str | None = None): + self.param_key = param + self.params = Params() + if self.param_key: + initial_state = self.params.get_bool(self.param_key) + Toggle.__init__(self, initial_state, callback) + + def _handle_mouse_release(self, mouse_pos: MousePos): + super()._handle_mouse_release(mouse_pos) + if self._enabled and self.param_key: + self.params.put_bool(self.param_key, self._state) + + def _render(self, rect: rl.Rectangle): + self.update() + self._rect.y -= style.ITEM_PADDING / 2 + if self._enabled: + bg_color = self._blend_color(style.TOGGLE_OFF_COLOR, style.TOGGLE_ON_COLOR, self._progress) + knob_color = style.TOGGLE_KNOB_COLOR + else: + bg_color = self._blend_color(style.TOGGLE_DISABLED_OFF_COLOR, style.TOGGLE_DISABLED_ON_COLOR, self._progress) + knob_color = style.TOGGLE_DISABLED_KNOB_COLOR + + # Draw background + bg_rect = rl.Rectangle(self._rect.x, self._rect.y, style.TOGGLE_WIDTH, style.TOGGLE_BG_HEIGHT) + + # Draw actual background + rl.draw_rectangle_rounded(bg_rect, 1.0, 10, bg_color) + + left_edge = bg_rect.x + KNOB_PADDING + right_edge = bg_rect.x + bg_rect.width - KNOB_PADDING + + knob_travel_distance = right_edge - left_edge - 2 * KNOB_RADIUS + min_knob_x = left_edge + KNOB_RADIUS + knob_x = min_knob_x + knob_travel_distance * self._progress + knob_y = self._rect.y + style.TOGGLE_BG_HEIGHT / 2 + + rl.draw_circle(int(knob_x), int(knob_y), KNOB_RADIUS, knob_color) diff --git a/system/ui/widgets/network.py b/system/ui/widgets/network.py index f41a04c249..fa47d35536 100644 --- a/system/ui/widgets/network.py +++ b/system/ui/widgets/network.py @@ -15,6 +15,9 @@ from openpilot.system.ui.widgets.label import gui_label from openpilot.system.ui.widgets.scroller_tici import Scroller from openpilot.system.ui.widgets.list_view import ButtonAction, ListItem, MultipleButtonAction, ToggleAction, button_item, text_item +if gui_app.sunnypilot_ui(): + from openpilot.system.ui.sunnypilot.widgets.list_view import ToggleActionSP as ToggleAction + # These are only used for AdvancedNetworkSettings, standalone apps just need WifiManagerUI try: from openpilot.common.params import Params From a4ce6f1ca7b19f3126f0771109e4aee720143d53 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Fri, 21 Nov 2025 23:40:45 -0500 Subject: [PATCH 29/32] no --- system/ui/widgets/scroller.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/ui/widgets/scroller.py b/system/ui/widgets/scroller.py index 9d300750e8..9a04e84257 100644 --- a/system/ui/widgets/scroller.py +++ b/system/ui/widgets/scroller.py @@ -28,8 +28,8 @@ class LineSeparator(Widget): self._rect.width = parent_rect.width def _render(self, _): - rl.draw_line(int(self._rect.x), int(self._rect.y), - int(self._rect.x + self._rect.width), int(self._rect.y), + rl.draw_line(int(self._rect.x) + LINE_PADDING, int(self._rect.y), + int(self._rect.x + self._rect.width) - LINE_PADDING, int(self._rect.y), LINE_COLOR) From f81d8644345f96fd48d2e9a4a74a74d1269dd6ee Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Fri, 21 Nov 2025 23:44:23 -0500 Subject: [PATCH 30/32] more --- .../ui/sunnypilot/layouts/settings/device.py | 7 +++++ .../sunnypilot/layouts/settings/settings.py | 26 ++++++++++++------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/selfdrive/ui/sunnypilot/layouts/settings/device.py b/selfdrive/ui/sunnypilot/layouts/settings/device.py index 85aa79c8e8..081969cf10 100644 --- a/selfdrive/ui/sunnypilot/layouts/settings/device.py +++ b/selfdrive/ui/sunnypilot/layouts/settings/device.py @@ -1,5 +1,12 @@ +""" +Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors. + +This file is part of sunnypilot and is licensed under the MIT License. +See the LICENSE.md file in the root directory for more details. +""" from openpilot.selfdrive.ui.layouts.settings.device import DeviceLayout + class DeviceLayoutSP(DeviceLayout): def __init__(self): DeviceLayout.__init__(self) diff --git a/selfdrive/ui/sunnypilot/layouts/settings/settings.py b/selfdrive/ui/sunnypilot/layouts/settings/settings.py index 7460219530..9fa6244b45 100644 --- a/selfdrive/ui/sunnypilot/layouts/settings/settings.py +++ b/selfdrive/ui/sunnypilot/layouts/settings/settings.py @@ -1,13 +1,20 @@ -import pyray as rl +""" +Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors. + +This file is part of sunnypilot and is licensed under the MIT License. +See the LICENSE.md file in the root directory for more details. +""" from dataclasses import dataclass from enum import IntEnum + +import pyray as rl from openpilot.selfdrive.ui.layouts.settings import settings as OP from openpilot.selfdrive.ui.layouts.settings.developer import DeveloperLayout from openpilot.selfdrive.ui.sunnypilot.layouts.settings.device import DeviceLayoutSP from openpilot.selfdrive.ui.layouts.settings.firehose import FirehoseLayout from openpilot.selfdrive.ui.layouts.settings.software import SoftwareLayout from openpilot.selfdrive.ui.layouts.settings.toggles import TogglesLayout -from openpilot.system.ui.lib.application import gui_app,MousePos +from openpilot.system.ui.lib.application import gui_app, MousePos from openpilot.system.ui.lib.multilang import tr_noop from openpilot.system.ui.widgets.scroller_tici import Scroller from openpilot.system.ui.lib.text_measure import measure_text_cached @@ -23,12 +30,13 @@ from openpilot.selfdrive.ui.sunnypilot.layouts.settings.steering import Steering from openpilot.selfdrive.ui.sunnypilot.layouts.settings.cruise import CruiseLayout from openpilot.selfdrive.ui.sunnypilot.layouts.settings.visuals import VisualsLayout from openpilot.selfdrive.ui.sunnypilot.layouts.settings.display import DisplayLayout -#from openpilot.selfdrive.ui.sunnypilot.layouts.settings.navigation import NavigationLayout + +# from openpilot.selfdrive.ui.sunnypilot.layouts.settings.navigation import NavigationLayout OP.PANEL_COLOR = rl.Color(10, 10, 10, 255) ICON_SIZE = 70 -OP.PanelType = IntEnum( # type: ignore +OP.PanelType = IntEnum( # type: ignore "PanelType", [es.name for es in OP.PanelType] + [ "SUNNYLINK", @@ -43,7 +51,8 @@ OP.PanelType = IntEnum( # type: ignore "VEHICLE", ], start=0, - ) +) + @dataclass class PanelInfo(OP.PanelInfo): @@ -56,7 +65,7 @@ class SettingsLayoutSP(OP.SettingsLayout): self._nav_items: list[Widget] = [] # Create sidebar scroller - self._sidebar_scroller = Scroller([], spacing=0, line_separator = False, pad_end=False) + self._sidebar_scroller = Scroller([], spacing=0, line_separator=False, pad_end=False) # Panel configuration wifi_manager = WifiManager() @@ -74,7 +83,7 @@ class SettingsLayoutSP(OP.SettingsLayout): OP.PanelType.VISUALS: PanelInfo(tr_noop("Visuals"), VisualsLayout(), icon="../../sunnypilot/selfdrive/assets/offroad/icon_visuals.png"), OP.PanelType.DISPLAY: PanelInfo(tr_noop("Display"), DisplayLayout(), icon="../../sunnypilot/selfdrive/assets/offroad/icon_display.png"), OP.PanelType.OSM: PanelInfo(tr_noop("OSM"), OSMLayout(), icon="../../sunnypilot/selfdrive/assets/offroad/icon_map.png"), - #OP.PanelType.NAVIGATION: PanelInfo(tr_noop("Navigation"), NavigationLayout(), icon="../../sunnypilot/selfdrive/assets/offroad/icon_map.png"), + # OP.PanelType.NAVIGATION: PanelInfo(tr_noop("Navigation"), NavigationLayout(), icon="../../sunnypilot/selfdrive/assets/offroad/icon_map.png"), OP.PanelType.TRIPS: PanelInfo(tr_noop("Trips"), TripsLayout(), icon="../../sunnypilot/selfdrive/assets/offroad/icon_trips.png"), OP.PanelType.VEHICLE: PanelInfo(tr_noop("Vehicle"), VehicleLayout(), icon="../../sunnypilot/selfdrive/assets/offroad/icon_vehicle.png"), OP.PanelType.FIREHOSE: PanelInfo(tr_noop("Firehose"), FirehoseLayout(), icon="../../sunnypilot/selfdrive/assets/offroad/icon_firehose.png"), @@ -138,7 +147,7 @@ class SettingsLayoutSP(OP.SettingsLayout): close_btn_rect.y + (close_btn_rect.height - self._close_icon.height) / 2, self._close_icon.width, self._close_icon.height, - ) + ) rl.draw_texture_pro( self._close_icon, rl.Rectangle(0, 0, self._close_icon.width, self._close_icon.height), @@ -172,7 +181,6 @@ class SettingsLayoutSP(OP.SettingsLayout): self._sidebar_scroller.render(nav_rect) return - def _handle_mouse_release(self, mouse_pos: MousePos) -> bool: # Check close button if rl.check_collision_point_rec(mouse_pos, self._close_btn_rect): From f6fc098d16a90c9774a3ed17dc3f9b2db8a30c27 Mon Sep 17 00:00:00 2001 From: nayan Date: Fri, 21 Nov 2025 23:51:16 -0500 Subject: [PATCH 31/32] size adjustments --- selfdrive/ui/sunnypilot/layouts/settings/settings.py | 7 ++++--- system/ui/sunnypilot/lib/styles.py | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/selfdrive/ui/sunnypilot/layouts/settings/settings.py b/selfdrive/ui/sunnypilot/layouts/settings/settings.py index 7460219530..21f39b3b46 100644 --- a/selfdrive/ui/sunnypilot/layouts/settings/settings.py +++ b/selfdrive/ui/sunnypilot/layouts/settings/settings.py @@ -9,6 +9,7 @@ from openpilot.selfdrive.ui.layouts.settings.software import SoftwareLayout from openpilot.selfdrive.ui.layouts.settings.toggles import TogglesLayout from openpilot.system.ui.lib.application import gui_app,MousePos from openpilot.system.ui.lib.multilang import tr_noop +from openpilot.system.ui.sunnypilot.lib.styles import style from openpilot.system.ui.widgets.scroller_tici import Scroller from openpilot.system.ui.lib.text_measure import measure_text_cached from openpilot.system.ui.widgets.network import NetworkUI @@ -98,7 +99,7 @@ class SettingsLayoutSP(OP.SettingsLayout): # Draw background if selected if is_selected: self.container_rect = rl.Rectangle( - content_x - 20, rect.y, OP.SIDEBAR_WIDTH - 70, OP.NAV_BTN_HEIGHT + content_x - 50, rect.y, OP.SIDEBAR_WIDTH - 50, OP.NAV_BTN_HEIGHT ) rl.draw_rectangle_rounded(self.container_rect, 0.2, 5, OP.CLOSE_BTN_COLOR) @@ -124,7 +125,7 @@ class SettingsLayoutSP(OP.SettingsLayout): # Close button close_btn_rect = rl.Rectangle( - rect.x + (rect.width - OP.CLOSE_BTN_SIZE) / 2, rect.y + 60, OP.CLOSE_BTN_SIZE, OP.CLOSE_BTN_SIZE + rect.x + style.ITEM_PADDING * 3, rect.y + style.ITEM_PADDING * 2, style.CLOSE_BTN_SIZE, style.CLOSE_BTN_SIZE ) pressed = (rl.is_mouse_button_down(rl.MouseButton.MOUSE_BUTTON_LEFT) and @@ -163,7 +164,7 @@ class SettingsLayoutSP(OP.SettingsLayout): # Draw navigation section with scroller nav_rect = rl.Rectangle( rect.x, - rect.y + 300, # Starting Y position for nav items + self._close_btn_rect.height + style.ITEM_PADDING * 4, # Starting Y position for nav items rect.width, rect.height - 300 # Remaining height after close button ) diff --git a/system/ui/sunnypilot/lib/styles.py b/system/ui/sunnypilot/lib/styles.py index a232ac192d..f87894a6b1 100644 --- a/system/ui/sunnypilot/lib/styles.py +++ b/system/ui/sunnypilot/lib/styles.py @@ -17,6 +17,7 @@ class Base: ITEM_TEXT_FONT_SIZE = 50 ITEM_DESC_FONT_SIZE = 40 ITEM_DESC_V_OFFSET = 150 + CLOSE_BTN_SIZE = 160 # Toggle Control TOGGLE_HEIGHT = 120 From 60da05f428d17feb5db383a6e065c69880f87e6e Mon Sep 17 00:00:00 2001 From: nayan Date: Sun, 23 Nov 2025 00:02:06 -0500 Subject: [PATCH 32/32] fix scroller. yay --- system/ui/lib/scroll_panel.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/system/ui/lib/scroll_panel.py b/system/ui/lib/scroll_panel.py index a5b9fc70d3..6dd9ceaadc 100644 --- a/system/ui/lib/scroll_panel.py +++ b/system/ui/lib/scroll_panel.py @@ -41,8 +41,12 @@ class GuiScrollPanel: if DEBUG: rl.draw_rectangle_lines(0, 0, abs(int(self._velocity_filter_y.x)), 10, rl.RED) - # Handle mouse wheel - self._offset_filter_y.x += rl.get_mouse_wheel_move() * MOUSE_WHEEL_SCROLL_SPEED + # Handle mouse wheel only when the mouse cursor is over this panel + mouse_wheel = rl.get_mouse_wheel_move() + if mouse_wheel != 0: + mouse_pos = rl.get_mouse_position() + if rl.check_collision_point_rec(mouse_pos, bounds): + self._offset_filter_y.x += mouse_wheel * MOUSE_WHEEL_SCROLL_SPEED max_scroll_distance = max(0, content.height - bounds.height) if self._scroll_state == ScrollState.IDLE: