Skip to content

Commit 9df5ffb

Browse files
authored
Gui/fixes (#2795)
* Fix UIManager to correctly handle size hint of (0, 0) * Refactor UIScrollArea to allow multiple children and detect UIScrollArea in UIDropdown * Update CHANGELOG.md to reflect UIScrollArea enhancements and UIDropdown positioning fix
1 parent 225a191 commit 9df5ffb

File tree

5 files changed

+26
-11
lines changed

5 files changed

+26
-11
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ Arcade [PyPi Release History](https://pypi.org/project/arcade/#history) page.
88
- Upgraded Pillow to 12.0.0 for Python 3.14 support.
99
- Adds a new `arcade.NoAracdeWindowError` exception type. This is raised when certain window operations are performed and there is no valid Arcade window found. Previously where this error would be raised, we raised a standard `RuntimeError`, this made it harder to properly catch and act accordingly. This new exception subclasses `RuntimeError`, so you can still catch this error the same way as before. The `arcade.get_window()` function will now raise this if there is no window.
1010
- Along with the new exception type, is a new `arcade.windows_exists()` function which will return True or False based on if there is currently an active window.
11+
- GUI
12+
- `UIManager` did not apply size hint of (0,0). Mainly an issue with `UIBoxLayout`.
13+
- Allow multiple children in `UIScrollArea`.
14+
- Fix `UIDropdown Overlay` positioning within a `UIScrollArea`.
1115

1216
## 3.3.3
1317

arcade/gui/experimental/scroll_area.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,6 @@ def __init__(
239239

240240
def add(self, child: W, **kwargs) -> W:
241241
"""Add a child to the widget."""
242-
if self._children:
243-
raise ValueError("UIScrollArea can only have one child")
244-
245242
super().add(child, **kwargs)
246243
self.trigger_full_render()
247244

arcade/gui/ui_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ def _do_layout(self):
246246
# actual layout
247247
if child.size_hint:
248248
sh_x, sh_y = child.size_hint
249-
nw = surface_width * sh_x if sh_x else None
250-
nh = surface_height * sh_y if sh_y else None
249+
nw = surface_width * sh_x if sh_x is not None else None
250+
nh = surface_height * sh_y if sh_y is not None else None
251251
child.rect = child.rect.resize(nw, nh, anchor=AnchorPoint.BOTTOM_LEFT)
252252

253253
if child.size_hint_min:

arcade/gui/widgets/dropdown.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from arcade import uicolor
77
from arcade.gui import UIEvent, UIMousePressEvent
88
from arcade.gui.events import UIControllerButtonPressEvent, UIOnChangeEvent, UIOnClickEvent
9+
from arcade.gui.experimental import UIScrollArea
910
from arcade.gui.experimental.focus import UIFocusMixin
1011
from arcade.gui.ui_manager import UIManager
1112
from arcade.gui.widgets import UILayout, UIWidget
@@ -21,7 +22,7 @@ class _UIDropdownOverlay(UIFocusMixin, UIBoxLayout):
2122

2223
# TODO move also options logic to this class
2324

24-
def show(self, manager: UIManager):
25+
def show(self, manager: UIManager | UIScrollArea):
2526
manager.add(self, layer=UIManager.OVERLAY_LAYER)
2627

2728
def hide(self):
@@ -197,11 +198,19 @@ def _update_options(self):
197198
self._overlay.detect_focusable_widgets()
198199

199200
def _show_overlay(self):
200-
manager = self.get_ui_manager()
201-
if manager is None:
202-
raise Exception("UIDropdown could not find UIManager in its parents.")
203-
204-
self._overlay.show(manager)
201+
# traverse parents until UIManager or UIScrollArea is found
202+
parent = self.parent
203+
while parent is not None:
204+
if isinstance(parent, UIManager):
205+
break
206+
if isinstance(parent, UIScrollArea):
207+
break
208+
parent = parent.parent
209+
210+
if parent is None:
211+
raise Exception("UIDropdown could not find a valid parent for the overlay.")
212+
213+
self._overlay.show(parent)
205214

206215
def _on_button_click(self, _: UIOnClickEvent):
207216
self._show_overlay()

tests/unit/gui/test_uimanager_layouting.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,21 @@ def test_supports_size_hint(window):
2525
widget3 = UIDummy()
2626
widget3.size_hint = (1, None)
2727

28+
widget4 = UIDummy()
29+
widget4.size_hint = (0, 0)
30+
2831
manager.add(widget1)
2932
manager.add(widget2)
3033
manager.add(widget3)
34+
manager.add(widget4)
3135

3236
with sized(window, 200, 300):
3337
manager.draw()
3438

3539
assert widget1.size == Vec2(200, 300)
3640
assert widget2.size == Vec2(100, 75)
3741
assert widget3.size == Vec2(200, 100)
42+
assert widget4.size == Vec2(0, 0)
3843

3944

4045
def test_supports_size_hint_min(window):

0 commit comments

Comments
 (0)