Skip to content

Commit c16dac7

Browse files
authored
Merge pull request #4 from FoamyGuy/my_bitmap_label
simplifying example scripts. Awesome!
2 parents b14b945 + 3084b17 commit c16dac7

5 files changed

+245
-558
lines changed

adafruit_display_text/label.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,7 @@ def __init__(
9595
self.width = max_glyphs
9696
self._font = font
9797
self._text = None
98-
if anchor_point is None:
99-
self._anchor_point = (0, 0)
100-
else:
101-
self._anchor_point = anchor_point
98+
self._anchor_point = anchor_point
10299
self.x = x
103100
self.y = y
104101

@@ -126,7 +123,7 @@ def __init__(
126123

127124
if text is not None:
128125
self._update_text(str(text))
129-
if anchored_position is not None:
126+
if (anchored_position is not None) and (anchor_point is not None):
130127
self.anchored_position = anchored_position
131128

132129
def _create_background_box(self, lines, y_offset):
@@ -374,14 +371,19 @@ def anchor_point(self):
374371

375372
@anchor_point.setter
376373
def anchor_point(self, new_anchor_point):
377-
current_anchored_position = self.anchored_position
378-
self._anchor_point = new_anchor_point
379-
self.anchored_position = current_anchored_position
374+
if self._anchor_point is not None:
375+
current_anchored_position = self.anchored_position
376+
self._anchor_point = new_anchor_point
377+
self.anchored_position = current_anchored_position
378+
else:
379+
self._anchor_point = new_anchor_point
380380

381381
@property
382382
def anchored_position(self):
383383
"""Position relative to the anchor_point. Tuple containing x,y
384384
pixel coordinates."""
385+
if self._anchor_point is None:
386+
return None
385387
return (
386388
int(self.x + (self._anchor_point[0] * self._boundingbox[2] * self._scale)),
387389
int(
@@ -393,6 +395,8 @@ def anchored_position(self):
393395

394396
@anchored_position.setter
395397
def anchored_position(self, new_position):
398+
if (self._anchor_point is None) or (new_position is None):
399+
return # Note: anchor_point must be set before setting anchored_position
396400
new_x = int(
397401
new_position[0]
398402
- self._anchor_point[0] * (self._boundingbox[2] * self._scale)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import board
2+
import terminalio
3+
from adafruit_display_text import bitmap_label
4+
5+
6+
text = "Hello world"
7+
text_area = bitmap_label.Label(terminalio.FONT, text=text)
8+
text_area.x = 10
9+
text_area.y = 10
10+
board.DISPLAY.show(text_area)
11+
while True:
12+
pass

0 commit comments

Comments
 (0)