adafruit / Adafruit_CircuitPython_DisplayIO_Layout

A Circuitpython helper library for display element layout using displayio.
MIT License
10 stars 14 forks source link

Missing int conversions on cell_anchor_point math #65

Closed Neradoc closed 2 years ago

Neradoc commented 2 years ago

In multiple places where cell["cell_anchor_point"] * X is used, the int conversion is missing, causing an error when an anchor_point is set to (0.5, 0.5) for example. I only encountered the issue with lines 179-182, but I think the others are required too.

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)

FoamyGuy commented 2 years ago

I think it should always round down because we want to avoid if possible placing things outside of the display if they round up to a number higher than display size.