ui: display mouse coordinates with debug mode (#1512)

* ui: add debug to display mouse coordinates

* cleanup

* use mouse x and y directly

* even less

* try this out

* ui: increase `scroll` delay in UI Preview

* sleep for clicks too

* don't lol

* try 1 secs

* try this out

* wait a sec before doing a screenshot

* nah
This commit is contained in:
Jason Wen
2025-11-25 18:10:40 -05:00
committed by GitHub
parent 1e95e1cc01
commit da35e60101
3 changed files with 31 additions and 0 deletions
@@ -148,6 +148,7 @@ class DeveloperLayout(Widget):
self._params.put_bool("ShowDebugInfo", state)
gui_app.set_show_touches(state)
gui_app.set_show_fps(state)
gui_app.set_show_mouse_coords(state)
def _on_enable_adb(self, state: bool):
self._params.put_bool("AdbEnabled", state)
+5
View File
@@ -227,6 +227,8 @@ class GuiApplication(GuiApplicationExt):
self._render_profiler = None
self._render_profile_start_time = None
GuiApplicationExt.__init__(self)
@property
def frame(self):
return self._frame
@@ -467,6 +469,9 @@ class GuiApplication(GuiApplicationExt):
if self._show_touches:
self._draw_touch_points()
if self._show_mouse_coords:
self._draw_mouse_coordinates(gui_app.font(FontWeight.SEMI_BOLD))
if self._grid_size > 0:
self._draw_grid()
+25
View File
@@ -6,10 +6,35 @@ See the LICENSE.md file in the root directory for more details.
"""
import os
import pyray as rl
SHOW_MOUSE_COORDS = os.getenv("SHOW_MOUSE_COORDS") == "1"
SUNNYPILOT_UI = os.getenv("SUNNYPILOT_UI", "1") == "1"
class GuiApplicationExt:
def __init__(self):
self._show_mouse_coords = SHOW_MOUSE_COORDS
@staticmethod
def sunnypilot_ui() -> bool:
return SUNNYPILOT_UI
def _draw_mouse_coordinates(self, font):
coords_text = f"X:{int(rl.get_mouse_x())}, Y:{int(rl.get_mouse_y())}"
green_color = rl.Color(0, 159, 47, 255) # Match the green color of FPS counter
# Calculate text width to position it at the right edge; estimate width based on text length
# Each character is approximately 10-12 pixels wide at font size 20
estimated_text_width = len(coords_text) * 11
# Position text at the top right corner, 10px from the top
screen_width = self._scaled_width if self._scale != 1.0 else self._width
text_pos = rl.Vector2(screen_width - estimated_text_width - 10, 6)
# Draw the text
rl.draw_text_ex(font, coords_text, text_pos, 20, 0, green_color)
def set_show_mouse_coords(self, show: bool):
self._show_mouse_coords = show