Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 9 additions & 2 deletions adafruit_magtag/magtag.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def __init__(
self._text_scale = []
self._text_font = []
self._text_line_spacing = []
self._text_anchor_point = []

gc.collect()

Expand All @@ -124,6 +125,7 @@ def add_text(
text_transform=None,
text_scale=1,
line_spacing=1.25,
text_anchor_point=(0, 0.5),
):
"""
Add text labels with settings
Expand Down Expand Up @@ -153,6 +155,10 @@ def add_text(
text_transform = None
if not isinstance(text_scale, (int, float)) or text_scale < 1:
text_scale = 1
if not isinstance(text_anchor_point, (tuple, list)):
text_anchor_point = (0, 0.5)
if not 0 <= text_anchor_point[0] <= 1 or not 0 <= text_anchor_point[1] <= 1:
raise ValueError("Text anchor point values should be between 0 and 1.")
text_scale = round(text_scale)
gc.collect()

Expand All @@ -166,6 +172,7 @@ def add_text(
self._text_transform.append(text_transform)
self._text_scale.append(text_scale)
self._text_line_spacing.append(line_spacing)
self._text_anchor_point.append(text_anchor_point)

# pylint: enable=too-many-arguments

Expand Down Expand Up @@ -255,8 +262,8 @@ def set_text(self, val, index=0, auto_refresh=True):
self._text_font[index], text=string, scale=self._text_scale[index]
)
self._text[index].color = self._text_color[index]
self._text[index].x = self._text_position[index][0]
self._text[index].y = self._text_position[index][1]
self._text[index].anchor_point = self._text_anchor_point[index]
self._text[index].anchored_position = self._text_position[index]
self._text[index].line_spacing = self._text_line_spacing[index]
elif index_in_splash is not None:
self._text[index] = None
Expand Down
3 changes: 2 additions & 1 deletion examples/bitcoin_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ def text_transform(val):
magtag.add_text(
text_font=terminalio.FONT,
text_position=(
10,
(magtag.graphics.display.width // 2) - 1,
(magtag.graphics.display.height // 2) - 1,
),
text_scale=3,
text_transform=text_transform,
text_anchor_point=(0.5, 0.5),
)

magtag.preload_font(b"$012345789") # preload numbers
Expand Down