Files
dragonpilot/system/ui/lib/text_measure.py
T
Vehicle Researcher 3a9999ce05 openpilot v0.10.0 release
date: 2025-08-19T09:22:22
master commit: 1508b2a6e31204c2fb41dd023412c90808236940
2025-08-19 09:22:24 -07:00

15 lines
441 B
Python

import pyray as rl
_cache: dict[int, rl.Vector2] = {}
def measure_text_cached(font: rl.Font, text: str, font_size: int, spacing: int = 0) -> rl.Vector2:
"""Caches text measurements to avoid redundant calculations."""
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, spacing) # noqa: TID251
_cache[key] = result
return result