Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: adafruit/Adafruit_CircuitPython_DisplayIO_Layout
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2.2.3
Choose a base ref
...
head repository: adafruit/Adafruit_CircuitPython_DisplayIO_Layout
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 3.0.0
Choose a head ref
  • 2 commits
  • 1 file changed
  • 2 contributors

Commits on Apr 2, 2025

  1. add pop_content, rename get_cell to get_content

    FoamyGuy committed Apr 2, 2025
    Copy the full SHA
    746b188 View commit details

Commits on Apr 5, 2025

  1. Merge pull request #99 from FoamyGuy/gridlayout_enhancements

    add pop_content() rename get_cell() to get_content()
    tannewt authored Apr 5, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    1af1781 View commit details
Showing with 39 additions and 7 deletions.
  1. +39 −7 adafruit_displayio_layout/layouts/grid_layout.py
46 changes: 39 additions & 7 deletions adafruit_displayio_layout/layouts/grid_layout.py
Original file line number Diff line number Diff line change
@@ -393,31 +393,63 @@ def add_content(
if layout_cells:
self._layout_cells()

def get_cell(self, cell_coordinates: Tuple[int, int]) -> displayio.Group:
def get_content(self, grid_position: Tuple[int, int]) -> displayio.Group:
"""
Return a cells content based on the cell_coordinates. Raises
Return a cells content based on the grid_position. Raises
KeyError if coordinates were not found in the GridLayout.
:param tuple cell_coordinates: the coordinates to lookup in the grid
:param tuple grid_position: the coordinates to lookup in the grid
:return: the displayio content object at those coordinates
"""
for index, cell in enumerate(self._cell_content_list):
# exact location 1x1 cell
if cell["grid_position"] == cell_coordinates:
if cell["grid_position"] == grid_position:
return self._cell_content_list[index]["content"]

# multi-spanning cell, any size bigger than 1x1
if (
cell["grid_position"][0]
<= cell_coordinates[0]
<= grid_position[0]
< cell["grid_position"][0] + cell["cell_size"][0]
and cell["grid_position"][1]
<= cell_coordinates[1]
<= grid_position[1]
< cell["grid_position"][1] + cell["cell_size"][1]
):
return self._cell_content_list[index]["content"]

raise KeyError(f"GridLayout does not contain cell at coordinates {cell_coordinates}")
raise KeyError(f"GridLayout does not contain content at coordinates {grid_position}")

def pop_content(self, grid_position: Tuple[int, int]) -> None:
"""
Remove and return a cells content based on the grid_position. Raises
KeyError if coordinates were not found in the GridLayout.
:param tuple grid_position: the coordinates to lookup in the grid
:return: the displayio content object at those coordinates
"""
for index, cell in enumerate(self._cell_content_list):
# exact location 1x1 cell
if cell["grid_position"] == grid_position:
_found = self._cell_content_list.pop(index)
self._layout_cells()
self.remove(_found["content"])
return _found["content"]

# multi-spanning cell, any size bigger than 1x1
if (
cell["grid_position"][0]
<= grid_position[0]
< cell["grid_position"][0] + cell["cell_size"][0]
and cell["grid_position"][1]
<= grid_position[1]
< cell["grid_position"][1] + cell["cell_size"][1]
):
_found = self._cell_content_list.pop(index)
self._layout_cells()
self.remove(_found["content"])
return _found["content"]

raise KeyError(f"GridLayout does not contain content at coordinates {grid_position}")

@property
def cell_size_pixels(self) -> Tuple[int, int]: