Skip to content

Commit cfb3f13

Browse files
committed
Add bounds check in add_content
1 parent 5d089bc commit cfb3f13

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

adafruit_displayio_layout/layouts/grid_layout.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,15 @@ def add_content(
378378
then the cell_anchor_point from the GridLayout will be used.
379379
:return: None"""
380380

381+
grid_x = grid_position[0]
382+
grid_y = grid_position[1]
383+
max_grid_x = self.grid_size[0]
384+
max_grid_y = self.grid_size[1]
385+
if grid_x >= max_grid_x or grid_y >= max_grid_y:
386+
raise ValueError(
387+
f"Grid position {grid_position} is out of bounds for grid size {self.grid_size}"
388+
)
389+
381390
if cell_anchor_point:
382391
_this_cell_anchor_point = cell_anchor_point
383392
else:

0 commit comments

Comments
 (0)