Skip to content

Commit 58e1fb2

Browse files
committed
try to use resize function instead of width and height properties
1 parent c2d99a2 commit 58e1fb2

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

adafruit_displayio_layout/layouts/grid_layout.py

+22-8
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,28 @@ def _layout_cells(self):
7878
- 2 * self.cell_padding
7979
)
8080
)
81-
cell["content"].width = (
82-
int(button_size_x * self._width / grid_size_x)
83-
- 2 * self.cell_padding
84-
)
85-
cell["content"].height = (
86-
int(button_size_y * self._height / grid_size_y)
87-
- 2 * self.cell_padding
88-
)
81+
if hasattr(cell["content"], "resize"):
82+
# if it has resize function
83+
cell["content"].resize(
84+
(
85+
int(button_size_x * self._width / grid_size_x)
86+
- 2 * self.cell_padding
87+
),
88+
(
89+
int(button_size_y * self._height / grid_size_y)
90+
- 2 * self.cell_padding
91+
),
92+
)
93+
else:
94+
# try width and height properties.
95+
cell["content"].width = (
96+
int(button_size_x * self._width / grid_size_x)
97+
- 2 * self.cell_padding
98+
)
99+
cell["content"].height = (
100+
int(button_size_y * self._height / grid_size_y)
101+
- 2 * self.cell_padding
102+
)
89103

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

0 commit comments

Comments
 (0)