Skip to content

Commit

Permalink
UI: Support iteration over widget children (#1771)
Browse files Browse the repository at this point in the history
* UI: Support iteration over widget children
  • Loading branch information
eruvanos committed May 12, 2023
1 parent 246abe1 commit bdfb14d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions arcade/gui/widgets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,9 @@ def padding(self, args: Union[int, Tuple[int, int], Tuple[int, int, int, int]]):
def children(self) -> List["UIWidget"]:
return [child for child, data in self._children]

def __iter__(self):
return iter(self.children)

def resize(self, *, width=None, height=None):
self.rect = self.rect.resize(width=width, height=height)

Expand Down
2 changes: 2 additions & 0 deletions doc/programming_guide/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,12 @@ Changes
* ``UIWidget.padding_bottom``
* ``UIWidget.padding_left``
* Update and add example code.
* Iterable (providing direct children)

* New widgets:

* :py:class:`~arcade.gui.widgets.dropdown.UIDropdown`
* :py:class:`~arcade.gui.widgets.image.UIImage`
* :py:class:`~arcade.gui.widgets.slider.UISlider`
* :py:class:`~arcade.gui.widgets.constructs.UIButtonRow` (`PR1580 <https://github.com/pythonarcade/arcade/pull/1580>`_ and `PR1253 <https://github.com/pythonarcade/arcade/pull/1253>`_)

Expand Down
16 changes: 16 additions & 0 deletions tests/unit/gui/test_widget_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,19 @@ def on_event(event):

# THEN
assert triggered is True


def test_iterate_widget_children(window):
# GIVEN
parent = UIDummy()
child1 = UIDummy()
child2 = UIDummy()
child3 = UIDummy()

# WHEN
parent.add(child1)
parent.add(child2)
child2.add(child3)

# THEN
assert list(parent) == [child1, child2]

0 comments on commit bdfb14d

Please sign in to comment.