raylib: fix option dialog (#36405)

* fix dialog

* rm
pull/36403/merge
Shane Smiskol 5 days ago committed by GitHub
parent 3c957c6e9d
commit 8752093801
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 17
      system/ui/widgets/option_dialog.py

@ -1,6 +1,6 @@
import pyray as rl import pyray as rl
from openpilot.system.ui.lib.application import FontWeight, gui_app from openpilot.system.ui.lib.application import FontWeight
from openpilot.system.ui.widgets import Widget from openpilot.system.ui.widgets import Widget, DialogResult
from openpilot.system.ui.widgets.button import Button, ButtonStyle from openpilot.system.ui.widgets.button import Button, ButtonStyle
from openpilot.system.ui.widgets.label import gui_label from openpilot.system.ui.widgets.label import gui_label
from openpilot.system.ui.widgets.scroller import Scroller from openpilot.system.ui.widgets.scroller import Scroller
@ -22,14 +22,19 @@ class MultiOptionDialog(Widget):
self.options = options self.options = options
self.current = current self.current = current
self.selection = current self.selection = current
self._result: DialogResult = DialogResult.NO_ACTION
# Create scroller with option buttons # Create scroller with option buttons
self.option_buttons = [Button(option, click_callback=lambda opt=option: self._on_option_clicked(opt), self.option_buttons = [Button(option, click_callback=lambda opt=option: self._on_option_clicked(opt),
text_alignment=rl.GuiTextAlignment.TEXT_ALIGN_LEFT, button_style=ButtonStyle.NORMAL) for option in options] text_alignment=rl.GuiTextAlignment.TEXT_ALIGN_LEFT, button_style=ButtonStyle.NORMAL,
text_padding=50, elide_right=True) for option in options]
self.scroller = Scroller(self.option_buttons, spacing=LIST_ITEM_SPACING) self.scroller = Scroller(self.option_buttons, spacing=LIST_ITEM_SPACING)
self.cancel_button = Button("Cancel", click_callback=lambda: gui_app.set_modal_overlay(None)) self.cancel_button = Button("Cancel", click_callback=lambda: self._set_result(DialogResult.CANCEL))
self.select_button = Button("Select", click_callback=lambda: gui_app.set_modal_overlay(None), button_style=ButtonStyle.PRIMARY) self.select_button = Button("Select", click_callback=lambda: self._set_result(DialogResult.CONFIRM), button_style=ButtonStyle.PRIMARY)
def _set_result(self, result: DialogResult):
self._result = result
def _on_option_clicked(self, option): def _on_option_clicked(self, option):
self.selection = option self.selection = option
@ -68,4 +73,4 @@ class MultiOptionDialog(Widget):
self.select_button.set_enabled(self.selection != self.current) self.select_button.set_enabled(self.selection != self.current)
self.select_button.render(select_rect) self.select_button.render(select_rect)
return -1 return self._result

Loading…
Cancel
Save