From 42579f870e08c496ce179b37b8153d0f3b57f63b Mon Sep 17 00:00:00 2001 From: FoamyGuy Date: Fri, 14 Aug 2020 18:59:22 -0500 Subject: [PATCH 1/3] fix anchored position rounding issue --- adafruit_display_text/label.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index 9f65598..d5af66d 100755 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -385,7 +385,7 @@ def anchored_position(self): if self._anchor_point is None: return None return ( - int(self.x + (self._anchor_point[0] * self._boundingbox[2] * self._scale)), + int(self.x + round(self._anchor_point[0] * self._boundingbox[2] * self._scale)), int( self.y + (self._anchor_point[1] * self._boundingbox[3] * self._scale) @@ -399,7 +399,7 @@ def anchored_position(self, new_position): 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) + - round(self._anchor_point[0] * (self._boundingbox[2] * self._scale)) ) new_y = int( new_position[1] From ff4be2722d62dbaba7299a21829c6ce6b4b53e7d Mon Sep 17 00:00:00 2001 From: FoamyGuy Date: Fri, 14 Aug 2020 19:00:20 -0500 Subject: [PATCH 2/3] black format --- adafruit_display_text/label.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index d5af66d..39619ad 100755 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -385,7 +385,10 @@ def anchored_position(self): if self._anchor_point is None: return None return ( - int(self.x + round(self._anchor_point[0] * self._boundingbox[2] * self._scale)), + int( + self.x + + round(self._anchor_point[0] * self._boundingbox[2] * self._scale) + ), int( self.y + (self._anchor_point[1] * self._boundingbox[3] * self._scale) From b598e15e793719f8b0c3f067327f82bcfe6afd4b Mon Sep 17 00:00:00 2001 From: FoamyGuy Date: Sat, 15 Aug 2020 12:43:21 -0500 Subject: [PATCH 3/3] fix y position shifting when text changes --- adafruit_display_text/label.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index 39619ad..fd299ba 100755 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -390,9 +390,11 @@ def anchored_position(self): + round(self._anchor_point[0] * self._boundingbox[2] * self._scale) ), int( - self.y - + (self._anchor_point[1] * self._boundingbox[3] * self._scale) - - round((self._boundingbox[3] * self._scale) / 2.0) + round( + self.y + + (self._anchor_point[1] * self._boundingbox[3] * self._scale) + - ((self._boundingbox[3] * self._scale) / 2.0) + ) ), ) @@ -405,9 +407,11 @@ def anchored_position(self, new_position): - round(self._anchor_point[0] * (self._boundingbox[2] * self._scale)) ) new_y = int( - new_position[1] - - (self._anchor_point[1] * self._boundingbox[3] * self._scale) - + round((self._boundingbox[3] * self._scale) / 2.0) + round( + new_position[1] + - (self._anchor_point[1] * self._boundingbox[3] * self._scale) + + ((self._boundingbox[3] * self._scale) / 2.0) + ) ) self.x = new_x self.y = new_y