raylib: updater UI (#36235)

* auto attempt

* gpt5

* Revert "gpt5"

This reverts commit 556d6d9ee4d53aca0f4612023db6cfb2bed7ce29.

* clean up

* fixes

* use raylib

* fixes

* debug

* test update

* more

* rm

* add value to button like qt

* bump

* bump

* fixes

* bump

* fix

* bump

* clean up

* time ago like qt

rm

* bump

* clean up

* updated can fail to respond on boot leading to stuck state

* fix color

fix

* bump

* bump

* add back

* test update

* no unknown just ''

* ffix
This commit is contained in:
Shane Smiskol
2025-10-02 03:57:10 -07:00
committed by GitHub
parent 49570c11c6
commit 3fd352a7ef
3 changed files with 158 additions and 13 deletions
+25 -1
View File
@@ -14,6 +14,7 @@ ITEM_BASE_HEIGHT = 170
ITEM_PADDING = 20
ITEM_TEXT_FONT_SIZE = 50
ITEM_TEXT_COLOR = rl.WHITE
ITEM_TEXT_VALUE_COLOR = rl.Color(170, 170, 170, 255)
ITEM_DESC_TEXT_COLOR = rl.Color(128, 128, 128, 255)
ITEM_DESC_FONT_SIZE = 40
ITEM_DESC_V_OFFSET = 140
@@ -77,7 +78,9 @@ class ButtonAction(ItemAction):
def __init__(self, text: str | Callable[[], str], width: int = BUTTON_WIDTH, enabled: bool | Callable[[], bool] = True):
super().__init__(width, enabled)
self._text_source = text
self._value_source: str | Callable[[], str] | None = None
self._pressed = False
self._font = gui_app.font(FontWeight.NORMAL)
def pressed():
self._pressed = True
@@ -96,16 +99,34 @@ class ButtonAction(ItemAction):
super().set_touch_valid_callback(touch_callback)
self._button.set_touch_valid_callback(touch_callback)
def set_text(self, text: str | Callable[[], str]):
self._text_source = text
def set_value(self, value: str | Callable[[], str]):
self._value_source = value
@property
def text(self):
return _resolve_value(self._text_source, "Error")
@property
def value(self):
return _resolve_value(self._value_source, "")
def _render(self, rect: rl.Rectangle) -> bool:
self._button.set_text(self.text)
self._button.set_enabled(_resolve_value(self.enabled))
button_rect = rl.Rectangle(rect.x, rect.y + (rect.height - BUTTON_HEIGHT) / 2, BUTTON_WIDTH, BUTTON_HEIGHT)
self._button.render(button_rect)
value_text = self.value
if value_text:
spacing = 20
text_size = measure_text_cached(self._font, value_text, ITEM_TEXT_FONT_SIZE)
text_x = button_rect.x - spacing - text_size.x
text_y = rect.y + (rect.height - text_size.y) / 2
rl.draw_text_ex(self._font, value_text, rl.Vector2(text_x, text_y), ITEM_TEXT_FONT_SIZE, 0, ITEM_TEXT_VALUE_COLOR)
# TODO: just use the generic Widget click callbacks everywhere, no returning from render
pressed = self._pressed
self._pressed = False
@@ -139,6 +160,9 @@ class TextAction(ItemAction):
rl.draw_text_ex(self._font, current_text, rl.Vector2(text_x, text_y), ITEM_TEXT_FONT_SIZE, 0, self.color)
return False
def set_text(self, text: str | Callable[[], str]):
self._text_source = text
def get_width(self) -> int:
text_width = measure_text_cached(self._font, self.text, ITEM_TEXT_FONT_SIZE).x
return int(text_width + TEXT_PADDING)
@@ -382,7 +406,7 @@ def button_item(title: str, button_text: str | Callable[[], str], description: s
def text_item(title: str, value: str | Callable[[], str], description: str | Callable[[], str] | None = None,
callback: Callable | None = None, enabled: bool | Callable[[], bool] = True) -> ListItem:
action = TextAction(text=value, color=rl.Color(170, 170, 170, 255), enabled=enabled)
action = TextAction(text=value, color=ITEM_TEXT_VALUE_COLOR, enabled=enabled)
return ListItem(title=title, description=description, action_item=action, callback=callback)