Skip to content

Commit 644de5a

Browse files
committed
fix vertical alignment of outlined accents. backwards compat classes. manual display.refresh() for scrolling.
1 parent 021ba40 commit 644de5a

File tree

5 files changed

+66
-12
lines changed

5 files changed

+66
-12
lines changed

adafruit_display_text/bitmap_label.py

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -587,13 +587,28 @@ def _place_text(
587587
# only one accent range can effect a given character
588588
break
589589

590+
if (
591+
not accented
592+
and self._has_outline_accent()
593+
or accented
594+
and accent_type == "foreground_background"
595+
):
596+
y_blit_target += self._outline_size
597+
590598
if accented:
591-
bitmaptools.blit(
592-
bitmap,
593-
self._tmp_glyph_bitmap,
594-
max(xposition + my_glyph.dx, 0),
595-
y_blit_target,
596-
)
599+
try:
600+
bitmaptools.blit(
601+
bitmap,
602+
self._tmp_glyph_bitmap,
603+
max(xposition + my_glyph.dx, 0),
604+
y_blit_target,
605+
)
606+
except ValueError:
607+
# It's possible to overshoot the width of the bitmap if max_characters
608+
# is enabled and outline is used on at least some of the text.
609+
# In this case just skip any characters that fall outside the
610+
# max_characters box size without accounting for outline size.
611+
pass
597612
else:
598613
try:
599614
self._blit(
@@ -651,6 +666,12 @@ def _add_outline(self, bitmap):
651666
"Try using either larger padding sizes, or smaller outline_size."
652667
) from value_error
653668

669+
def _has_outline_accent(self):
670+
for accent in self._accent_ranges:
671+
if accent[ACCENT_TYPE] == "outline":
672+
return True
673+
return False
674+
654675
def _blit(
655676
self,
656677
bitmap: displayio.Bitmap, # target bitmap
@@ -777,14 +798,14 @@ def bitmap(self) -> displayio.Bitmap:
777798
"""
778799
return self._bitmap
779800

780-
def update(self, force: bool = False) -> None:
801+
def update(self, force: bool = False) -> bool:
781802
"""Attempt to update the display. If ``animate_time`` has elapsed since
782803
previews animation frame then move the characters over by 1 index.
783804
Must be called in the main loop of user code.
784805
785806
:param bool force: whether to ignore ``animation_time`` and force the update.
786807
Default is False.
787-
:return: None
808+
:return: bool updated: whether anything changed and the display needs to be refreshed.
788809
"""
789810
_now = adafruit_ticks.ticks_ms()
790811
if force or adafruit_ticks.ticks_less(
@@ -815,10 +836,13 @@ def update(self, force: bool = False) -> None:
815836

816837
_showing_string = f"{_showing_string_start}{_showing_string_end}"
817838
self._set_text(_showing_string, self.scale)
818-
self.current_index += 1
839+
if not force:
840+
self.current_index += 1
819841
self._last_animate_time = _now
820842

821-
return
843+
return True
844+
845+
return False
822846

823847
@property
824848
def current_index(self) -> int:
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SPDX-FileCopyrightText: 2025 Tim C for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
import warnings
5+
6+
from .bitmap_label import Label as BitmapLabel
7+
8+
warnings.warn(
9+
"outlined_label.OutlinedLabel is deprecated, adafruit_display_text.bitmap_label.Label"
10+
" now supports outline functionality with the same API, it should be used instead."
11+
)
12+
OutlineLabel = BitmapLabel
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SPDX-FileCopyrightText: 2025 Tim C for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
import warnings
5+
6+
from .bitmap_label import Label as BitmapLabel
7+
8+
warnings.warn(
9+
"scrolling_label.ScrollingLabel is deprecated, adafruit_display_text.bitmap_label.Label"
10+
" now supports scrolling functionality with the same API, it should be used instead."
11+
)
12+
ScrollingLabel = BitmapLabel

examples/display_text_accent_scrolling_example.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,8 @@
3333
scrolling_label.add_accent_to_substring("CircuitPython", 5, 6)
3434
scrolling_label.add_accent_to_substring("awesome!", 3, 4, "outline")
3535

36+
display.auto_refresh = False
37+
display.refresh()
3638
while True:
37-
scrolling_label.update()
39+
if scrolling_label.update():
40+
display.refresh()

examples/display_text_scrolling_label.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@
1212
scrolling_label.x = 10
1313
scrolling_label.y = 10
1414
display.root_group = scrolling_label
15+
display.auto_refresh = False
16+
display.refresh()
1517
while True:
16-
scrolling_label.update()
18+
if scrolling_label.update():
19+
display.refresh()

0 commit comments

Comments
 (0)