5
5
6
6
import arcade
7
7
from arcade import MOUSE_BUTTON_LEFT
8
- from arcade .gui import (
9
- ListProperty ,
10
- Property ,
11
- Surface ,
12
- UIAnchorLayout ,
8
+ from arcade .gui .events import (
13
9
UIEvent ,
14
- UIInteractiveWidget ,
15
10
UIKeyPressEvent ,
16
11
UIKeyReleaseEvent ,
17
- UIManager ,
18
12
UIMousePressEvent ,
19
13
UIMouseReleaseEvent ,
20
- UIWidget ,
21
- bind ,
22
14
)
23
15
from arcade .gui .experimental .controller import (
24
16
UIControllerButtonPressEvent ,
25
17
UIControllerButtonReleaseEvent ,
26
18
UIControllerDpadEvent ,
27
19
)
20
+ from arcade .gui .property import ListProperty , Property , bind
21
+ from arcade .gui .surface import Surface
22
+ from arcade .gui .ui_manager import UIManager
23
+ from arcade .gui .widgets import UIInteractiveWidget , UIWidget
24
+ from arcade .gui .widgets .layout import UIAnchorLayout
25
+ from arcade .gui .widgets .slider import UIBaseSlider
28
26
29
27
30
28
class Focusable (UIWidget ):
@@ -59,7 +57,7 @@ def ui(self) -> UIManager | None:
59
57
return None
60
58
61
59
62
- class UIFocusGroup ( UIAnchorLayout ):
60
+ class UIFocusMixin ( UIWidget ):
63
61
"""A group of widgets that can be focused.
64
62
65
63
UIFocusGroup maintains two lists of widgets:
@@ -82,8 +80,8 @@ class UIFocusGroup(UIAnchorLayout):
82
80
83
81
_debug = Property (False )
84
82
85
- def __init__ (self , size_hint = ( 1 , 1 ) , ** kwargs ):
86
- super ().__init__ (size_hint = size_hint , ** kwargs )
83
+ def __init__ (self , * args , ** kwargs ):
84
+ super ().__init__ (* args , ** kwargs )
87
85
88
86
bind (self , "_debug" , self .trigger_full_render )
89
87
bind (self , "_focused" , self .trigger_full_render )
@@ -253,6 +251,11 @@ def _do_render(self, surface: Surface, force=False) -> bool:
253
251
254
252
def do_post_render (self , surface : Surface ):
255
253
surface .limit (None )
254
+
255
+ if self ._focused < len (self ._focusable_widgets ):
256
+ warnings .warn ("Focused widget is out of range" )
257
+ return
258
+
256
259
widget = self ._focusable_widgets [self ._focused ]
257
260
arcade .draw_rect_outline (
258
261
rect = widget .rect ,
@@ -295,3 +298,7 @@ def _draw_indicator(self, start: Vec2, end: Vec2, color=arcade.color.WHITE):
295
298
@staticmethod
296
299
def is_focusable (widget ):
297
300
return isinstance (widget , (Focusable , UIInteractiveWidget ))
301
+
302
+
303
+ class UIFocusGroup (UIFocusMixin , UIAnchorLayout ):
304
+ pass
0 commit comments