raylib: fix button clicking on device (#36201)

* fix button clicking on device

* clean up
pull/36203/head
Shane Smiskol 3 days ago committed by GitHub
parent 6aecf59536
commit 5429748767
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 37
      system/ui/widgets/list_view.py

@ -6,7 +6,7 @@ from openpilot.system.ui.lib.application import gui_app, FontWeight, MousePos
from openpilot.system.ui.lib.text_measure import measure_text_cached from openpilot.system.ui.lib.text_measure import measure_text_cached
from openpilot.system.ui.lib.wrap_text import wrap_text from openpilot.system.ui.lib.wrap_text import wrap_text
from openpilot.system.ui.widgets import Widget from openpilot.system.ui.widgets import Widget
from openpilot.system.ui.widgets.button import gui_button, ButtonStyle from openpilot.system.ui.widgets.button import Button, gui_button, ButtonStyle
from openpilot.system.ui.widgets.toggle import Toggle, WIDTH as TOGGLE_WIDTH, HEIGHT as TOGGLE_HEIGHT from openpilot.system.ui.widgets.toggle import Toggle, WIDTH as TOGGLE_WIDTH, HEIGHT as TOGGLE_HEIGHT
ITEM_BASE_WIDTH = 600 ITEM_BASE_WIDTH = 600
@ -73,21 +73,38 @@ class ButtonAction(ItemAction):
def __init__(self, text: str | Callable[[], str], width: int = BUTTON_WIDTH, enabled: bool | Callable[[], bool] = True): def __init__(self, text: str | Callable[[], str], width: int = BUTTON_WIDTH, enabled: bool | Callable[[], bool] = True):
super().__init__(width, enabled) super().__init__(width, enabled)
self._text_source = text self._text_source = text
self._pressed = False
def pressed():
self._pressed = True
self._button = Button(
self.text,
font_size=BUTTON_FONT_SIZE,
font_weight=BUTTON_FONT_WEIGHT,
button_style=ButtonStyle.LIST_ACTION,
border_radius=BUTTON_BORDER_RADIUS,
click_callback=pressed,
)
self._button.set_enabled(_resolve_value(enabled))
def set_touch_valid_callback(self, touch_callback: Callable[[], bool]) -> None:
super().set_touch_valid_callback(touch_callback)
self._button.set_touch_valid_callback(touch_callback)
@property @property
def text(self): def text(self):
return _resolve_value(self._text_source, "Error") return _resolve_value(self._text_source, "Error")
def _render(self, rect: rl.Rectangle) -> bool: def _render(self, rect: rl.Rectangle) -> bool:
return gui_button( self._button.set_text(self.text)
rl.Rectangle(rect.x, rect.y + (rect.height - BUTTON_HEIGHT) / 2, BUTTON_WIDTH, BUTTON_HEIGHT), button_rect = rl.Rectangle(rect.x, rect.y + (rect.height - BUTTON_HEIGHT) / 2, BUTTON_WIDTH, BUTTON_HEIGHT)
self.text, self._button.render(button_rect)
border_radius=BUTTON_BORDER_RADIUS,
font_weight=BUTTON_FONT_WEIGHT, # TODO: just use the generic Widget click callbacks everywhere, no returning from render
font_size=BUTTON_FONT_SIZE, pressed = self._pressed
button_style=ButtonStyle.LIST_ACTION, self._pressed = False
is_enabled=self.enabled, return pressed
) == 1
class TextAction(ItemAction): class TextAction(ItemAction):

Loading…
Cancel
Save