Revert "add elide support to Label"

This reverts commit 28c3e0e745.
pull/36359/head
Shane Smiskol 3 weeks ago
parent 3033e65c45
commit 92c2d66941
  1. 3
      system/ui/widgets/button.py
  2. 34
      system/ui/widgets/label.py
  3. 3
      system/ui/widgets/option_dialog.py

@ -88,7 +88,6 @@ class Button(Widget):
text_alignment: TextAlignment = TextAlignment.CENTER,
text_padding: int = 20,
icon=None,
elide_right: bool = False,
multi_touch: bool = False,
):
@ -98,7 +97,7 @@ class Button(Widget):
self._background_color = BUTTON_BACKGROUND_COLORS[self._button_style]
self._label = Label(text, font_size, font_weight, text_alignment, text_padding,
BUTTON_TEXT_COLOR[self._button_style], icon=icon, elide_right=elide_right)
BUTTON_TEXT_COLOR[self._button_style], icon=icon)
self._click_callback = click_callback
self._multi_touch = multi_touch

@ -34,17 +34,17 @@ def gui_label(
# Elide text to fit within the rectangle
if elide_right and text_size.x > rect.width:
_ellipsis = "..."
ellipsis = "..."
left, right = 0, len(text)
while left < right:
mid = (left + right) // 2
candidate = text[:mid] + _ellipsis
candidate = text[:mid] + ellipsis
candidate_size = measure_text_cached(font, candidate, font_size)
if candidate_size.x <= rect.width:
left = mid + 1
else:
right = mid
display_text = text[: left - 1] + _ellipsis if left > 0 else _ellipsis
display_text = text[: left - 1] + ellipsis if left > 0 else ellipsis
text_size = measure_text_cached(font, display_text, font_size)
# Calculate horizontal position based on alignment
@ -101,8 +101,7 @@ class Label(Widget):
text_alignment: TextAlignment = TextAlignment.CENTER,
text_padding: int = 20,
text_color: rl.Color = DEFAULT_TEXT_COLOR,
icon=None,
elide_right: bool = False
icon = None,
):
super().__init__()
@ -113,7 +112,6 @@ class Label(Widget):
self._text_padding = text_padding
self._text_color = text_color
self._icon = icon
self._elide_right = elide_right
self.set_text(text)
def set_text(self, text):
@ -129,29 +127,7 @@ class Label(Widget):
def _update_text(self, text):
self._emojis = []
self._text_size = []
if self._elide_right:
display_text = text
# Elide text to fit within the rectangle
text_size = measure_text_cached(self._font, text, self._font_size)
content_width = self._rect.width - self._text_padding * 2
if text_size.x > content_width:
_ellipsis = "..."
left, right = 0, len(text)
while left < right:
mid = (left + right) // 2
candidate = text[:mid] + _ellipsis
candidate_size = measure_text_cached(self._font, candidate, self._font_size)
if candidate_size.x <= content_width:
left = mid + 1
else:
right = mid
display_text = text[: left - 1] + _ellipsis if left > 0 else _ellipsis
self._text = [display_text]
else:
self._text = wrap_text(self._font, text, self._font_size, self._rect.width - (self._text_padding * 2))
self._text = wrap_text(self._font, text, self._font_size, self._rect.width - (self._text_padding*2))
for t in self._text:
self._emojis.append(find_emoji(t))
self._text_size.append(measure_text_cached(self._font, t, self._font_size))

@ -26,8 +26,7 @@ class MultiOptionDialog(Widget):
# Create scroller with option buttons
self.option_buttons = [Button(option, click_callback=lambda opt=option: self._on_option_clicked(opt),
text_alignment=TextAlignment.LEFT, button_style=ButtonStyle.NORMAL,
text_padding=50, elide_right=True) for option in options]
text_alignment=TextAlignment.LEFT, button_style=ButtonStyle.NORMAL) for option in options]
self.scroller = Scroller(self.option_buttons, spacing=LIST_ITEM_SPACING)
# Buttons set a result; the application loop will clear the overlay and invoke the callback

Loading…
Cancel
Save