Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
cf39eef
debug
sshane Oct 2, 2025
cc17be0
hacks everywhere but kind of works
sshane Oct 2, 2025
76bad30
by font
sshane Oct 2, 2025
d855c0b
fix sidebar
sshane Oct 3, 2025
ce5ca24
Merge remote-tracking branch 'upstream/master' into debug-rl-small-text
sshane Oct 3, 2025
5da6465
stash
sshane Oct 3, 2025
a60bbb5
Merge remote-tracking branch 'upstream/master' into debug-rl-small-text
sshane Oct 4, 2025
99c8840
test update
sshane Oct 4, 2025
ab978bf
Merge remote-tracking branch 'upstream/master' into debug-rl-small-text
sshane Oct 4, 2025
3197620
Merge remote-tracking branch 'upstream/master' into debug-rl-small-text
sshane Oct 4, 2025
ab120c5
Merge remote-tracking branch 'upstream/master' into debug-rl-small-text
sshane Oct 4, 2025
be644e7
just use a const
sshane Oct 4, 2025
7e73a5b
just use a const
sshane Oct 4, 2025
94c4445
Merge remote-tracking branch 'upstream/master' into debug-rl-small-text
sshane Oct 4, 2025
12e4ce0
better
sshane Oct 4, 2025
ce6304c
clean up
sshane Oct 4, 2025
46aa5b1
fix label
sshane Oct 4, 2025
2015e8d
simplify
sshane Oct 4, 2025
258df57
gpt5 is yet again garbage
sshane Oct 4, 2025
6af6892
rm that
sshane Oct 4, 2025
9bc6f57
clean up
sshane Oct 4, 2025
f68e2b7
Merge remote-tracking branch 'upstream/master' into debug-rl-small-text
sshane Oct 4, 2025
369b368
rm
sshane Oct 4, 2025
88c126b
blank
sshane Oct 4, 2025
c01e106
clean up
sshane Oct 4, 2025
1edf4b1
Merge remote-tracking branch 'upstream/master' into debug-rl-small-text
sshane Oct 4, 2025
e6261c0
Merge remote-tracking branch 'upstream/master' into debug-rl-small-text
sshane Oct 4, 2025
952a928
I really don't like this but shrug
sshane Oct 4, 2025
e242994
fix
sshane Oct 4, 2025
4dfe9b7
fix experimental text
sshane Oct 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions selfdrive/ui/layouts/sidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,21 @@ def _draw_metric(self, rect: rl.Rectangle, metric: MetricData, y: float):
# Draw border
rl.draw_rectangle_rounded_lines_ex(metric_rect, 0.3, 10, 2, Colors.METRIC_BORDER)

# Draw label and value
labels = [metric.label, metric.value]
text_y = metric_rect.y + (metric_rect.height / 2 - len(labels) * FONT_SIZE)
for text in labels:
text_size = measure_text_cached(self._font_bold, text, FONT_SIZE)
text_y += text_size.y
text_pos = rl.Vector2(
metric_rect.x + 22 + (metric_rect.width - 22 - text_size.x) / 2,
text_y
)
rl.draw_text_ex(self._font_bold, text, text_pos, FONT_SIZE, 0, Colors.WHITE)
label_size = measure_text_cached(self._font_bold, metric.label, FONT_SIZE)
value_size = measure_text_cached(self._font_bold, metric.value, FONT_SIZE)
text_height = label_size.y + value_size.y

label_y = metric_rect.y + (metric_rect.height - text_height) / 2
value_y = label_y + label_size.y

# label
rl.draw_text_ex(self._font_bold, metric.label, rl.Vector2(
metric_rect.x + 22 + (metric_rect.width - 22 - label_size.x) / 2,
label_y
), FONT_SIZE, 0, Colors.WHITE)

# value
rl.draw_text_ex(self._font_bold, metric.value, rl.Vector2(
metric_rect.x + 22 + (metric_rect.width - 22 - value_size.x) / 2,
value_y
), FONT_SIZE, 0, Colors.WHITE)
6 changes: 3 additions & 3 deletions selfdrive/ui/widgets/exp_mode_button.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pyray as rl
from openpilot.common.params import Params
from openpilot.system.ui.lib.application import gui_app, FontWeight
from openpilot.system.ui.lib.application import gui_app, FontWeight, FONT_SCALE
from openpilot.system.ui.widgets import Widget


Expand All @@ -9,7 +9,7 @@ def __init__(self):
super().__init__()

self.img_width = 80
self.horizontal_padding = 50
self.horizontal_padding = 30
self.button_height = 125

self.params = Params()
Expand Down Expand Up @@ -51,7 +51,7 @@ def _render(self, rect):
# Draw text label (left aligned)
text = "EXPERIMENTAL MODE ON" if self.experimental_mode else "CHILL MODE ON"
text_x = rect.x + self.horizontal_padding
text_y = rect.y + rect.height / 2 - 45 // 2 # Center vertically
text_y = rect.y + rect.height / 2 - 45 * FONT_SCALE // 2 # Center vertically

rl.draw_text_ex(gui_app.font(FontWeight.NORMAL), text, rl.Vector2(int(text_x), int(text_y)), 45, 0, rl.BLACK)

Expand Down
15 changes: 15 additions & 0 deletions system/ui/lib/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
DEFAULT_TEXT_SIZE = 60
DEFAULT_TEXT_COLOR = rl.WHITE

# Qt draws fonts accounting for ascent/descent differently, so compensate to match old styles
# The real scales for the fonts below range from 1.212 to 1.266
FONT_SCALE = 1.242

ASSETS_DIR = files("openpilot.selfdrive").joinpath("assets")
FONT_DIR = ASSETS_DIR.joinpath("fonts")

Expand Down Expand Up @@ -173,6 +177,7 @@ def init_window(self, title: str, fps: int = _DEFAULT_FPS):
self._target_fps = fps
self._set_styles()
self._load_fonts()
self._patch_text_functions()

if not PC:
self._mouse.start()
Expand Down Expand Up @@ -356,6 +361,16 @@ def _set_styles(self):
rl.gui_set_style(rl.GuiControl.DEFAULT, rl.GuiControlProperty.TEXT_COLOR_NORMAL, rl.color_to_int(DEFAULT_TEXT_COLOR))
rl.gui_set_style(rl.GuiControl.DEFAULT, rl.GuiControlProperty.BASE_COLOR_NORMAL, rl.color_to_int(rl.Color(50, 50, 50, 255)))

def _patch_text_functions(self):
# Wrap pyray text APIs to apply a global text size scale so our px sizes match Qt
if not hasattr(rl, "_orig_draw_text_ex"):
rl._orig_draw_text_ex = rl.draw_text_ex

def _draw_text_ex_scaled(font, text, position, font_size, spacing, tint):
return rl._orig_draw_text_ex(font, text, position, font_size * FONT_SCALE, spacing, tint)

rl.draw_text_ex = _draw_text_ex_scaled

def _set_log_callback(self):
ffi_libc = cffi.FFI()
ffi_libc.cdef("""
Expand Down
3 changes: 2 additions & 1 deletion system/ui/lib/text_measure.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pyray as rl
from openpilot.system.ui.lib.application import FONT_SCALE

_cache: dict[int, rl.Vector2] = {}

Expand All @@ -9,6 +10,6 @@ def measure_text_cached(font: rl.Font, text: str, font_size: int, spacing: int =
if key in _cache:
return _cache[key]

result = rl.measure_text_ex(font, text, font_size, spacing) # noqa: TID251
result = rl.measure_text_ex(font, text, font_size * FONT_SCALE, spacing) # noqa: TID251
_cache[key] = result
return result
10 changes: 5 additions & 5 deletions system/ui/widgets/html_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from dataclasses import dataclass
from enum import Enum
from typing import Any
from openpilot.system.ui.lib.application import gui_app, FontWeight
from openpilot.system.ui.lib.application import gui_app, FontWeight, FONT_SCALE
from openpilot.system.ui.lib.scroll_panel import GuiScrollPanel
from openpilot.system.ui.lib.wrap_text import wrap_text
from openpilot.system.ui.widgets import Widget
Expand Down Expand Up @@ -176,8 +176,8 @@ def _render(self, rect: rl.Rectangle):
wrapped_lines = wrap_text(font, element.content, element.font_size, int(content_width))

for line in wrapped_lines:
if current_y < rect.y - element.font_size:
current_y += element.font_size * element.line_height
if current_y < rect.y - element.font_size * FONT_SCALE:
current_y += element.font_size * FONT_SCALE * element.line_height
continue

if current_y > rect.y + rect.height:
Expand All @@ -186,7 +186,7 @@ def _render(self, rect: rl.Rectangle):
text_x = rect.x + (max(element.indent_level - 1, 0) * LIST_INDENT_PX)
rl.draw_text_ex(font, line, rl.Vector2(text_x + padding, current_y), element.font_size, 0, self._text_color)

current_y += element.font_size * element.line_height
current_y += element.font_size * FONT_SCALE * element.line_height

# Apply bottom margin
current_y += element.margin_bottom
Expand All @@ -210,7 +210,7 @@ def get_total_height(self, content_width: int) -> float:
wrapped_lines = wrap_text(font, element.content, element.font_size, int(usable_width))

for _ in wrapped_lines:
total_height += element.font_size * element.line_height
total_height += element.font_size * FONT_SCALE * element.line_height

total_height += element.margin_bottom

Expand Down