Skip to content

Commit cb263f1

Browse files
authored
Merge pull request #42 from FoamyGuy/grid_layout_label_fix
fix for content elements that dont allow setting width and height
2 parents fda9020 + 3272475 commit cb263f1

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

adafruit_displayio_layout/layouts/grid_layout.py

+14-9
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,20 @@ def _layout_cells(self):
7979
),
8080
)
8181
else:
82-
# try width and height properties.
83-
cell["content"].width = (
84-
int(button_size_x * self._width / grid_size_x)
85-
- 2 * self.cell_padding
86-
)
87-
cell["content"].height = (
88-
int(button_size_y * self._height / grid_size_y)
89-
- 2 * self.cell_padding
90-
)
82+
try:
83+
# try width and height properties.
84+
cell["content"].width = (
85+
int(button_size_x * self._width / grid_size_x)
86+
- 2 * self.cell_padding
87+
)
88+
cell["content"].height = (
89+
int(button_size_y * self._height / grid_size_y)
90+
- 2 * self.cell_padding
91+
)
92+
except AttributeError:
93+
# This element does not allow setting width and height.
94+
# No problem, we'll use whatever size it already is.
95+
pass
9196

9297
cell["content"].x = (
9398
int(grid_position_x * self._width / grid_size_x) + self.cell_padding

0 commit comments

Comments
 (0)