mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-08-19 18:03:46 +08:00
f29eb5d25c
* remove emoji support, replace with png * upload icons * fix icon left/right positioning * simplify rewrite * simplify firehose * simplify custom software set up text * lint * fix custom software * move fix to diff pr --------- Co-authored-by: elkoled <elkoled@gmail.com>
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
|