Skip to content

Commit

Permalink
Merge pull request #22 from neoxharsh/master
Browse files Browse the repository at this point in the history
Added "cx" and "cy" property to the label to change center of Label
  • Loading branch information
kattni committed Jan 28, 2020
2 parents 06bec73 + 86130b3 commit 4d53a37
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions adafruit_display_text/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ def __init__(self, font, *, text=None, max_glyphs=None, color=0xffffff,
self.width = max_glyphs
self.font = font
self._text = None
self._anchor_point = (0, 0)
self.x = 0
self.y = 0

self.palette = displayio.Palette(2)
self.palette.make_transparent(0)
Expand Down Expand Up @@ -173,3 +176,26 @@ def text(self):
@text.setter
def text(self, new_text):
self._update_text(new_text)

@property
def anchor_point(self):
"""Point that anchored_position moves relative to.
Tuple with decimal percentage of width and height.
(E.g. (0,0) is top left, (1.0, 0.5): is middle right.)"""
return self._anchor_point

@anchor_point.setter
def anchor_point(self, new_anchor_point):
self._anchor_point = new_anchor_point

@property
def anchored_position(self):
"""Position relative to the anchor_point. Tuple containing x,y
pixel coordinates."""
return (self.x-self._boundingbox[2]*self._anchor_point[0],
self.y-self._boundingbox[3]*self._anchor_point[1])

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

0 comments on commit 4d53a37

Please sign in to comment.