mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-11-08 05:23:41 +08:00
a82935f326
Integrate onroad views, configurable widgets, local settings, steering-profile contracts, Bluetooth and Android Auto with their device and runtime services. Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> Co-authored-by: Daniel Koepping <elkoled@gmail.com> Co-authored-by: Danny <dannyirwin31@yahoo.com> Co-authored-by: DimitriChrysafis <Dimitri.chrysafis@gmail.com> Co-authored-by: Dom <168790843+firestar5683@users.noreply.github.com> Co-authored-by: Harald Schäfer <harald.the.engineer@gmail.com> Co-authored-by: Prabhaav Pillai <prabhaav@msu.edu> Co-authored-by: Shane Smiskol <shane@smiskol.com> Co-authored-by: dirwin31 <83434411+dirwin31@users.noreply.github.com> Co-authored-by: firestarsdog <229254897+firestarsdog@users.noreply.github.com> Co-authored-by: stef <19478336+stefpi@users.noreply.github.com> Co-authored-by: whoisdomi <dcantu83@gmail.com> Co-authored-by: Intelli <contact@intelli.software> Co-authored-by: pharmacomaniac <blittle65@gmail.com> Co-authored-by: prabhaavp <prabhaav@msu.edu>
22 lines
720 B
Python
22 lines
720 B
Python
import pyray as rl
|
|
from openpilot.system.ui.lib.application import FONT_SCALE, font_fallback
|
|
from openpilot.system.ui.lib.lru_cache import LRUCache
|
|
|
|
_CACHE_MAXSIZE = 1024
|
|
_cache: LRUCache[int, rl.Vector2] = LRUCache(_CACHE_MAXSIZE)
|
|
|
|
|
|
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))
|
|
cached = _cache.get(key)
|
|
if cached is not None:
|
|
return cached
|
|
|
|
result = rl.measure_text_ex(font, text, font_size * FONT_SCALE, spacing) # noqa: TID251
|
|
|
|
_cache[key] = result
|
|
return result
|