You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							15 lines
						
					
					
						
							513 B
						
					
					
				
			
		
		
	
	
							15 lines
						
					
					
						
							513 B
						
					
					
				import pyray as rl
 | 
						|
from openpilot.system.ui.lib.application import FONT_SCALE
 | 
						|
 | 
						|
_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 * FONT_SCALE, spacing)  # noqa: TID251
 | 
						|
  _cache[key] = result
 | 
						|
  return result
 | 
						|
 |