Skip to content

Commit 67f8bc9

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

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

adafruit_displayio_layout/layouts/grid_layout.py

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

114+
def layout_cells(self):
115+
"""render the grid with all cell content and dividers"""
116+
self._layout_cells()
117+
114118
def _layout_cells(self) -> None:
115119
# pylint: disable=too-many-locals, too-many-branches, too-many-statements
120+
for line_obj in self._divider_lines:
121+
self.remove(line_obj["rect"])
116122
for cell in self._cell_content_list:
117123
if cell["content"] not in self:
118124
grid_size_x = self.grid_size[0]
@@ -359,15 +365,16 @@ def _layout_cells(self) -> None:
359365
}
360366
)
361367

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

365371
def add_content(
366372
self,
367373
cell_content: displayio.Group,
368374
grid_position: Tuple[int, int],
369375
cell_size: Tuple[int, int],
370376
cell_anchor_point: Optional[Tuple[float, ...]] = None,
377+
layout_cells=True,
371378
) -> None:
372379
"""Add a child to the grid.
373380
@@ -395,7 +402,8 @@ def add_content(
395402
"cell_size": cell_size,
396403
}
397404
self._cell_content_list.append(sub_view_obj)
398-
self._layout_cells()
405+
if layout_cells:
406+
self._layout_cells()
399407

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

0 commit comments

Comments
 (0)