f8e13417f2
date: 2026-08-15T14:20:10 master commit: d48cfa730bf21593b684efeaf3fd8940695e1dea
19 lines
590 B
Python
19 lines
590 B
Python
import pyray as rl
|
|
from openpilot.system.ui.lib.application import FONT_SCALE, font_fallback
|
|
|
|
_cache: dict[int, rl.Vector2] = {}
|
|
|
|
|
|
def measure_text_cached(font: rl.Font, text: str, font_size: int, spacing: float = 0) -> rl.Vector2:
|
|
"""Caches text measurements to avoid redundant calculations."""
|
|
font = font_fallback(font)
|
|
spacing = round(spacing, 4)
|
|
key = hash((font.texture.id, text, font_size, spacing))
|
|
if key in _cache:
|
|
return _cache[key]
|
|
|
|
result = rl.measure_text_ex(font, text, font_size * FONT_SCALE, spacing) # noqa: TID251
|
|
|
|
_cache[key] = result
|
|
return result
|