Skip to content
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
27 changes: 23 additions & 4 deletions adafruit_display_text/scrolling_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ def __init__(
self.animate_time = animate_time
self._current_index = current_index
self._last_animate_time = -1
self.max_characters = max_characters
self._max_characters = max_characters

if text and text[-1] != " ":
if text and text[-1] != " " and len(text) > max_characters:
text = f"{text} "
self._full_text = text

self.update()
self.update(True)

def update(self, force: bool = False) -> None:
"""Attempt to update the display. If ``animate_time`` has elapsed since
Expand Down Expand Up @@ -137,7 +137,7 @@ def full_text(self) -> str:

@full_text.setter
def full_text(self, new_text: str) -> None:
if new_text and new_text[-1] != " ":
if new_text and new_text[-1] != " " and len(new_text) > self.max_characters:
new_text = f"{new_text} "
if new_text != self._full_text:
self._full_text = new_text
Expand All @@ -156,3 +156,22 @@ def text(self):
@text.setter
def text(self, new_text):
self.full_text = new_text

@property
def max_characters(self):
"""The maximum number of characters to display on screen.

:return int: The maximum character length of this label.
"""
return self._max_characters

@max_characters.setter
def max_characters(self, new_max_characters):
"""Recalculate the full text based on the new max characters.

This is necessary to correctly handle the potential space at the end of
the text.
"""
if new_max_characters != self._max_characters:
self._max_characters = new_max_characters
self.full_text = self.full_text