Skip to content

Fix memory issues with label reuse and use of bitmap label #19

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 3 commits into from
Mar 8, 2021
Merged
Changes from all commits
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
30 changes: 16 additions & 14 deletions adafruit_portalbase/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import time
import terminalio
from adafruit_bitmap_font import bitmap_font
from adafruit_display_text.label import Label
from adafruit_display_text.bitmap_label import Label
from adafruit_display_text import wrap_text_to_lines

__version__ = "0.0.0-auto.0"
Expand Down Expand Up @@ -237,27 +237,29 @@ def set_text(self, val, index=0):
index_in_splash = self.splash.index(self._text[index]["label"])
elif self._debug:
print("Creating text area with :", string)

if len(string) > 0:
self._text[index]["label"] = Label(
self._fonts[self._text[index]["font"]],
text=string,
scale=self._text[index]["scale"],
)
if self._text[index]["label"] is None:
self._text[index]["label"] = Label(
self._fonts[self._text[index]["font"]],
text=string,
scale=self._text[index]["scale"],
)
if index_in_splash is not None:
self.splash[index_in_splash] = self._text[index]["label"]
else:
self.splash.append(self._text[index]["label"])
else:
self._text[index]["label"].text = string
self._text[index]["label"].color = self._text[index]["color"]
self._text[index]["label"].anchor_point = self._text[index]["anchor_point"]
self._text[index]["label"].anchored_position = self._text[index]["position"]
self._text[index]["label"].line_spacing = self._text[index]["line_spacing"]
elif index_in_splash is not None:
self._text[index]["label"] = None

if index_in_splash is not None:
if self._text[index]["label"] is not None:
self.splash[index_in_splash] = self._text[index]["label"]
else:
del self.splash[index_in_splash]
elif self._text[index]["label"] is not None:
self.splash.append(self._text[index]["label"])
# Remove the label from splash
if index_in_splash is not None and self._text[index]["label"] is None:
del self.splash[index_in_splash]

def preload_font(self, glyphs=None, index=0):
# pylint: disable=line-too-long
Expand Down