Skip to content

Commit 79561c4

Browse files
committed
Free the bitmap when set to empty string
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`).
1 parent a49295f commit 79561c4

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

adafruit_display_text/bitmap_label.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ def _reset_text(
154154
for _ in self._local_group:
155155
self._local_group.pop(0)
156156

157+
# Free the bitmap and tilegrid since they are removed
158+
self._bitmap = None
159+
self._tilegrid = None
160+
157161
else: # The text string is not empty, so create the Bitmap and TileGrid and
158162
# append to the self Group
159163

@@ -200,9 +204,7 @@ def _reset_text(
200204
# Place the text into the Bitmap
201205
self._place_text(
202206
self._bitmap,
203-
text
204-
if self._label_direction != "RTL"
205-
else "".join(reversed(self._text)),
207+
text if self._label_direction != "RTL" else "".join(reversed(text)),
206208
self._font,
207209
self._padding_left - x_offset,
208210
self._padding_top + y_offset,

0 commit comments

Comments
 (0)