Skip to content

Commit c2277a3

Browse files
authored
Gui/small fixes (#1426)
* UI: Fix Rect.center providing bottom left * UI: Fix UIManager.clear() * UI: Fix UILabel support multiline
1 parent 59f193e commit c2277a3

File tree

6 files changed

+31
-4
lines changed

6 files changed

+31
-4
lines changed

arcade/gui/ui_manager.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ def remove(self, child: UIWidget):
105105
children.remove(child)
106106
child.parent = None
107107
self.trigger_render()
108+
else:
109+
print()
110+
print()
108111

109112
def walk_widgets(self, *, root: Optional[UIWidget] = None) -> Iterable[UIWidget]:
110113
"""walks through widget tree, in reverse draw order (most top drawn widget first)"""
@@ -119,7 +122,7 @@ def clear(self):
119122
Remove all widgets from UIManager
120123
"""
121124
for layer in self.children.values():
122-
for widget in layer:
125+
for widget in layer[:]:
123126
self.remove(widget)
124127

125128
def get_widgets_at(self, pos, cls=UIWidget) -> Iterable[W]:

arcade/gui/widgets/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def center_y(self):
102102

103103
@property
104104
def center(self):
105-
return self.left, self.bottom
105+
return self.center_x, self.center_y
106106

107107
@property
108108
def position(self):

arcade/gui/widgets/text.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ def __init__(
7777
font_name=font_name,
7878
font_size=font_size,
7979
color=arcade.get_four_byte_color(text_color),
80-
width=None,
81-
height=None,
80+
width=width,
81+
height=height,
8282
bold=bold,
8383
italic=italic,
8484
stretch=stretch,

tests/test_gui/test_rect.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ def test_rect_align_center_y():
6060
assert new_rect == (10, -50, 100, 200)
6161

6262

63+
def test_rect_center():
64+
# WHEN
65+
rect = Rect(0, 0, 100, 200)
66+
67+
# THEN
68+
assert rect.center == (50, 100)
69+
70+
6371
def test_rect_align_top():
6472
# GIVEN
6573
rect = Rect(10, 20, 100, 200)

tests/test_gui/test_uimanager.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ def test_clear_removes_all_children(window):
7070
widget1 = UIDummy(x=50, y=50, width=100, height=100)
7171
manager.add(widget1)
7272

73+
widget2 = UIDummy(x=50, y=50, width=100, height=100)
74+
manager.add(widget2)
75+
7376
manager.clear()
7477

7578
assert widget1.parent is None
79+
assert widget2.parent is None
7680
assert list(manager.walk_widgets()) == []

tests/test_gui/test_widget_inputtext.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from arcade.gui import UILabel
12
from arcade.gui.events import UIEvent
23

34
from arcade.gui.widgets import UIDummy
@@ -14,3 +15,14 @@ def test_widget():
1415

1516
# THEN
1617
assert widget.rect == (0, 0, 100, 100)
18+
19+
def test_uilabel_support_multiline(window):
20+
# WHEN
21+
widget = UILabel(
22+
text="Lorem ipsum dolor",
23+
width=20,
24+
multiline=True,
25+
)
26+
27+
# THEN
28+
assert widget is not None

0 commit comments

Comments
 (0)