Skip to content

Updated label.py to correct position of initial blank text #81

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 4 commits into from
Aug 11, 2020
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
20 changes: 12 additions & 8 deletions adafruit_display_text/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,7 @@ def __init__(
self.width = max_glyphs
self._font = font
self._text = None
if anchor_point is None:
self._anchor_point = (0, 0)
else:
self._anchor_point = anchor_point
self._anchor_point = anchor_point
self.x = x
self.y = y

Expand Down Expand Up @@ -126,7 +123,7 @@ def __init__(

if text is not None:
self._update_text(str(text))
if anchored_position is not None:
if (anchored_position is not None) and (anchor_point is not None):
self.anchored_position = anchored_position

def _create_background_box(self, lines, y_offset):
Expand Down Expand Up @@ -374,14 +371,19 @@ def anchor_point(self):

@anchor_point.setter
def anchor_point(self, new_anchor_point):
current_anchored_position = self.anchored_position
self._anchor_point = new_anchor_point
self.anchored_position = current_anchored_position
if self._anchor_point is not None:
current_anchored_position = self.anchored_position
self._anchor_point = new_anchor_point
self.anchored_position = current_anchored_position
else:
self._anchor_point = new_anchor_point

@property
def anchored_position(self):
"""Position relative to the anchor_point. Tuple containing x,y
pixel coordinates."""
if self._anchor_point is None:
return None
return (
int(self.x + (self._anchor_point[0] * self._boundingbox[2] * self._scale)),
int(
Expand All @@ -393,6 +395,8 @@ def anchored_position(self):

@anchored_position.setter
def anchored_position(self, new_position):
if (self._anchor_point is None) or (new_position is None):
return # Note: anchor_point must be set before setting anchored_position
new_x = int(
new_position[0]
- self._anchor_point[0] * (self._boundingbox[2] * self._scale)
Expand Down