Skip to content

Commit

Permalink
Refactor anchor_point & anchored_position
Browse files Browse the repository at this point in the history
  • Loading branch information
lesamouraipourpre committed Jul 9, 2021
1 parent fb75d66 commit 4bef392
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 21 deletions.
8 changes: 4 additions & 4 deletions adafruit_display_text/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,9 @@ def anchor_point(self, new_anchor_point: Tuple[float, float]) -> None:
self._anchor_point = (new_anchor_point[0], -1.0)
else:
self._anchor_point = new_anchor_point
self.anchored_position = (
self._anchored_position
) # update the anchored_position using setter

# update the anchored_position using setter
self.anchored_position = self._anchored_position

@property
def anchored_position(self) -> Tuple[int, int]:
Expand All @@ -336,7 +336,7 @@ def anchored_position(self) -> Tuple[int, int]:
@anchored_position.setter
def anchored_position(self, new_position: Tuple[int, int]) -> None:
self._anchored_position = new_position
# Set anchored_position
# Calculate (x,y) position
if (self._anchor_point is not None) and (self._anchored_position is not None):
self.x = int(
new_position[0]
Expand Down
13 changes: 2 additions & 11 deletions adafruit_display_text/bitmap_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ def __init__(self, font, save_text=True, **kwargs) -> None:
font=font,
text=kwargs.get("text", ""),
line_spacing=self._line_spacing,
anchor_point=kwargs.get("anchor_point", None),
anchored_position=kwargs.get("anchored_position", None),
scale=kwargs.get("scale", 1),
)

Expand All @@ -116,8 +114,6 @@ def _reset_text(
font=None,
text: str = None,
line_spacing: float = None,
anchor_point: Tuple[float, float] = None,
anchored_position: Tuple[int, int] = None,
scale: int = None,
) -> None:

Expand All @@ -126,10 +122,6 @@ def _reset_text(
self._font = font
if line_spacing is not None:
self._line_spacing = line_spacing
if anchor_point is not None:
self._anchor_point = anchor_point
if anchored_position is not None:
self._anchored_position = anchored_position

# if text is not provided as a parameter (text is None), use the previous value.
if (text is None) and self._save_text:
Expand Down Expand Up @@ -258,10 +250,9 @@ def _reset_text(
): # Scale will be defined in local_group (Note: self should have scale=1)
self.scale = scale # call the setter

self.anchored_position = (
self._anchored_position
) # set the anchored_position with setter after bitmap is created, sets the
# set the anchored_position with setter after bitmap is created, sets the
# x,y positions of the label
self.anchored_position = self._anchored_position

@staticmethod
def _line_spacing_ypixels(font, line_spacing: float) -> int:
Expand Down
7 changes: 1 addition & 6 deletions adafruit_display_text/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ def __init__(self, font, **kwargs) -> None:
self.width = max_glyphs
self._font = font
self._text = None
self._anchor_point = kwargs.get("anchor_point", None)

self.height = self._font.get_bounding_box()[1]
self._bounding_box = None
Expand All @@ -113,11 +112,7 @@ def __init__(self, font, **kwargs) -> None:
self._palette.make_transparent(0)

if text is not None:
self._update_text(str(text))
if (kwargs.get("anchored_position", None) is not None) and (
kwargs.get("anchor_point", None) is not None
):
self.anchored_position = kwargs.get("anchored_position", None)
self._reset_text(str(text))

def _create_background_box(self, lines: int, y_offset: int) -> None:
"""Private Class function to create a background_box
Expand Down

0 comments on commit 4bef392

Please sign in to comment.