Skip to content

Commit d020bab

Browse files
committed
fix for anchored_position to work correctly with scaled label
1 parent 1dcecb9 commit d020bab

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

adafruit_display_text/label.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ def __init__(
7979
padding_right=0,
8080
**kwargs
8181
):
82+
if "scale" in kwargs.keys():
83+
self._scale = kwargs["scale"]
84+
else:
85+
self._scale = 1
8286
if not max_glyphs and not text:
8387
raise RuntimeError("Please provide a max size, or initial text")
8488
if not max_glyphs:
@@ -361,13 +365,15 @@ def anchored_position(self):
361365

362366
@anchored_position.setter
363367
def anchored_position(self, new_position):
364-
self.x = int(
368+
new_x = int(
365369
new_position[0]
366-
- self._boundingbox[0]
367-
- self._anchor_point[0] * self._boundingbox[2]
370+
- self._anchor_point[0] * (self._boundingbox[2] * self._scale)
368371
)
369-
self.y = int(
372+
new_y = self.y = int(
370373
new_position[1]
371-
- self._boundingbox[1]
372-
- self._anchor_point[1] * self._boundingbox[3]
374+
- self._anchor_point[1] * (self._boundingbox[3] * self._scale)
375+
+ (self._boundingbox[3] * self._scale) / 2
373376
)
377+
self._boundingbox = (new_x, new_y, self._boundingbox[2], self._boundingbox[3])
378+
self.x = new_x
379+
self.y = new_y

0 commit comments

Comments
 (0)