Skip to content

Commit 873672f

Browse files
committed
public layout_content. Don't add and remove lines many times unecessarily.
1 parent 4b0f993 commit 873672f

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

adafruit_displayio_layout/layouts/grid_layout.py

+15-8
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,13 @@ def __init__(
111111
):
112112
self.cell_padding = 1
113113

114+
def layout_cells(self):
115+
self._layout_cells()
116+
114117
def _layout_cells(self) -> None:
115118
# pylint: disable=too-many-locals, too-many-branches, too-many-statements
119+
for line_obj in self._divider_lines:
120+
self.remove(line_obj["rect"])
116121
for cell in self._cell_content_list:
117122
if cell["content"] not in self:
118123
grid_size_x = self.grid_size[0]
@@ -359,15 +364,16 @@ def _layout_cells(self) -> None:
359364
}
360365
)
361366

362-
for line_obj in self._divider_lines:
363-
self.append(line_obj["rect"])
367+
for line_obj in self._divider_lines:
368+
self.append(line_obj["rect"])
364369

365370
def add_content(
366-
self,
367-
cell_content: displayio.Group,
368-
grid_position: Tuple[int, int],
369-
cell_size: Tuple[int, int],
370-
cell_anchor_point: Optional[Tuple[float, ...]] = None,
371+
self,
372+
cell_content: displayio.Group,
373+
grid_position: Tuple[int, int],
374+
cell_size: Tuple[int, int],
375+
cell_anchor_point: Optional[Tuple[float, ...]] = None,
376+
layout_cells=True
371377
) -> None:
372378
"""Add a child to the grid.
373379
@@ -395,7 +401,8 @@ def add_content(
395401
"cell_size": cell_size,
396402
}
397403
self._cell_content_list.append(sub_view_obj)
398-
self._layout_cells()
404+
if layout_cells:
405+
self._layout_cells()
399406

400407
def get_cell(self, cell_coordinates: Tuple[int, int]) -> displayio.Group:
401408
"""

0 commit comments

Comments
 (0)