Skip to content

fix for anchored_position to work correctly with scaled label #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
18 changes: 12 additions & 6 deletions adafruit_display_text/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ def __init__(
padding_right=0,
**kwargs
):
if "scale" in kwargs.keys():
self._scale = kwargs["scale"]
else:
self._scale = 1
if not max_glyphs and not text:
raise RuntimeError("Please provide a max size, or initial text")
if not max_glyphs:
Expand Down Expand Up @@ -361,13 +365,15 @@ def anchored_position(self):

@anchored_position.setter
def anchored_position(self, new_position):
self.x = int(
new_x = int(
new_position[0]
- self._boundingbox[0]
- self._anchor_point[0] * self._boundingbox[2]
- self._anchor_point[0] * (self._boundingbox[2] * self._scale)
)
self.y = int(
new_y = self.y = int(
new_position[1]
- self._boundingbox[1]
- self._anchor_point[1] * self._boundingbox[3]
- self._anchor_point[1] * (self._boundingbox[3] * self._scale)
+ (self._boundingbox[3] * self._scale) / 2
)
self._boundingbox = (new_x, new_y, self._boundingbox[2], self._boundingbox[3])
self.x = new_x
self.y = new_y