Skip to content

Commit b1eebc8

Browse files
authored
Merge pull request #211 from shubham0x13/main
Allow empty text and update text instantly
2 parents 3ba5f74 + f237d6c commit b1eebc8

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

adafruit_display_text/scrolling_label.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def __init__(
6666
self._last_animate_time = -1
6767
self.max_characters = max_characters
6868

69-
if text[-1] != " ":
69+
if text and text[-1] != " ":
7070
text = "{} ".format(text)
7171
self._full_text = text
7272

@@ -123,10 +123,10 @@ def current_index(self) -> int:
123123

124124
@current_index.setter
125125
def current_index(self, new_index: int) -> None:
126-
if new_index < len(self.full_text):
127-
self._current_index = new_index
128-
else:
126+
if self.full_text:
129127
self._current_index = new_index % len(self.full_text)
128+
else:
129+
self._current_index = 0
130130

131131
@property
132132
def full_text(self) -> str:
@@ -139,11 +139,12 @@ def full_text(self) -> str:
139139

140140
@full_text.setter
141141
def full_text(self, new_text: str) -> None:
142-
if new_text[-1] != " ":
142+
if new_text and new_text[-1] != " ":
143143
new_text = "{} ".format(new_text)
144-
self._full_text = new_text
145-
self.current_index = 0
146-
self.update()
144+
if new_text != self._full_text:
145+
self._full_text = new_text
146+
self.current_index = 0
147+
self.update(True)
147148

148149
@property
149150
def text(self):

0 commit comments

Comments
 (0)