Skip to content

Commit 66a6bde

Browse files
committed
lookup cell from list instead of dictionary
1 parent aa8e69c commit 66a6bde

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

adafruit_displayio_layout/layouts/grid_layout.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ def __init__(self, x, y, width, height, grid_size, cell_padding):
5252
self.grid_size = grid_size
5353
self.cell_padding = cell_padding
5454
self._cell_content_list = []
55-
self._cell_dictionary = {}
5655

5756
def _layout_cells(self):
5857

@@ -121,7 +120,6 @@ def add_content(self, cell_content, grid_position, cell_size):
121120
"cell_size": cell_size,
122121
}
123122
self._cell_content_list.append(sub_view_obj)
124-
self._cell_dictionary[grid_position] = len(self._cell_content_list) - 1
125123
self._layout_cells()
126124

127125
def get_cell(self, cell_coordinates):
@@ -132,10 +130,11 @@ def get_cell(self, cell_coordinates):
132130
:param tuple cell_coordinates: the coordinates to lookup in the grid
133131
:return: the displayio content object at those coordinates
134132
"""
135-
if cell_coordinates in self._cell_dictionary:
136-
return self._cell_content_list[self._cell_dictionary[cell_coordinates]][
137-
"content"
138-
]
133+
for index, cell in enumerate(self._cell_content_list):
134+
if cell["grid_position"] == cell_coordinates:
135+
return self._cell_content_list[index][
136+
"content"
137+
]
139138

140139
raise KeyError(
141140
"GridLayout does not contain cell at coordinates {}".format(

0 commit comments

Comments
 (0)