[TIZI/TICI] ui: Developer UI cleanup (#1746)

* [TIZI/TICI] ui: Developer UI cleanup

* why 61
This commit is contained in:
Jason Wen
2026-03-01 02:07:23 -05:00
committed by GitHub
parent 7b104c682b
commit cfc28176f2
4 changed files with 27 additions and 25 deletions
@@ -9,7 +9,7 @@ import pyray as rl
from cereal import log
from openpilot.selfdrive.ui import UI_BORDER_SIZE
from openpilot.selfdrive.ui.ui_state import ui_state
from openpilot.selfdrive.ui.sunnypilot.onroad.developer_ui import DeveloperUiRenderer
from openpilot.selfdrive.ui.sunnypilot.onroad.developer_ui import DeveloperUiState
from openpilot.system.ui.lib.application import gui_app, FontWeight, FONT_SCALE
from openpilot.system.ui.lib.text_measure import measure_text_cached
@@ -77,7 +77,7 @@ class CircularAlertsRenderer:
return
e2e_alert_size = 250
dev_ui_width_adjustment = 180 if ui_state.developer_ui in (DeveloperUiRenderer.DEV_UI_RIGHT, DeveloperUiRenderer.DEV_UI_BOTH) else 100
dev_ui_width_adjustment = 180 if ui_state.developer_ui in (DeveloperUiState.RIGHT, DeveloperUiState.BOTH) else 100
x = rect.x + rect.width - e2e_alert_size - dev_ui_width_adjustment - (UI_BORDER_SIZE * 3)
y = rect.y + rect.height / 2 + 20
@@ -4,6 +4,8 @@ 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 enum import IntEnum
import pyray as rl
from openpilot.selfdrive.ui.ui_state import ui_state
from openpilot.selfdrive.ui.sunnypilot.onroad.developer_ui.elements import (
@@ -17,18 +19,25 @@ from openpilot.system.ui.lib.text_measure import measure_text_cached
from openpilot.system.ui.widgets import Widget
class DeveloperUiRenderer(Widget):
DEV_UI_OFF = 0
DEV_UI_BOTTOM = 1
DEV_UI_RIGHT = 2
DEV_UI_BOTH = 3
BOTTOM_BAR_HEIGHT = 61
def get_bottom_dev_ui_offset():
if ui_state.developer_ui in (DeveloperUiState.BOTTOM, DeveloperUiState.BOTH):
return 60
return 0
class DeveloperUiState(IntEnum):
OFF = 0
BOTTOM = 1
RIGHT = 2
BOTH = 3
class DeveloperUiRenderer(Widget):
def __init__(self):
super().__init__()
self._font_bold: rl.Font = gui_app.font(FontWeight.BOLD)
self._font_semi_bold: rl.Font = gui_app.font(FontWeight.SEMI_BOLD)
self.dev_ui_mode = self.DEV_UI_OFF
self.dev_ui_mode = DeveloperUiState.OFF
self.rel_dist_elem = RelDistElement()
self.rel_speed_elem = RelSpeedElement()
@@ -45,28 +54,22 @@ class DeveloperUiRenderer(Widget):
self.bearing_elem = BearingDegElement()
self.altitude_elem = AltitudeElement()
@staticmethod
def get_bottom_dev_ui_offset():
if ui_state.developer_ui in (DeveloperUiRenderer.DEV_UI_BOTTOM, DeveloperUiRenderer.DEV_UI_BOTH):
return DeveloperUiRenderer.BOTTOM_BAR_HEIGHT
return 0
def _update_state(self) -> None:
self.dev_ui_mode = ui_state.developer_ui
def _render(self, rect: rl.Rectangle) -> None:
if self.dev_ui_mode == self.DEV_UI_OFF:
if self.dev_ui_mode == DeveloperUiState.OFF:
return
sm = ui_state.sm
if sm.recv_frame["carState"] < ui_state.started_frame:
return
if self.dev_ui_mode == self.DEV_UI_BOTTOM:
if self.dev_ui_mode == DeveloperUiState.BOTTOM:
self._draw_bottom_dev_ui(rect)
elif self.dev_ui_mode == self.DEV_UI_RIGHT:
elif self.dev_ui_mode == DeveloperUiState.RIGHT:
self._draw_right_dev_ui(rect)
elif self.dev_ui_mode == self.DEV_UI_BOTH:
elif self.dev_ui_mode == DeveloperUiState.BOTH:
self._draw_right_dev_ui(rect)
self._draw_bottom_dev_ui(rect)
@@ -8,13 +8,12 @@ import numpy as np
from openpilot.selfdrive.ui import UI_BORDER_SIZE
from openpilot.selfdrive.ui.onroad.driver_state import DriverStateRenderer, BTN_SIZE, ARC_LENGTH
from openpilot.selfdrive.ui.sunnypilot.onroad.developer_ui import DeveloperUiRenderer
from openpilot.selfdrive.ui.sunnypilot.onroad.developer_ui import get_bottom_dev_ui_offset
class DriverStateRendererSP(DriverStateRenderer):
def __init__(self):
super().__init__()
self.dev_ui_offset = DeveloperUiRenderer.get_bottom_dev_ui_offset()
def _pre_calculate_drawing_elements(self):
"""Pre-calculate all drawing elements based on the current rectangle"""
@@ -22,7 +21,7 @@ class DriverStateRendererSP(DriverStateRenderer):
width, height = self._rect.width, self._rect.height
offset = UI_BORDER_SIZE + BTN_SIZE // 2
self.position_x = self._rect.x + (width - offset if self.is_rhd else offset)
self.position_y = self._rect.y + height - offset - self.dev_ui_offset
self.position_y = self._rect.y + height - offset - get_bottom_dev_ui_offset()
# Pre-calculate the face lines positions
positioned_keypoints = self.face_keypoints_transformed + np.array([self.position_x, self.position_y])
@@ -8,7 +8,7 @@ import pyray as rl
from openpilot.common.constants import CV
from openpilot.selfdrive.ui.mici.onroad.torque_bar import TorqueBar
from openpilot.selfdrive.ui.sunnypilot.onroad.developer_ui import DeveloperUiRenderer
from openpilot.selfdrive.ui.sunnypilot.onroad.developer_ui import DeveloperUiRenderer, DeveloperUiState, get_bottom_dev_ui_offset
from openpilot.selfdrive.ui.sunnypilot.onroad.road_name import RoadNameRenderer
from openpilot.selfdrive.ui.sunnypilot.onroad.rocket_fuel import RocketFuel
from openpilot.selfdrive.ui.sunnypilot.onroad.speed_limit import SpeedLimitRenderer
@@ -133,8 +133,8 @@ class HudRendererSP(HudRenderer):
if ui_state.torque_bar and ui_state.sm['controlsState'].lateralControlState.which() != 'angleState':
torque_rect = rect
if ui_state.developer_ui in (DeveloperUiRenderer.DEV_UI_BOTTOM, DeveloperUiRenderer.DEV_UI_BOTH):
torque_rect = rl.Rectangle(rect.x, rect.y, rect.width, rect.height - DeveloperUiRenderer.BOTTOM_BAR_HEIGHT)
if ui_state.developer_ui in (DeveloperUiState.BOTTOM, DeveloperUiState.BOTH):
torque_rect = rl.Rectangle(rect.x, rect.y, rect.width, rect.height - get_bottom_dev_ui_offset())
self._torque_bar.render(torque_rect)
self.developer_ui.render(rect)