diff --git a/CHANGELOG.md b/CHANGELOG.md index 56caa3ff3c..2537aaf645 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,18 @@ Arcade [PyPi Release History](https://pypi.org/project/arcade/#history) page. ## Version 3.0.1 (unreleased) +### Improvements + +- `UIWidget.with_background` now accepts a tuple for color + +### Bug Fixes + +- Fixed division error in box layout algorithm +- Fix example added buttons to multiple layouts + + +## Version 3.0.1 + ### Bug Fixes - Fixed blurriness in `UIWidget` text during interaction diff --git a/arcade/examples/gui/5_uicolor_picker.py b/arcade/examples/gui/5_uicolor_picker.py index 55e794bfea..46be1a2db6 100644 --- a/arcade/examples/gui/5_uicolor_picker.py +++ b/arcade/examples/gui/5_uicolor_picker.py @@ -144,12 +144,10 @@ def __init__(self): ) ) for i, (name, color) in enumerate(self.colors.items()): - button = self.root.add( - ColorButton( - color_name=name, - color=color, - size_hint=(1, 1), - ) + button = ColorButton( + color_name=name, + color=color, + size_hint=(1, 1), ) self.grid.add(button, row=i // 5, column=i % 5) diff --git a/arcade/gui/widgets/__init__.py b/arcade/gui/widgets/__init__.py index b7441fefd8..7d4f341a9c 100644 --- a/arcade/gui/widgets/__init__.py +++ b/arcade/gui/widgets/__init__.py @@ -461,6 +461,9 @@ def with_background( self """ if color is not ...: + if color is not None: + color = Color.from_iterable(color) + self._bg_color = color if texture is not ...: diff --git a/arcade/gui/widgets/layout.py b/arcade/gui/widgets/layout.py index 40764723d5..61cdfcd3a1 100644 --- a/arcade/gui/widgets/layout.py +++ b/arcade/gui/widgets/layout.py @@ -1,5 +1,6 @@ from __future__ import annotations +import warnings from dataclasses import dataclass from typing import Dict, Iterable, List, Optional, Tuple, TypeVar @@ -900,6 +901,13 @@ def _box_axis_algorithm(constraints: list[_C], container_size: float) -> List[fl Returns: List of tuples with the sizes of each element """ + + # if there is no space, return the min value of each constraint + # this will cause a overflow, so we give a warning + if container_size <= 0: + warnings.warn("Container size is 0, cannot calculate sizes for children.") + return [c.min for c in constraints] + # adjust hint value based on min and max values for c in constraints: c.hint = max(c.min / container_size, c.hint) diff --git a/tests/unit/gui/test_layouting_box_main_algorithm.py b/tests/unit/gui/test_layouting_box_main_algorithm.py index 092f7b410e..c111028d0a 100644 --- a/tests/unit/gui/test_layouting_box_main_algorithm.py +++ b/tests/unit/gui/test_layouting_box_main_algorithm.py @@ -31,6 +31,21 @@ def test_shw_smaller_1(window): assert sizes == [10, 10, 50] +def test_container_size_zero(window): + # GIVEN + entries = [ + _C(hint=0.1, min=50, max=None), + _C(hint=0.1, min=50, max=None), + _C(hint=0.5, min=50, max=None), + ] + + # WHEN + sizes = _box_axis_algorithm(entries, 0) + + # THEN + assert sizes == [50, 50, 50] + + def test_complex_example_with_max_value(): # GIVEN entries = [