Skip to content

Commit 77760e0

Browse files
committed
wip slider support
1 parent 78a0687 commit 77760e0

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

arcade/examples/gui/exp_controller_support.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
from arcade.gui import (
66
UIAnchorLayout,
77
UIBoxLayout,
8+
UIDropdown,
89
UIEvent,
910
UIFlatButton,
1011
UIImage,
1112
UIMouseFilterMixin,
1213
UIOnClickEvent,
14+
UISlider,
1315
UIView,
1416
)
1517
from arcade.gui.experimental.controller import (
@@ -156,14 +158,19 @@ def __init__(self):
156158

157159
self.controller_bridge = UIControllerBridge(self.ui)
158160

159-
self.root = self.add_widget(ControllerIndicator())
160-
self.root = self.root.add(UIFocusGroup())
161+
base = self.add_widget(ControllerIndicator())
162+
self.root = base.add(UIFocusGroup())
163+
self.root.with_padding(left=10)
161164
box = self.root.add(UIBoxLayout(space_between=10), anchor_x="left")
162165

163166
box.add(UIFlatButton(text="Button 1")).on_click = self.on_button_click
164167
box.add(UIFlatButton(text="Button 2")).on_click = self.on_button_click
165168
box.add(UIFlatButton(text="Button 3")).on_click = self.on_button_click
166169

170+
box.add(UIDropdown(default="Option 1", options=["Option 1", "Option 2", "Option 3"]))
171+
172+
box.add(UISlider(value=0.5, min_value=0, max_value=1, width=200))
173+
167174
self.root.detect_focusable_widgets()
168175

169176
def on_button_click(self, event: UIOnClickEvent):

arcade/gui/experimental/focus.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from arcade.gui.ui_manager import UIManager
2424
from arcade.gui.widgets import UIInteractiveWidget, UIWidget
2525
from arcade.gui.widgets.layout import UIAnchorLayout
26+
from arcade.gui.widgets.slider import UIBaseSlider
2627

2728

2829
class Focusable(UIWidget):
@@ -112,6 +113,7 @@ def on_event(self, event: UIEvent) -> Optional[bool]:
112113

113114
if isinstance(event, UIControllerDpadEvent):
114115
if self._interacting:
116+
# TODO this should be handled in the slider!
115117
# pass dpad events to the interacting widget
116118
if event.vector.x == 1 and isinstance(self._interacting, UIBaseSlider):
117119
self._interacting.norm_value += 0.1
@@ -277,7 +279,7 @@ def _do_render(self, surface: Surface, force=False) -> bool:
277279
def do_post_render(self, surface: Surface):
278280
surface.limit(None)
279281

280-
if self._focused < len(self._focusable_widgets):
282+
if len(self._focusable_widgets) < self._focused < 0:
281283
warnings.warn("Focused widget is out of range")
282284
return
283285

0 commit comments

Comments
 (0)