Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
You can grab pre-release versions from PyPi. See the available versions from the
Arcade [PyPi Release History](https://pypi.org/project/arcade/#history) page.

## Version 3.1.2 (unreleased)

- GUI
- Fix `UIScrollArea.add` always returning None
- Support `layer` in `UIView.add_widget()`

## Version 3.1.1

* Text objects are now lazy and can be created before the window
Expand Down
12 changes: 8 additions & 4 deletions arcade/gui/experimental/scroll_area.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import Iterable
from typing import Iterable, TypeVar

from pyglet.event import EVENT_UNHANDLED

Expand All @@ -23,6 +23,8 @@
)
from arcade.types import LBWH

W = TypeVar("W", bound="UIWidget")


class UIScrollBar(UIWidget):
"""Scroll bar for a UIScrollLayout.
Expand Down Expand Up @@ -210,7 +212,7 @@ def __init__(
y: float = 0,
width: float = 300,
height: float = 300,
children: Iterable["UIWidget"] = tuple(),
children: Iterable[UIWidget] = tuple(),
size_hint=None,
size_hint_min=None,
size_hint_max=None,
Expand Down Expand Up @@ -242,15 +244,17 @@ def __init__(
bind(self, "scroll_x", self.trigger_full_render)
bind(self, "scroll_y", self.trigger_full_render)

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

super().add(child, **kwargs)
self.trigger_full_render()

def remove(self, child: "UIWidget"):
return child

def remove(self, child: UIWidget):
"""Remove a child from the widget."""
super().remove(child)
self.trigger_full_render()
Expand Down
2 changes: 1 addition & 1 deletion arcade/gui/ui_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def on_update(self, time_delta):
"""Dispatches an update event to all widgets in the UIManager."""
return self.dispatch_ui_event(UIOnUpdateEvent(self, time_delta))

def draw(self, pixelated=False) -> None:
def draw(self, **kwargs) -> None:
"""Will draw all widgets to the window.

UIManager caches all rendered widgets into a framebuffer (something like a
Expand Down
12 changes: 9 additions & 3 deletions arcade/gui/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,15 @@ def __init__(self):
The UIManager of this view.
"""

def add_widget(self, widget: W) -> W:
"""Add a widget to the UIManager of this view."""
return self.ui.add(widget)
def add_widget(self, widget: W, *, index=None, layer=UIManager.DEFAULT_LAYER) -> W:
"""Add a widget to the UIManager of this view.

Args:
widget: widget to add
index: position a widget is added, None has the highest priority
layer: layer which the widget should be added to, higher layer are above
"""
return self.ui.add(widget, index=index, layer=layer)

def on_show_view(self):
"""If subclassing UIView, don't forget to call super().on_show_view()."""
Expand Down
Loading