Skip to content

Missing int conversions on cell_anchor_point math #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 16, 2021

Conversation

Neradoc
Copy link
Contributor

@Neradoc Neradoc commented Dec 16, 2021

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)

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)
@tannewt tannewt requested a review from FoamyGuy December 16, 2021 19:48
Copy link
Contributor

@FoamyGuy FoamyGuy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me. Thanks @Neradoc.

Tested on pyportal

@FoamyGuy FoamyGuy merged commit 84f1762 into adafruit:main Dec 16, 2021
@FoamyGuy FoamyGuy mentioned this pull request Dec 16, 2021
@FoamyGuy
Copy link
Contributor

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.

adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Dec 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants