Skip to content

Commit dfcc8a1

Browse files
authored
Merge pull request #2641 from pythonarcade/gui/improve-uiview
Gui/improve uiview
2 parents 4f940df + 08a526e commit dfcc8a1

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
You can grab pre-release versions from PyPi. See the available versions from the
44
Arcade [PyPi Release History](https://pypi.org/project/arcade/#history) page.
55

6+
## Version 3.1.2 (unreleased)
7+
8+
- GUI
9+
- Fix `UIScrollArea.add` always returning None
10+
- Support `layer` in `UIView.add_widget()`
11+
612
## Version 3.1.1
713

814
* Text objects are now lazy and can be created before the window

arcade/gui/experimental/scroll_area.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from typing import Iterable
3+
from typing import Iterable, TypeVar
44

55
from pyglet.event import EVENT_UNHANDLED
66

@@ -23,6 +23,8 @@
2323
)
2424
from arcade.types import LBWH
2525

26+
W = TypeVar("W", bound="UIWidget")
27+
2628

2729
class UIScrollBar(UIWidget):
2830
"""Scroll bar for a UIScrollLayout.
@@ -210,7 +212,7 @@ def __init__(
210212
y: float = 0,
211213
width: float = 300,
212214
height: float = 300,
213-
children: Iterable["UIWidget"] = tuple(),
215+
children: Iterable[UIWidget] = tuple(),
214216
size_hint=None,
215217
size_hint_min=None,
216218
size_hint_max=None,
@@ -242,15 +244,17 @@ def __init__(
242244
bind(self, "scroll_x", self.trigger_full_render)
243245
bind(self, "scroll_y", self.trigger_full_render)
244246

245-
def add(self, child: "UIWidget", **kwargs):
247+
def add(self, child: W, **kwargs) -> W:
246248
"""Add a child to the widget."""
247249
if self._children:
248250
raise ValueError("UIScrollArea can only have one child")
249251

250252
super().add(child, **kwargs)
251253
self.trigger_full_render()
252254

253-
def remove(self, child: "UIWidget"):
255+
return child
256+
257+
def remove(self, child: UIWidget):
254258
"""Remove a child from the widget."""
255259
super().remove(child)
256260
self.trigger_full_render()

arcade/gui/ui_manager.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def on_update(self, time_delta):
320320
"""Dispatches an update event to all widgets in the UIManager."""
321321
return self.dispatch_ui_event(UIOnUpdateEvent(self, time_delta))
322322

323-
def draw(self, pixelated=False) -> None:
323+
def draw(self, **kwargs) -> None:
324324
"""Will draw all widgets to the window.
325325
326326
UIManager caches all rendered widgets into a framebuffer (something like a

arcade/gui/view.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,15 @@ def __init__(self):
3131
The UIManager of this view.
3232
"""
3333

34-
def add_widget(self, widget: W) -> W:
35-
"""Add a widget to the UIManager of this view."""
36-
return self.ui.add(widget)
34+
def add_widget(self, widget: W, *, index=None, layer=UIManager.DEFAULT_LAYER) -> W:
35+
"""Add a widget to the UIManager of this view.
36+
37+
Args:
38+
widget: widget to add
39+
index: position a widget is added, None has the highest priority
40+
layer: layer which the widget should be added to, higher layer are above
41+
"""
42+
return self.ui.add(widget, index=index, layer=layer)
3743

3844
def on_show_view(self):
3945
"""If subclassing UIView, don't forget to call super().on_show_view()."""

0 commit comments

Comments
 (0)