Skip to content

Commit

Permalink
Free the bitmap when set to empty string
Browse files Browse the repository at this point in the history
In the latest release, setting the text to an empty string, then back to a string of the same size as the previous value, the bitmap label would not be updated. [See this code for example](https://github.com/adafruit/Adafruit_CircuitPython_MacroPad/blob/main/examples/macropad_grid_layout.py). In addition, clearing the memory when the text is empty seems to me to match expectations.

(Also use `text` instead of `self._text`).
  • Loading branch information
Neradoc committed Apr 2, 2022
1 parent a49295f commit 79561c4
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions adafruit_display_text/bitmap_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ def _reset_text(
for _ in self._local_group:
self._local_group.pop(0)

# Free the bitmap and tilegrid since they are removed
self._bitmap = None
self._tilegrid = None

else: # The text string is not empty, so create the Bitmap and TileGrid and
# append to the self Group

Expand Down Expand Up @@ -200,9 +204,7 @@ def _reset_text(
# Place the text into the Bitmap
self._place_text(
self._bitmap,
text
if self._label_direction != "RTL"
else "".join(reversed(self._text)),
text if self._label_direction != "RTL" else "".join(reversed(text)),
self._font,
self._padding_left - x_offset,
self._padding_top + y_offset,
Expand Down

0 comments on commit 79561c4

Please sign in to comment.