From d54bec2a0c47546e8e41221735df39282ac35461 Mon Sep 17 00:00:00 2001 From: Maic Siemering Date: Mon, 3 Mar 2025 22:30:45 +0100 Subject: [PATCH 1/4] gui/fix color picker example added buttons to multiple layouts --- arcade/examples/gui/5_uicolor_picker.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) 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) From 12b647206604c82be5f7f099dafd3223fb5b9aa3 Mon Sep 17 00:00:00 2001 From: Maic Siemering Date: Tue, 4 Mar 2025 22:26:23 +0100 Subject: [PATCH 2/4] gui/fix with_background accepts iterables as color --- arcade/gui/widgets/__init__.py | 3 +++ 1 file changed, 3 insertions(+) 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 ...: From a3916d855e4f34927c6147a7d936a39269821382 Mon Sep 17 00:00:00 2001 From: Maic Siemering Date: Tue, 4 Mar 2025 22:32:42 +0100 Subject: [PATCH 3/4] gui/fix division by zero error, when container size ==0 --- arcade/gui/widgets/layout.py | 8 ++++++++ .../unit/gui/test_layouting_box_main_algorithm.py | 15 +++++++++++++++ 2 files changed, 23 insertions(+) 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 = [ From 027214a8a3455ec6cee09eac3eb4eb14f59ccfea Mon Sep 17 00:00:00 2001 From: Maic Siemering Date: Tue, 4 Mar 2025 22:46:56 +0100 Subject: [PATCH 4/4] add release notes --- CHANGELOG.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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