|
|
|
@ -2,7 +2,6 @@ import pyray as rl |
|
|
|
|
from dataclasses import dataclass |
|
|
|
|
from enum import IntEnum |
|
|
|
|
from collections.abc import Callable |
|
|
|
|
from openpilot.common.params import Params |
|
|
|
|
from openpilot.selfdrive.ui.layouts.settings.developer import DeveloperLayout |
|
|
|
|
from openpilot.selfdrive.ui.layouts.settings.device import DeviceLayout |
|
|
|
|
from openpilot.selfdrive.ui.layouts.settings.firehose import FirehoseLayout |
|
|
|
@ -21,7 +20,6 @@ SIDEBAR_WIDTH = 500 |
|
|
|
|
CLOSE_BTN_SIZE = 200 |
|
|
|
|
NAV_BTN_HEIGHT = 80 |
|
|
|
|
PANEL_MARGIN = 50 |
|
|
|
|
SCROLL_SPEED = 30 |
|
|
|
|
|
|
|
|
|
# Colors |
|
|
|
|
SIDEBAR_COLOR = rl.BLACK |
|
|
|
@ -30,7 +28,6 @@ CLOSE_BTN_COLOR = rl.Color(41, 41, 41, 255) |
|
|
|
|
CLOSE_BTN_PRESSED = rl.Color(59, 59, 59, 255) |
|
|
|
|
TEXT_NORMAL = rl.Color(128, 128, 128, 255) |
|
|
|
|
TEXT_SELECTED = rl.Color(255, 255, 255, 255) |
|
|
|
|
TEXT_PRESSED = rl.Color(173, 173, 173, 255) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PanelType(IntEnum): |
|
|
|
@ -46,24 +43,22 @@ class PanelType(IntEnum): |
|
|
|
|
class PanelInfo: |
|
|
|
|
name: str |
|
|
|
|
instance: object |
|
|
|
|
button_rect: rl.Rectangle |
|
|
|
|
button_rect: rl.Rectangle = rl.Rectangle(0, 0, 0, 0) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SettingsLayout(Widget): |
|
|
|
|
def __init__(self): |
|
|
|
|
super().__init__() |
|
|
|
|
self._params = Params() |
|
|
|
|
self._current_panel = PanelType.DEVICE |
|
|
|
|
self._max_scroll = 0.0 |
|
|
|
|
|
|
|
|
|
# Panel configuration |
|
|
|
|
self._panels = { |
|
|
|
|
PanelType.DEVICE: PanelInfo("Device", DeviceLayout(), rl.Rectangle(0, 0, 0, 0)), |
|
|
|
|
PanelType.NETWORK: PanelInfo("Network", NetworkLayout(), rl.Rectangle(0, 0, 0, 0)), |
|
|
|
|
PanelType.TOGGLES: PanelInfo("Toggles", TogglesLayout(), rl.Rectangle(0, 0, 0, 0)), |
|
|
|
|
PanelType.SOFTWARE: PanelInfo("Software", SoftwareLayout(), rl.Rectangle(0, 0, 0, 0)), |
|
|
|
|
PanelType.FIREHOSE: PanelInfo("Firehose", FirehoseLayout(), rl.Rectangle(0, 0, 0, 0)), |
|
|
|
|
PanelType.DEVELOPER: PanelInfo("Developer", DeveloperLayout(), rl.Rectangle(0, 0, 0, 0)), |
|
|
|
|
PanelType.DEVICE: PanelInfo("Device", DeviceLayout()), |
|
|
|
|
PanelType.NETWORK: PanelInfo("Network", NetworkLayout()), |
|
|
|
|
PanelType.TOGGLES: PanelInfo("Toggles", TogglesLayout()), |
|
|
|
|
PanelType.SOFTWARE: PanelInfo("Software", SoftwareLayout()), |
|
|
|
|
PanelType.FIREHOSE: PanelInfo("Firehose", FirehoseLayout()), |
|
|
|
|
PanelType.DEVELOPER: PanelInfo("Developer", DeveloperLayout()), |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
self._font_medium = gui_app.font(FontWeight.MEDIUM) |
|
|
|
@ -108,17 +103,11 @@ class SettingsLayout(Widget): |
|
|
|
|
self._close_btn_rect = close_btn_rect |
|
|
|
|
|
|
|
|
|
# Navigation buttons |
|
|
|
|
nav_start_y = rect.y + 300 |
|
|
|
|
y = rect.y + 300 |
|
|
|
|
button_spacing = 20 |
|
|
|
|
|
|
|
|
|
i = 0 |
|
|
|
|
for panel_type, panel_info in self._panels.items(): |
|
|
|
|
button_rect = rl.Rectangle( |
|
|
|
|
rect.x + 50, |
|
|
|
|
nav_start_y + i * (NAV_BTN_HEIGHT + button_spacing), |
|
|
|
|
rect.width - 150, # Right-aligned with margin |
|
|
|
|
NAV_BTN_HEIGHT, |
|
|
|
|
) |
|
|
|
|
button_rect = rl.Rectangle(rect.x + 50, y, rect.width - 150, NAV_BTN_HEIGHT) |
|
|
|
|
|
|
|
|
|
# Button styling |
|
|
|
|
is_selected = panel_type == self._current_panel |
|
|
|
@ -132,7 +121,8 @@ class SettingsLayout(Widget): |
|
|
|
|
|
|
|
|
|
# Store button rect for click detection |
|
|
|
|
panel_info.button_rect = button_rect |
|
|
|
|
i += 1 |
|
|
|
|
|
|
|
|
|
y += NAV_BTN_HEIGHT + button_spacing |
|
|
|
|
|
|
|
|
|
def _draw_current_panel(self, rect: rl.Rectangle): |
|
|
|
|
rl.draw_rectangle_rounded( |
|
|
|
@ -154,20 +144,15 @@ class SettingsLayout(Widget): |
|
|
|
|
# Check navigation buttons |
|
|
|
|
for panel_type, panel_info in self._panels.items(): |
|
|
|
|
if rl.check_collision_point_rec(mouse_pos, panel_info.button_rect): |
|
|
|
|
self._switch_to_panel(panel_type) |
|
|
|
|
self.set_current_panel(panel_type) |
|
|
|
|
return True |
|
|
|
|
|
|
|
|
|
return False |
|
|
|
|
|
|
|
|
|
def _switch_to_panel(self, panel_type: PanelType): |
|
|
|
|
def set_current_panel(self, panel_type: PanelType): |
|
|
|
|
if panel_type != self._current_panel: |
|
|
|
|
self._current_panel = panel_type |
|
|
|
|
|
|
|
|
|
def set_current_panel(self, index: int, param: str = ""): |
|
|
|
|
panel_types = list(self._panels.keys()) |
|
|
|
|
if 0 <= index < len(panel_types): |
|
|
|
|
self._switch_to_panel(panel_types[index]) |
|
|
|
|
|
|
|
|
|
def close_settings(self): |
|
|
|
|
if self._close_callback: |
|
|
|
|
self._close_callback() |
|
|
|
|