|
|
|
|
@ -1,6 +1,6 @@ |
|
|
|
|
import pyray as rl |
|
|
|
|
from openpilot.system.ui.lib.application import FontWeight, gui_app |
|
|
|
|
from openpilot.system.ui.widgets import Widget |
|
|
|
|
from openpilot.system.ui.lib.application import FontWeight |
|
|
|
|
from openpilot.system.ui.widgets import Widget, DialogResult |
|
|
|
|
from openpilot.system.ui.widgets.button import Button, ButtonStyle |
|
|
|
|
from openpilot.system.ui.widgets.label import gui_label |
|
|
|
|
from openpilot.system.ui.widgets.scroller import Scroller |
|
|
|
|
@ -22,14 +22,19 @@ class MultiOptionDialog(Widget): |
|
|
|
|
self.options = options |
|
|
|
|
self.current = current |
|
|
|
|
self.selection = current |
|
|
|
|
self._result: DialogResult = DialogResult.NO_ACTION |
|
|
|
|
|
|
|
|
|
# Create scroller with option buttons |
|
|
|
|
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.cancel_button = Button("Cancel", click_callback=lambda: gui_app.set_modal_overlay(None)) |
|
|
|
|
self.select_button = Button("Select", click_callback=lambda: gui_app.set_modal_overlay(None), button_style=ButtonStyle.PRIMARY) |
|
|
|
|
self.cancel_button = Button("Cancel", click_callback=lambda: self._set_result(DialogResult.CANCEL)) |
|
|
|
|
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): |
|
|
|
|
self.selection = option |
|
|
|
|
@ -68,4 +73,4 @@ class MultiOptionDialog(Widget): |
|
|
|
|
self.select_button.set_enabled(self.selection != self.current) |
|
|
|
|
self.select_button.render(select_rect) |
|
|
|
|
|
|
|
|
|
return -1 |
|
|
|
|
return self._result |
|
|
|
|
|