Skip to content

Commit fcd6a1d

Browse files
authored
Gui/3.x fixes (#2600)
* gui/fix color picker example added buttons to multiple layouts * gui/fix with_background accepts iterables as color * gui/fix division by zero error, when container size is 0 * update release notes
1 parent be83d1d commit fcd6a1d

File tree

5 files changed

+42
-6
lines changed

5 files changed

+42
-6
lines changed

CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ Arcade [PyPi Release History](https://pypi.org/project/arcade/#history) page.
66

77
## Version 3.0.1 (unreleased)
88

9+
### Improvements
10+
11+
- `UIWidget.with_background` now accepts a tuple for color
12+
13+
### Bug Fixes
14+
15+
- Fixed division error in box layout algorithm
16+
- Fix example added buttons to multiple layouts
17+
18+
19+
## Version 3.0.1
20+
921
### Bug Fixes
1022

1123
- Fixed blurriness in `UIWidget` text during interaction

arcade/examples/gui/5_uicolor_picker.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,10 @@ def __init__(self):
144144
)
145145
)
146146
for i, (name, color) in enumerate(self.colors.items()):
147-
button = self.root.add(
148-
ColorButton(
149-
color_name=name,
150-
color=color,
151-
size_hint=(1, 1),
152-
)
147+
button = ColorButton(
148+
color_name=name,
149+
color=color,
150+
size_hint=(1, 1),
153151
)
154152
self.grid.add(button, row=i // 5, column=i % 5)
155153

arcade/gui/widgets/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,9 @@ def with_background(
461461
self
462462
"""
463463
if color is not ...:
464+
if color is not None:
465+
color = Color.from_iterable(color)
466+
464467
self._bg_color = color
465468

466469
if texture is not ...:

arcade/gui/widgets/layout.py

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

3+
import warnings
34
from dataclasses import dataclass
45
from typing import Dict, Iterable, List, Optional, Tuple, TypeVar
56

@@ -900,6 +901,13 @@ def _box_axis_algorithm(constraints: list[_C], container_size: float) -> List[fl
900901
Returns:
901902
List of tuples with the sizes of each element
902903
"""
904+
905+
# if there is no space, return the min value of each constraint
906+
# this will cause a overflow, so we give a warning
907+
if container_size <= 0:
908+
warnings.warn("Container size is 0, cannot calculate sizes for children.")
909+
return [c.min for c in constraints]
910+
903911
# adjust hint value based on min and max values
904912
for c in constraints:
905913
c.hint = max(c.min / container_size, c.hint)

tests/unit/gui/test_layouting_box_main_algorithm.py

+15
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,21 @@ def test_shw_smaller_1(window):
3131
assert sizes == [10, 10, 50]
3232

3333

34+
def test_container_size_zero(window):
35+
# GIVEN
36+
entries = [
37+
_C(hint=0.1, min=50, max=None),
38+
_C(hint=0.1, min=50, max=None),
39+
_C(hint=0.5, min=50, max=None),
40+
]
41+
42+
# WHEN
43+
sizes = _box_axis_algorithm(entries, 0)
44+
45+
# THEN
46+
assert sizes == [50, 50, 50]
47+
48+
3449
def test_complex_example_with_max_value():
3550
# GIVEN
3651
entries = [

0 commit comments

Comments
 (0)