diff --git a/src/textual/geometry.py b/src/textual/geometry.py index 1b7ceae78..1d98d7f9e 100644 --- a/src/textual/geometry.py +++ b/src/textual/geometry.py @@ -127,11 +127,6 @@ class Size(NamedTuple): return Region(0, 0, width, height) def __add__(self, other: object) -> Size: - if isinstance(other, Spacing): - width, height = self - other_width, other_height = other.totals - return Size(width + other_width, height + other_height) - if isinstance(other, tuple): width, height = self width2, height2 = other @@ -617,6 +612,7 @@ class Spacing(NamedTuple): @property def totals(self) -> tuple[int, int]: + """Total spacing for horizontal and vertical spacing.""" top, right, bottom, left = self return (left + right, top + bottom) diff --git a/tests/test_geometry.py b/tests/test_geometry.py index 2581f77d5..46f1517c8 100644 --- a/tests/test_geometry.py +++ b/tests/test_geometry.py @@ -251,6 +251,10 @@ def test_region_y_range(): assert Region(5, 10, 20, 30).y_range == range(10, 40) +def test_region_reset_origin(): + assert Region(5, 10, 20, 30).reset_origin == Region(0, 0, 20, 30) + + def test_region_expand(): assert Region(50, 10, 10, 5).expand((2, 3)) == Region(48, 7, 14, 11) @@ -280,6 +284,10 @@ def test_spacing_bottom_right(): assert Spacing(2, 3, 4, 5).bottom_right == (3, 4) +def test_spacing_totals(): + assert Spacing(2, 3, 4, 5).totals == (8, 6) + + def test_spacing_css(): assert Spacing(1, 1, 1, 1).css == "1" assert Spacing(1, 2, 1, 2).css == "1 2"