ui: add debug toggle (#36529)

* ui: add debug toggle

* initial state
This commit is contained in:
Adeeb Shihadeh
2025-10-30 15:52:56 -07:00
committed by GitHub
parent 76c5cb6d87
commit c4a0e57046
3 changed files with 28 additions and 6 deletions

View File

@@ -108,6 +108,7 @@ inline static std::unordered_map<std::string, ParamKeyAttributes> keys = {
{"RecordFront", {PERSISTENT, BOOL}},
{"RecordFrontLock", {PERSISTENT, BOOL}}, // for the internal fleet
{"SecOCKey", {PERSISTENT | DONT_LOG, STRING}},
{"ShowDebugInfo", {PERSISTENT, BOOL}},
{"RouteCount", {PERSISTENT, INT, "0"}},
{"SnoozeUpdate", {CLEAR_ON_MANAGER_START | CLEAR_ON_OFFROAD_TRANSITION, BOOL}},
{"SshEnabled", {PERSISTENT, BOOL}},

View File

@@ -75,16 +75,23 @@ class DeveloperLayout(Widget):
enabled=lambda: not ui_state.engaged,
)
items = [
self._ui_debug_toggle = toggle_item(
lambda: tr("UI Debug Mode"),
description="",
initial_state=self._params.get_bool("ShowDebugInfo"),
callback=self._on_enable_ui_debug,
)
self._on_enable_ui_debug(self._params.get_bool("ShowDebugInfo"))
self._scroller = Scroller([
self._adb_toggle,
self._ssh_toggle,
self._ssh_keys,
self._joystick_toggle,
self._long_maneuver_toggle,
self._alpha_long_toggle,
]
self._scroller = Scroller(items, line_separator=True, spacing=0)
self._ui_debug_toggle,
], line_separator=True, spacing=0)
# Toggles should be not available to change in onroad state
ui_state.add_offroad_transition_callback(self._update_toggles)
@@ -130,9 +137,15 @@ class DeveloperLayout(Widget):
("JoystickDebugMode", self._joystick_toggle),
("LongitudinalManeuverMode", self._long_maneuver_toggle),
("AlphaLongitudinalEnabled", self._alpha_long_toggle),
("ShowDebugInfo", self._ui_debug_toggle),
):
item.action_item.set_state(self._params.get_bool(key))
def _on_enable_ui_debug(self, state: bool):
self._params.put_bool("ShowDebugInfo", state)
gui_app.set_show_touches(state)
gui_app.set_show_fps(state)
def _on_enable_adb(self, state: bool):
self._params.put_bool("AdbEnabled", state)

View File

@@ -160,6 +160,14 @@ class GuiApplication:
# Debug variables
self._mouse_history: deque[MousePos] = deque(maxlen=MOUSE_THREAD_RATE)
self._show_touches = SHOW_TOUCHES
self._show_fps = SHOW_FPS
def set_show_touches(self, show: bool):
self._show_touches = show
def set_show_fps(self, show: bool):
self._show_fps = show
@property
def target_fps(self):
@@ -367,10 +375,10 @@ class GuiApplication:
dst_rect = rl.Rectangle(0, 0, float(self._scaled_width), float(self._scaled_height))
rl.draw_texture_pro(self._render_texture.texture, src_rect, dst_rect, rl.Vector2(0, 0), 0.0, rl.WHITE)
if SHOW_FPS:
if self._show_fps:
rl.draw_fps(10, 10)
if SHOW_TOUCHES:
if self._show_touches:
for mouse_event in self._mouse_events:
if mouse_event.left_pressed:
self._mouse_history.clear()