Skip to content

Commit b8a845f

Browse files
ui: add GRID debug helper (#36630)
1 parent a6d2297 commit b8a845f

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

system/ui/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Quick start:
77
* set `STRICT_MODE=1` to kill the app if it drops too much below 60fps
88
* set `SCALE=1.5` to scale the entire UI by 1.5x
99
* set `BURN_IN=1` to get a burn-in heatmap version of the UI
10+
* set `GRID=50` to show a 50-pixel alignment grid overlay
1011
* https://www.raylib.com/cheatsheet/cheatsheet.html
1112
* https://electronstudio.github.io/raylib-python-cffi/README.html#quickstart
1213

system/ui/lib/application.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
SHOW_TOUCHES = os.getenv("SHOW_TOUCHES") == "1"
3333
STRICT_MODE = os.getenv("STRICT_MODE") == "1"
3434
SCALE = float(os.getenv("SCALE", "1.0"))
35+
GRID_SIZE = int(os.getenv("GRID", "0"))
3536
PROFILE_RENDER = int(os.getenv("PROFILE_RENDER", "0"))
3637
PROFILE_STATS = int(os.getenv("PROFILE_STATS", "100")) # Number of functions to show in profile output
3738

@@ -213,6 +214,7 @@ def __init__(self, width: int, height: int):
213214
self._mouse_history: deque[MousePosWithTime] = deque(maxlen=MOUSE_THREAD_RATE)
214215
self._show_touches = SHOW_TOUCHES
215216
self._show_fps = SHOW_FPS
217+
self._grid_size = GRID_SIZE
216218
self._profile_render_frames = PROFILE_RENDER
217219
self._render_profiler = None
218220
self._render_profile_start_time = None
@@ -457,6 +459,9 @@ def render(self):
457459
if self._show_touches:
458460
self._draw_touch_points()
459461

462+
if self._grid_size > 0:
463+
self._draw_grid()
464+
460465
rl.end_drawing()
461466
self._monitor_fps()
462467
self._frame += 1
@@ -605,6 +610,19 @@ def _draw_touch_points(self):
605610
color = rl.Color(min(int(255 * (1.5 - perc)), 255), int(min(255 * (perc + 0.5), 255)), 50, 255)
606611
rl.draw_circle(int(mouse_pos.x), int(mouse_pos.y), 5, color)
607612

613+
def _draw_grid(self):
614+
grid_color = rl.Color(60, 60, 60, 255)
615+
# Draw vertical lines
616+
x = 0
617+
while x <= self._scaled_width:
618+
rl.draw_line(x, 0, x, self._scaled_height, grid_color)
619+
x += self._grid_size
620+
# Draw horizontal lines
621+
y = 0
622+
while y <= self._scaled_height:
623+
rl.draw_line(0, y, self._scaled_width, y, grid_color)
624+
y += self._grid_size
625+
608626
def _output_render_profile(self):
609627
import io
610628
import pstats

0 commit comments

Comments
 (0)