Skip to content

Commit 46d158c

Browse files
authored
Adding a bunch of int conversions on cell_anchor_point math
In multiple places where `cell["cell_anchor_point"] * X` is used, the int conversion is missing, causing `TypeError: can't convert float to int` when an anchor_point is set to `(0.5, 0.5)` for example. ``` Traceback (most recent call last): File "code.py", line 9, in <module> File "code_pyportal.py", line 285, in switch_page File "/lib/adafruit_displayio_layout/layouts/grid_layout.py", line 413, in add_content File "/lib/adafruit_displayio_layout/layouts/grid_layout.py", line 182, in _layout_cells File "/lib/adafruit_displayio_layout/widgets/widget.py", line 297, in anchored_position File "/lib/adafruit_displayio_layout/widgets/widget.py", line 234, in _update_position TypeError: can't convert float to int ``` I didn't look into the math but I wonder, should it use `round()` rather that `int()` ? (which always rounds down)
1 parent 48b512a commit 46d158c

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

adafruit_displayio_layout/layouts/grid_layout.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,10 @@ def _layout_cells(self):
176176
cell["content"].anchored_position = (
177177
int(grid_position_x * self._width / grid_size_x)
178178
+ self.cell_padding
179-
+ (cell["cell_anchor_point"][0] * _measured_width),
179+
+ int(cell["cell_anchor_point"][0] * _measured_width),
180180
int(grid_position_y * self._height / grid_size_y)
181181
+ self.cell_padding
182-
+ (cell["cell_anchor_point"][1] * _measured_height),
182+
+ int(cell["cell_anchor_point"][1] * _measured_height),
183183
)
184184

185185
self.append(cell["content"])
@@ -236,29 +236,29 @@ def _layout_cells(self):
236236
cell["content"].anchored_position[1]
237237
+ _measured_height
238238
+ self.cell_padding
239-
- (cell["cell_anchor_point"][1] * _measured_height)
239+
- int(cell["cell_anchor_point"][1] * _measured_height)
240240
) - 1
241241
_bottom_line_loc_x = (
242242
cell["content"].anchored_position[0]
243243
- self.cell_padding
244-
- (cell["cell_anchor_point"][0] * _measured_width)
244+
- int(cell["cell_anchor_point"][0] * _measured_width)
245245
)
246246

247247
_top_line_loc_y = (
248248
cell["content"].anchored_position[1]
249249
- self.cell_padding
250-
- (cell["cell_anchor_point"][1] * _measured_height)
250+
- int(cell["cell_anchor_point"][1] * _measured_height)
251251
)
252252
_top_line_loc_x = (
253253
cell["content"].anchored_position[0]
254254
- self.cell_padding
255-
- (cell["cell_anchor_point"][0] * _measured_width)
255+
- int(cell["cell_anchor_point"][0] * _measured_width)
256256
)
257257

258258
_right_line_loc_y = (
259259
cell["content"].anchored_position[1]
260260
- self.cell_padding
261-
- (cell["cell_anchor_point"][1] * _measured_height)
261+
- int(cell["cell_anchor_point"][1] * _measured_height)
262262
)
263263
_right_line_loc_x = (
264264
(
@@ -267,7 +267,7 @@ def _layout_cells(self):
267267
+ self.cell_padding
268268
)
269269
- 1
270-
- (cell["cell_anchor_point"][0] * _measured_width)
270+
- int(cell["cell_anchor_point"][0] * _measured_width)
271271
)
272272

273273
_horizontal_divider_line = displayio.Shape(

0 commit comments

Comments
 (0)