Skip to content

Commit c5af111

Browse files
committed
remove background tilegrid if text is set to empty and no padding. Fix for Group insert/append issue
1 parent aa4d0a0 commit c5af111

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

adafruit_display_text/label.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,13 @@ def _update_background_color(self, new_color):
190190
)
191191
lines = self.text.count("\n") + 1
192192
if not self._added_background_tilegrid:
193-
self._added_background_tilegrid = True
194-
self.insert(0, self._create_background_box(lines, y_offset))
193+
# only if we have text or padding
194+
if len(self.text) + self._padding_left + self._padding_right > 0:
195+
if len(self) > 0:
196+
self.insert(0, self._create_background_box(lines, y_offset))
197+
else:
198+
self.append(self._create_background_box(lines, y_offset))
199+
self._added_background_tilegrid = True
195200
else:
196201
self[0] = self._create_background_box(lines, y_offset)
197202

@@ -294,6 +299,11 @@ def _update_text(
294299
self.insert(0, self._create_background_box(lines, y_offset))
295300
else:
296301
self[0] = self._create_background_box(lines, y_offset)
302+
else:
303+
self._background_palette.make_transparent(0)
304+
if self._added_background_tilegrid:
305+
self.pop(0)
306+
self._added_background_tilegrid = False
297307

298308
@property
299309
def bounding_box(self):

0 commit comments

Comments
 (0)