Skip to content

Commit bf06c47

Browse files
Add test for column-row-span with spacing (#1609)
* Add test for column-row-span with spacing * Fix test assertion value * Add fix for the failing test
1 parent b7dc2b2 commit bf06c47

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

arcade/gui/widgets/layout.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -640,19 +640,20 @@ def do_layout(self):
640640
principal_height_ratio_list = []
641641
principal_width_ratio_list = []
642642

643-
# making max_height_per_row and max_width_per_column uniform
643+
# Making cell height same for each row.
644644
for row in max_height_per_row:
645-
principal_height_ratio = max(height / (span or 1) for height, span in row)
645+
principal_height_ratio = max((height + self._vertical_spacing) / (span or 1) for height, span in row)
646646
principal_height_ratio_list.append(principal_height_ratio)
647647
for i, (height, span) in enumerate(row):
648-
if height / (span or 1) < principal_height_ratio:
648+
if (height + self._vertical_spacing) / (span or 1) < principal_height_ratio:
649649
row[i] = (principal_height_ratio * span, span)
650650

651+
# Making cell width same for each column.
651652
for col in max_width_per_column:
652-
principal_width_ratio = max(width / (span or 1) for width, span in col)
653+
principal_width_ratio = max((width + self._horizontal_spacing) / (span or 1) for width, span in col)
653654
principal_width_ratio_list.append(principal_width_ratio)
654655
for i, (width, span) in enumerate(col):
655-
if width / (span or 1) < principal_width_ratio:
656+
if (width + self._horizontal_spacing) / (span or 1) < principal_width_ratio:
656657
col[i] = (principal_width_ratio * span, span)
657658

658659
content_height = sum(principal_height_ratio_list) + self.row_count * self._vertical_spacing

tests/test_gui/test_layouting_gridlayout.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,35 @@ def test_place_widgets_with_col_row_span(window):
126126
assert dummy6.position == (200, 50)
127127

128128

129+
def test_place_widgets_with_col_row_span_and_spacing(window):
130+
dummy1 = UIDummy(width=100, height=100)
131+
dummy2 = UIDummy(width=100, height=100)
132+
dummy3 = UIDummy(width=100, height=100)
133+
dummy4 = UIDummy(width=100, height=100)
134+
dummy5 = UIDummy(width=220, height=100)
135+
136+
subject = UIGridLayout(
137+
column_count=2,
138+
row_count=3,
139+
horizontal_spacing=20,
140+
)
141+
142+
subject.add(dummy1, 0, 0)
143+
subject.add(dummy2, 0, 1)
144+
subject.add(dummy3, 1, 0)
145+
subject.add(dummy4, 1, 1)
146+
subject.add(dummy5, 0, 2, col_span=2)
147+
148+
subject.rect = Rect(0, 0, *subject.size_hint_min)
149+
subject.do_layout()
150+
151+
assert dummy1.position == (10, 200)
152+
assert dummy2.position == (10, 100)
153+
assert dummy3.position == (130, 200)
154+
assert dummy4.position == (130, 100)
155+
assert dummy5.position == (10, 0)
156+
157+
129158
def test_fit_content_by_default(window):
130159
subject = UIGridLayout(
131160
column_count=1,

0 commit comments

Comments
 (0)