raylib: fix emoji centering with Label (#36376)
* kinda works * but spacing was off, so back to big emoji * rm debug * fixed! * fixed! * fix newline in emoji pattern * fix * fix dat
This commit is contained in:
@@ -46,7 +46,7 @@ class PrimeWidget(Widget):
|
||||
features = ["Remote access", "24/7 LTE connectivity", "1 year of drive storage", "Remote snapshots"]
|
||||
for i, feature in enumerate(features):
|
||||
item_y = features_y + 80 + i * 65
|
||||
gui_label(rl.Rectangle(x, item_y, 50, 60), "✓", 50, color=rl.Color(70, 91, 234, 255))
|
||||
gui_label(rl.Rectangle(x, item_y, 100, 60), "✓", 50, color=rl.Color(70, 91, 234, 255))
|
||||
gui_label(rl.Rectangle(x + 60, item_y, w - 60, 60), feature, 50)
|
||||
|
||||
def _render_for_prime_user(self, rect: rl.Rectangle):
|
||||
|
||||
@@ -64,8 +64,7 @@ class SetupWidget(Widget):
|
||||
spacing = 42
|
||||
|
||||
# Title with fire emojis
|
||||
# TODO: fix Label centering with emojis
|
||||
self._firehose_label.render(rl.Rectangle(x - 48, y, w, 64))
|
||||
self._firehose_label.render(rl.Rectangle(rect.x, y, rect.width, 64))
|
||||
y += 64 + spacing
|
||||
|
||||
# Description
|
||||
|
||||
@@ -28,7 +28,7 @@ EMOJI_REGEX = re.compile(
|
||||
\u231a
|
||||
\ufe0f
|
||||
\u3030
|
||||
]+""",
|
||||
]+""".replace("\n", ""),
|
||||
flags=re.UNICODE
|
||||
)
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import pyray as rl
|
||||
from openpilot.system.ui.lib.application import FONT_SCALE
|
||||
from openpilot.system.ui.lib.emoji import find_emoji
|
||||
|
||||
_cache: dict[int, rl.Vector2] = {}
|
||||
|
||||
@@ -10,6 +11,23 @@ def measure_text_cached(font: rl.Font, text: str, font_size: int, spacing: int =
|
||||
if key in _cache:
|
||||
return _cache[key]
|
||||
|
||||
result = rl.measure_text_ex(font, text, font_size * FONT_SCALE, spacing) # noqa: TID251
|
||||
# Measure normal characters without emojis, then add standard width for each found emoji
|
||||
emoji = find_emoji(text)
|
||||
if emoji:
|
||||
non_emoji_text = ""
|
||||
last_index = 0
|
||||
for start, end, _ in emoji:
|
||||
non_emoji_text += text[last_index:start]
|
||||
last_index = end
|
||||
else:
|
||||
non_emoji_text = text
|
||||
|
||||
result = rl.measure_text_ex(font, non_emoji_text, font_size * FONT_SCALE, spacing) # noqa: TID251
|
||||
if emoji:
|
||||
result.x += len(emoji) * font_size * FONT_SCALE
|
||||
# If just emoji assume a single line height
|
||||
if result.y == 0:
|
||||
result.y = font_size * FONT_SCALE
|
||||
|
||||
_cache[key] = result
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user