From 359d213711bc45f1946b46350e7d79c0061da2cc Mon Sep 17 00:00:00 2001 From: rav4kumar Date: Mon, 29 Dec 2025 14:10:34 -0700 Subject: [PATCH] road name --- selfdrive/ui/onroad/hud_renderer.py | 4 ++ selfdrive/ui/sunnypilot/onroad/road_name.py | 49 +++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 selfdrive/ui/sunnypilot/onroad/road_name.py diff --git a/selfdrive/ui/onroad/hud_renderer.py b/selfdrive/ui/onroad/hud_renderer.py index afd7f01cf6..45c9cf9ee2 100644 --- a/selfdrive/ui/onroad/hud_renderer.py +++ b/selfdrive/ui/onroad/hud_renderer.py @@ -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 diff --git a/selfdrive/ui/sunnypilot/onroad/road_name.py b/selfdrive/ui/sunnypilot/onroad/road_name.py new file mode 100644 index 0000000000..903e96606b --- /dev/null +++ b/selfdrive/ui/sunnypilot/onroad/road_name.py @@ -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))