Skip to content

Commit 89e71f3

Browse files
committed
fix lib imports and extract UIFocusMixin from UIFocusGroup
1 parent cf51a0e commit 89e71f3

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

arcade/gui/experimental/focus.py

+19-12
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,24 @@
55

66
import arcade
77
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 (
139
UIEvent,
14-
UIInteractiveWidget,
1510
UIKeyPressEvent,
1611
UIKeyReleaseEvent,
17-
UIManager,
1812
UIMousePressEvent,
1913
UIMouseReleaseEvent,
20-
UIWidget,
21-
bind,
2214
)
2315
from arcade.gui.experimental.controller import (
2416
UIControllerButtonPressEvent,
2517
UIControllerButtonReleaseEvent,
2618
UIControllerDpadEvent,
2719
)
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
2826

2927

3028
class Focusable(UIWidget):
@@ -59,7 +57,7 @@ def ui(self) -> UIManager | None:
5957
return None
6058

6159

62-
class UIFocusGroup(UIAnchorLayout):
60+
class UIFocusMixin(UIWidget):
6361
"""A group of widgets that can be focused.
6462
6563
UIFocusGroup maintains two lists of widgets:
@@ -82,8 +80,8 @@ class UIFocusGroup(UIAnchorLayout):
8280

8381
_debug = Property(False)
8482

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)
8785

8886
bind(self, "_debug", self.trigger_full_render)
8987
bind(self, "_focused", self.trigger_full_render)
@@ -253,6 +251,11 @@ def _do_render(self, surface: Surface, force=False) -> bool:
253251

254252
def do_post_render(self, surface: Surface):
255253
surface.limit(None)
254+
255+
if self._focused < len(self._focusable_widgets):
256+
warnings.warn("Focused widget is out of range")
257+
return
258+
256259
widget = self._focusable_widgets[self._focused]
257260
arcade.draw_rect_outline(
258261
rect=widget.rect,
@@ -295,3 +298,7 @@ def _draw_indicator(self, start: Vec2, end: Vec2, color=arcade.color.WHITE):
295298
@staticmethod
296299
def is_focusable(widget):
297300
return isinstance(widget, (Focusable, UIInteractiveWidget))
301+
302+
303+
class UIFocusGroup(UIFocusMixin, UIAnchorLayout):
304+
pass

arcade/gui/experimental/password_input.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
from typing import Optional
44

5-
from arcade.gui import Surface, UIEvent, UIInputText, UITextInputEvent
5+
from arcade.gui.events import UIEvent, UITextInputEvent
6+
from arcade.gui.surface import Surface
7+
from arcade.gui.widgets.text import UIInputText
68

79

810
class UIPasswordInput(UIInputText):

arcade/gui/experimental/scroll_area.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,19 @@
66

77
import arcade
88
from arcade import XYWH
9-
from arcade.gui import (
10-
Property,
11-
Surface,
9+
from arcade.gui.events import (
1210
UIEvent,
13-
UILayout,
1411
UIMouseDragEvent,
1512
UIMouseEvent,
1613
UIMouseMovementEvent,
1714
UIMousePressEvent,
1815
UIMouseReleaseEvent,
1916
UIMouseScrollEvent,
20-
UIWidget,
21-
bind,
2217
)
18+
from arcade.gui.property import Property, bind
19+
from arcade.gui.surface import Surface
20+
from arcade.gui.widgets import UIWidget
21+
from arcade.gui.widgets.layout import UILayout
2322
from arcade.types import LBWH
2423

2524

0 commit comments

Comments
 (0)