Skip to content

Updated background color handling for label #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Jun 6, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion adafruit_display_text/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __init__(
if not max_glyphs and not text:
raise RuntimeError("Please provide a max size, or initial text")
if not max_glyphs:
max_glyphs = len(text)
max_glyphs = len(text) + 1 # add one for the background bitmap tileGrid
super().__init__(max_size=max_glyphs, **kwargs)
self.width = max_glyphs
self._font = font
Expand Down Expand Up @@ -188,6 +188,18 @@ def _update_text(self, new_text): # pylint: disable=too-many-locals
self._text = new_text
self._boundingbox = (left, top, left + right, bottom - top)

background_bitmap = displayio.Bitmap(
self._boundingbox[2], self._boundingbox[3], 1
)

tile_grid = displayio.TileGrid(
background_bitmap, pixel_shader=self.palette, x=left, y=top
)

self.insert(
0, tile_grid
) # add background bitmaps to the bottom layer of the group

@property
def bounding_box(self):
"""An (x, y, w, h) tuple that completely covers all glyphs. The
Expand Down