BigUI WIP: Onroad Cleaner-er

This commit is contained in:
firestarsdog
2026-05-21 13:47:56 -04:00
parent a94c3b72d3
commit 3f4f2a1813
9 changed files with 47 additions and 23 deletions
@@ -5,7 +5,7 @@ from enum import IntEnum
import pyray as rl
from openpilot.common.params import Params
from openpilot.common.params import Params, UnknownKeyName
from openpilot.system.ui.lib.multilang import tr
from openpilot.system.ui.lib.application import gui_app
from openpilot.system.ui.widgets import DialogResult, Widget
@@ -45,27 +45,42 @@ class StarPilotParamsProxy:
self._params_memory.put_bool("StarPilotTogglesUpdated", True)
def put(self, key, value):
result = self._params.put(key, value)
try:
result = self._params.put(key, value)
except UnknownKeyName:
return None
self._mark_updated()
return result
def put_bool(self, key, value):
result = self._params.put_bool(key, value)
try:
result = self._params.put_bool(key, value)
except UnknownKeyName:
return None
self._mark_updated()
return result
def put_int(self, key, value):
result = self._params.put_int(key, value)
try:
result = self._params.put_int(key, value)
except UnknownKeyName:
return None
self._mark_updated()
return result
def put_float(self, key, value):
result = self._params.put_float(key, value)
try:
result = self._params.put_float(key, value)
except UnknownKeyName:
return None
self._mark_updated()
return result
def remove(self, key):
result = self._params.remove(key)
try:
result = self._params.remove(key)
except UnknownKeyName:
return None
self._mark_updated()
return result
+3 -2
View File
@@ -15,6 +15,7 @@ from openpilot.selfdrive.ui.onroad.cameraview import CameraView
from openpilot.selfdrive.ui.lib.starpilot_mode_banner import ModeTransitionBanner
from openpilot.selfdrive.ui.lib.starpilot_status import get_screen_edge_color
from openpilot.system.ui.lib.application import gui_app, FontWeight
from openpilot.system.ui.lib.text_measure import measure_text_cached
from openpilot.common.transformations.camera import DEVICE_CAMERAS, DeviceCameraConfig, view_frame_from_device_frame
from openpilot.common.transformations.orientation import rot_from_euler
@@ -121,10 +122,10 @@ class MinSteerSpeedBanner:
text = self._get_message(min_steer_speed)
font_size = 52
max_text_width = rect.width - 100
text_size = rl.measure_text_ex(self._font, text, font_size, 0)
text_size = measure_text_cached(self._font, text, font_size)
while font_size > 36 and text_size.x > max_text_width:
font_size -= 2
text_size = rl.measure_text_ex(self._font, text, font_size, 0)
text_size = measure_text_cached(self._font, text, font_size)
text_pos = rl.Vector2(
rect.x + (rect.width - text_size.x) / 2,
+3 -2
View File
@@ -12,6 +12,7 @@ from openpilot.selfdrive.ui.lib.starpilot_visuals import lead_indicator_enabled
from openpilot.selfdrive.ui.ui_state import ui_state, UIStatus
from openpilot.system.ui.lib.application import gui_app
from openpilot.system.ui.lib.shader_polygon import draw_polygon, Gradient
from openpilot.system.ui.lib.text_measure import measure_text_cached
from openpilot.system.ui.widgets import Widget
CLIP_MARGIN = 500
@@ -562,7 +563,7 @@ class ModelRenderer(Widget):
max_text_width = 0.0
for line in text_lines:
sz = rl.measure_text_ex(font, line, font_size, 0)
sz = measure_text_cached(font, line, font_size)
if sz.x > max_text_width:
max_text_width = sz.x
@@ -593,7 +594,7 @@ class ModelRenderer(Widget):
self._lead_text_rects.append(text_rect)
for i, line in enumerate(text_lines):
sz = rl.measure_text_ex(font, line, font_size, 0)
sz = measure_text_cached(font, line, font_size)
line_x = centerX - sz.x / 2
line_y = startY + (i * line_height)
_draw_text_with_outline(line, line_x, line_y, font, font_size)
+2 -1
View File
@@ -1,6 +1,7 @@
import pyray as rl
from openpilot.selfdrive.ui.ui_state import ui_state
from openpilot.selfdrive.ui.lib.starpilot_status import CEM_OVERRIDE_COLOR, EXPERIMENTAL_COLOR
from openpilot.system.ui.lib.text_measure import measure_text_cached
def render_cem_status(rect: rl.Rectangle, font):
if not ui_state.params.get_bool("ShowCEMStatus"):
@@ -41,7 +42,7 @@ def render_cem_status(rect: rl.Rectangle, font):
# Draw text label centered inside the badge
font_size = 20
text_sz = rl.measure_text_ex(font, label, font_size, 0)
text_sz = measure_text_cached(font, label, font_size)
pos_x = rect.x + (rect.width - text_sz.x) / 2
pos_y = rect.y + (rect.height - text_sz.y) / 2
rl.draw_text_ex(font, label, rl.Vector2(int(pos_x), int(pos_y)), font_size, 0, rl.WHITE)
+2 -1
View File
@@ -1,5 +1,6 @@
import pyray as rl
from openpilot.selfdrive.ui.ui_state import ui_state
from openpilot.system.ui.lib.text_measure import measure_text_cached
def render_compass(rect: rl.Rectangle, font):
if not ui_state.params.get_bool("Compass"):
@@ -47,7 +48,7 @@ def render_compass(rect: rl.Rectangle, font):
notch_width = 3
lbl = labels.get(norm_deg, "")
if lbl:
lbl_sz = rl.measure_text_ex(font, lbl, 22, 0)
lbl_sz = measure_text_cached(font, lbl, 22)
rl.draw_text_ex(font, lbl, rl.Vector2(int(x - lbl_sz.x / 2), int(rect.y + 12)), 22, 0, rl.WHITE)
elif norm_deg % 15 == 0:
notch_height = 15
@@ -2,6 +2,7 @@ import pyray as rl
import math
from openpilot.common.constants import CV
from openpilot.selfdrive.ui.ui_state import ui_state
from openpilot.system.ui.lib.text_measure import measure_text_cached
def render_csc_force_stop(content_rect: rl.Rectangle, font_bold):
plan = ui_state.sm["starpilotPlan"] if ui_state.sm.valid.get("starpilotPlan", False) else None
@@ -65,7 +66,7 @@ def render_csc_force_stop(content_rect: rl.Rectangle, font_bold):
dist_val = int(round(forcing_stop_length * distance_conversion))
text = f"{dist_val} {dist_unit}"
text_sz = rl.measure_text_ex(font_bold, text, 40, 0)
text_sz = measure_text_cached(font_bold, text, 40)
rl.draw_text_ex(font_bold, text, rl.Vector2(int(csc_x + 20), int(badge_rect.y + (100 - text_sz.y) / 2)), 40, 0, rl.WHITE)
else:
@@ -121,5 +122,5 @@ def render_csc_force_stop(content_rect: rl.Rectangle, font_bold):
csc_speed_val = int(round(min(v_ego, csc_speed) * speed_conversion))
text = f"{csc_speed_val} {speed_unit}"
text_sz = rl.measure_text_ex(font_bold, text, 40, 0)
text_sz = measure_text_cached(font_bold, text, 40)
rl.draw_text_ex(font_bold, text, rl.Vector2(int(csc_x + 20), int(badge_rect.y + (100 - text_sz.y) / 2)), 40, 0, rl.WHITE)
+4 -2
View File
@@ -10,6 +10,7 @@ from openpilot.selfdrive.ui.lib.starpilot_theme import get_param_color, get_them
from openpilot.selfdrive.ui.ui_state import ui_state
from openpilot.system.ui.lib.application import gui_app, FontWeight
from openpilot.system.ui.lib.shader_polygon import draw_polygon, Gradient
from openpilot.system.ui.lib.text_measure import measure_text_cached
_METRICS_FONT_SIZE = 45
_STOCK_LINE_GREEN = rl.Color(0, 255, 0, 241)
@@ -88,8 +89,9 @@ def render_adjacent_paths(renderer) -> None:
right = verts[mid_index + (len(verts) - mid_index) // 2]
text = f"{lane_width * distance_conversion:.2f}{unit}"
text_width = rl.measure_text_ex(font, text, _METRICS_FONT_SIZE, 0).x
text_height = rl.measure_text_ex(font, text, _METRICS_FONT_SIZE, 0).y
text_sz = measure_text_cached(font, text, _METRICS_FONT_SIZE)
text_width = text_sz.x
text_height = text_sz.y
text_x = (left[0] + right[0]) / 2.0 - text_width / 2.0
text_y = (left[1] + right[1]) / 2.0 - text_height / 2.0 + text_height * 0.75
@@ -13,6 +13,7 @@ from openpilot.selfdrive.ui.onroad.starpilot.slc_speed_limit import (
from openpilot.selfdrive.ui.ui_state import ui_state
from openpilot.selfdrive.ui.lib.starpilot_status import get_screen_edge_color
from openpilot.system.ui.lib.application import MousePos, gui_app, FontWeight
from openpilot.system.ui.lib.text_measure import measure_text_cached
class StarPilotOnroadView(AugmentedRoadView):
@@ -117,7 +118,7 @@ class StarPilotOnroadView(AugmentedRoadView):
if not road_name:
return
text_size = rl.measure_text_ex(self._font_bold, road_name, 52, 0)
text_size = measure_text_cached(self._font_bold, road_name, 52)
pad_x, pad_y = 28, 18
box_w = int(text_size.x + pad_x * 2)
box_h = int(text_size.y + pad_y * 2)
@@ -162,8 +163,8 @@ class StarPilotOnroadView(AugmentedRoadView):
seconds = duration % 60
minute_text = f"{minutes} minute{'s' if minutes != 1 else ''}"
second_text = f"{seconds} second{'s' if seconds != 1 else ''}"
minute_size = rl.measure_text_ex(self._font_bold, minute_text, 176, 0)
second_size = rl.measure_text_ex(self._font_medium, second_text, 66, 0)
minute_size = measure_text_cached(self._font_bold, minute_text, 176)
second_size = measure_text_cached(self._font_medium, second_text, 66)
from openpilot.selfdrive.ui.lib.starpilot_status import ENGAGED_COLOR, EXPERIMENTAL_COLOR, TRAFFIC_COLOR
import numpy as np
@@ -298,12 +299,12 @@ class StarPilotOnroadView(AugmentedRoadView):
x = self._content_rect.x + self._content_rect.width - 30
y = self._content_rect.y + 40
for i, line in enumerate(text_lines):
sz = rl.measure_text_ex(font, line, font_size, 0)
sz = measure_text_cached(font, line, font_size)
draw_text_with_outline(line, x - sz.x, y + i * line_height, rl.WHITE)
# 2. Render bottom-center detailed FPS tracker string (min/max/avg)
fps_str = f"FPS: {round(fps)} | Min: {round(self._min_fps)} | Max: {round(self._max_fps)} | Avg: {round(self._avg_fps)}"
sz = rl.measure_text_ex(font, fps_str, font_size, 0)
sz = measure_text_cached(font, fps_str, font_size)
bx = self._content_rect.x + (self._content_rect.width - sz.x) / 2
by = self._content_rect.y + self._content_rect.height - sz.y - 10
draw_text_with_outline(fps_str, bx, by, rl.WHITE)
@@ -1,5 +1,6 @@
import pyray as rl
from openpilot.selfdrive.ui.ui_state import ui_state
from openpilot.system.ui.lib.text_measure import measure_text_cached
def render_stopping_point(renderer, font):
params = ui_state.params
@@ -36,7 +37,7 @@ def render_stopping_point(renderer, font):
# Draw "STOP" text centered in octagon
font_size = 18
lbl_sz = rl.measure_text_ex(font, "STOP", font_size, 0)
lbl_sz = measure_text_cached(font, "STOP", font_size)
rl.draw_text_ex(
font, "STOP",
rl.Vector2(int(cx - lbl_sz.x / 2), int(cy - radius - lbl_sz.y / 2)),
@@ -51,7 +52,7 @@ def render_stopping_point(renderer, font):
else:
dist_text = f"{int(round(stopping_distance * 3.28084))} ft"
text_sz = rl.measure_text_ex(font, dist_text, 24, 0)
text_sz = measure_text_cached(font, dist_text, 24)
tx = cx - text_sz.x / 2
ty = cy - radius * 2 - text_sz.y - 5