raylib: cache wrap text (#36258)

* cache html height

* clean up

* todo
pull/36259/head
Shane Smiskol 3 days ago committed by GitHub
parent 89d350a791
commit 12b3d0e08d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 8
      system/ui/lib/wrap_text.py
  2. 1
      system/ui/widgets/html_render.py

@ -36,7 +36,14 @@ def _break_long_word(font: rl.Font, word: str, font_size: int, max_width: int) -
return parts
_cache: dict[int, list[str]] = {}
def wrap_text(font: rl.Font, text: str, font_size: int, max_width: int) -> list[str]:
key = hash((font.texture.id, text, font_size, max_width))
if key in _cache:
return _cache[key]
if not text or max_width <= 0:
return []
@ -100,4 +107,5 @@ def wrap_text(font: rl.Font, text: str, font_size: int, max_width: int) -> list[
# Add all lines from this paragraph
all_lines.extend(lines)
_cache[key] = all_lines
return all_lines

@ -155,6 +155,7 @@ class HtmlRenderer(Widget):
self.elements.append(element)
def _render(self, rect: rl.Rectangle):
# TODO: speed up by removing duplicate calculations across renders
current_y = rect.y
padding = 20
content_width = rect.width - (padding * 2)

Loading…
Cancel
Save