Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions displayio/tilegrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,18 @@ def __init__(
self._flip_y = False
self._top_left_x = 0
self._top_left_y = 0
if tile_width is None:
if tile_width is None or tile_width == 0:
Copy link
Member

Choose a reason for hiding this comment

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

if not tile_width: would cover both cases.

tile_width = bitmap_width
if tile_height is None:
if tile_height is None or tile_width == 0:
tile_height = bitmap_height
if tile_width > 0 and bitmap_width % tile_width != 0:
if tile_width < 1:
tile_width = 1
Copy link
Member

Choose a reason for hiding this comment

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

Let's raise an exception instead. 0 makes no sense and should therefore be invalid.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We should probably fix it in display_text first.

if tile_height < 1:
tile_height = 1
if bitmap_width % tile_width != 0:
raise ValueError("Tile width must exactly divide bitmap width")
self._tile_width = tile_width
if tile_height > 0 and bitmap_height % tile_height != 0:
if bitmap_height % tile_height != 0:
raise ValueError("Tile height must exactly divide bitmap height")
self._tile_height = tile_height
if not 0 <= default_tile <= 255:
Expand Down Expand Up @@ -217,6 +221,9 @@ def _fill_area(self, buffer):
if self._hidden:
return

if self._bitmap.width <= 0 or self._bitmap.height <= 0:
return

image = Image.new(
"RGBA",
(self._width * self._tile_width, self._height * self._tile_height),
Expand Down Expand Up @@ -269,7 +276,7 @@ def _fill_area(self, buffer):
y *= self._absolute_transform.dy
x += self._absolute_transform.x
y += self._absolute_transform.y
buffer.alpha_composite(image, (x, y))
buffer.alpha_composite(image, (int(x), int(y)))

# pylint: enable=too-many-locals

Expand Down