Skip to content

Commit 119f638

Browse files
committed
try to truncate text instead of raising error if button is not big enough
1 parent 760084b commit 119f638

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

adafruit_button.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,13 @@ def label(self, newtext):
192192
self._label = Label(self._label_font, text=newtext)
193193
dims = self._label.bounding_box
194194
if dims[2] >= self.width or dims[3] >= self.height:
195-
raise RuntimeError("Button not large enough for label")
195+
while len(self._label.text) > 1 and (
196+
dims[2] >= self.width or dims[3] >= self.height
197+
):
198+
self._label.text = "{}.".format(self._label.text[:-2])
199+
dims = self._label.bounding_box
200+
if len(self._label.text) <= 1:
201+
raise RuntimeError("Button not large enough for label")
196202
self._label.x = (self.width - dims[2]) // 2
197203
self._label.y = self.height // 2
198204
self._label.color = self._label_color

0 commit comments

Comments
 (0)