mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-09-11 00:23:43 +08:00
0e51ecbb7e
version: sunnypilot v2026.003.000 (dev)
date: 2026-09-09T15:43:49
master commit: b255314f5a
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
|