Skip to content

Commit e62781c

Browse files
committed
Revert "raylib: font sizes from QT should match (#36237)"
This reverts commit 7933c10.
1 parent e1912fa commit e62781c

File tree

5 files changed

+20
-43
lines changed

5 files changed

+20
-43
lines changed

selfdrive/ui/layouts/sidebar.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -216,21 +216,14 @@ def _draw_metric(self, rect: rl.Rectangle, metric: MetricData, y: float):
216216
# Draw border
217217
rl.draw_rectangle_rounded_lines_ex(metric_rect, 0.3, 10, 2, Colors.METRIC_BORDER)
218218

219-
label_size = measure_text_cached(self._font_bold, metric.label, FONT_SIZE)
220-
value_size = measure_text_cached(self._font_bold, metric.value, FONT_SIZE)
221-
text_height = label_size.y + value_size.y
222-
223-
label_y = metric_rect.y + (metric_rect.height - text_height) / 2
224-
value_y = label_y + label_size.y
225-
226-
# label
227-
rl.draw_text_ex(self._font_bold, metric.label, rl.Vector2(
228-
metric_rect.x + 22 + (metric_rect.width - 22 - label_size.x) / 2,
229-
label_y
230-
), FONT_SIZE, 0, Colors.WHITE)
231-
232-
# value
233-
rl.draw_text_ex(self._font_bold, metric.value, rl.Vector2(
234-
metric_rect.x + 22 + (metric_rect.width - 22 - value_size.x) / 2,
235-
value_y
236-
), FONT_SIZE, 0, Colors.WHITE)
219+
# Draw label and value
220+
labels = [metric.label, metric.value]
221+
text_y = metric_rect.y + (metric_rect.height / 2 - len(labels) * FONT_SIZE)
222+
for text in labels:
223+
text_size = measure_text_cached(self._font_bold, text, FONT_SIZE)
224+
text_y += text_size.y
225+
text_pos = rl.Vector2(
226+
metric_rect.x + 22 + (metric_rect.width - 22 - text_size.x) / 2,
227+
text_y
228+
)
229+
rl.draw_text_ex(self._font_bold, text, text_pos, FONT_SIZE, 0, Colors.WHITE)

selfdrive/ui/widgets/exp_mode_button.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pyray as rl
22
from openpilot.common.params import Params
3-
from openpilot.system.ui.lib.application import gui_app, FontWeight, FONT_SCALE
3+
from openpilot.system.ui.lib.application import gui_app, FontWeight
44
from openpilot.system.ui.widgets import Widget
55

66

@@ -9,7 +9,7 @@ def __init__(self):
99
super().__init__()
1010

1111
self.img_width = 80
12-
self.horizontal_padding = 30
12+
self.horizontal_padding = 50
1313
self.button_height = 125
1414

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

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

system/ui/lib/application.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@
3030
DEFAULT_TEXT_SIZE = 60
3131
DEFAULT_TEXT_COLOR = rl.WHITE
3232

33-
# Qt draws fonts accounting for ascent/descent differently, so compensate to match old styles
34-
# The real scales for the fonts below range from 1.212 to 1.266
35-
FONT_SCALE = 1.242
36-
3733
ASSETS_DIR = files("openpilot.selfdrive").joinpath("assets")
3834
FONT_DIR = ASSETS_DIR.joinpath("fonts")
3935

@@ -177,7 +173,6 @@ def init_window(self, title: str, fps: int = _DEFAULT_FPS):
177173
self._target_fps = fps
178174
self._set_styles()
179175
self._load_fonts()
180-
self._patch_text_functions()
181176

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

364-
def _patch_text_functions(self):
365-
# Wrap pyray text APIs to apply a global text size scale so our px sizes match Qt
366-
if not hasattr(rl, "_orig_draw_text_ex"):
367-
rl._orig_draw_text_ex = rl.draw_text_ex
368-
369-
def _draw_text_ex_scaled(font, text, position, font_size, spacing, tint):
370-
return rl._orig_draw_text_ex(font, text, position, font_size * FONT_SCALE, spacing, tint)
371-
372-
rl.draw_text_ex = _draw_text_ex_scaled
373-
374359
def _set_log_callback(self):
375360
ffi_libc = cffi.FFI()
376361
ffi_libc.cdef("""

system/ui/lib/text_measure.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import pyray as rl
2-
from openpilot.system.ui.lib.application import FONT_SCALE
32

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

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

13-
result = rl.measure_text_ex(font, text, font_size * FONT_SCALE, spacing) # noqa: TID251
12+
result = rl.measure_text_ex(font, text, font_size, spacing) # noqa: TID251
1413
_cache[key] = result
1514
return result

system/ui/widgets/html_render.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from dataclasses import dataclass
44
from enum import Enum
55
from typing import Any
6-
from openpilot.system.ui.lib.application import gui_app, FontWeight, FONT_SCALE
6+
from openpilot.system.ui.lib.application import gui_app, FontWeight
77
from openpilot.system.ui.lib.scroll_panel import GuiScrollPanel
88
from openpilot.system.ui.lib.wrap_text import wrap_text
99
from openpilot.system.ui.widgets import Widget
@@ -176,8 +176,8 @@ def _render(self, rect: rl.Rectangle):
176176
wrapped_lines = wrap_text(font, element.content, element.font_size, int(content_width))
177177

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

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

189-
current_y += element.font_size * FONT_SCALE * element.line_height
189+
current_y += element.font_size * element.line_height
190190

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

212212
for _ in wrapped_lines:
213-
total_height += element.font_size * FONT_SCALE * element.line_height
213+
total_height += element.font_size * element.line_height
214214

215215
total_height += element.margin_bottom
216216

0 commit comments

Comments
 (0)