road name

This commit is contained in:
rav4kumar
2025-12-29 14:10:34 -07:00
parent ffaf0a990e
commit 359d213711
2 changed files with 53 additions and 0 deletions
+4
View File
@@ -4,6 +4,7 @@ from openpilot.common.constants import CV
from openpilot.selfdrive.ui.onroad.exp_button import ExpButton
from openpilot.selfdrive.ui.ui_state import ui_state, UIStatus
from openpilot.selfdrive.ui.sunnypilot.onroad.speed_limit_ui import SpeedLimitRenderer
from openpilot.selfdrive.ui.sunnypilot.onroad.road_name import RoadNameRenderer
from openpilot.system.ui.lib.application import gui_app, FontWeight
from openpilot.system.ui.lib.multilang import tr
from openpilot.system.ui.lib.text_measure import measure_text_cached
@@ -68,6 +69,7 @@ class HudRenderer(Widget):
self.v_ego_cluster_seen: bool = False
self._speed_limit_renderer = SpeedLimitRenderer()
self._road_name_renderer = RoadNameRenderer()
self._font_semi_bold: rl.Font = gui_app.font(FontWeight.SEMI_BOLD)
self._font_bold: rl.Font = gui_app.font(FontWeight.BOLD)
@@ -79,6 +81,7 @@ class HudRenderer(Widget):
"""Update HUD state based on car state and controls state."""
self._speed_limit_renderer._update_state()
self._road_name_renderer._update_state()
sm = ui_state.sm
if sm.recv_frame["carState"] < ui_state.started_frame:
@@ -124,6 +127,7 @@ class HudRenderer(Widget):
self._draw_current_speed(rect)
self._speed_limit_renderer.render(rect)
self._road_name_renderer.render(rect)
button_x = rect.x + rect.width - UI_CONFIG.border_size - UI_CONFIG.button_size
button_y = rect.y + UI_CONFIG.border_size
@@ -0,0 +1,49 @@
import pyray as rl
from openpilot.selfdrive.ui.ui_state import ui_state
from openpilot.system.ui.lib.application import gui_app, FontWeight
from openpilot.system.ui.lib.text_measure import measure_text_cached
from openpilot.system.ui.widgets import Widget
class RoadNameRenderer(Widget):
def __init__(self):
super().__init__()
self.road_name = ""
self.is_metric = False
self.font_demi = gui_app.font(FontWeight.SEMI_BOLD)
def _update_state(self):
sm = ui_state.sm
if sm.recv_frame["carState"] < ui_state.started_frame:
return
self.is_metric = ui_state.is_metric
if sm.updated["liveMapDataSP"]:
lmd = sm["liveMapDataSP"]
self.road_name = lmd.roadName
def _render(self, rect: rl.Rectangle):
if not self.road_name:
return
text = self.road_name
text_size = measure_text_cached(self.font_demi, text, 46)
padding = 40
rect_width = max(200, min(text_size.x + padding, rect.width - 40))
road_rect = rl.Rectangle(rect.x + rect.width / 2 - rect_width / 2, rect.y - 4, rect_width, 60)
rl.draw_rectangle_rounded(road_rect, 0.2, 10, rl.Color(0, 0, 0, 120))
max_text_width = road_rect.width - 20
if text_size.x > max_text_width:
while text_size.x > max_text_width and len(text) > 3:
text = text[:-1]
text_size = measure_text_cached(self.font_demi, text + "...", 46)
text = text + "..."
sz = measure_text_cached(self.font_demi, text, 46)
origin = rl.Vector2(road_rect.x + road_rect.width / 2 - sz.x / 2, road_rect.y + road_rect.height / 2 - sz.y / 2)
rl.draw_text_ex(self.font_demi, text, origin, 46, 0, rl.Color(255, 255, 255, 200))