Skip to content

Commit 54acb53

Browse files
authored
Merge pull request #83 from FoamyGuy/fix_anchored_position_rounding
Fix anchored position rounding
2 parents 5a514ce + b598e15 commit 54acb53

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

adafruit_display_text/label.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -386,11 +386,16 @@ def anchored_position(self):
386386
if self._anchor_point is None:
387387
return None
388388
return (
389-
int(self.x + (self._anchor_point[0] * self._boundingbox[2] * self._scale)),
390389
int(
391-
self.y
392-
+ (self._anchor_point[1] * self._boundingbox[3] * self._scale)
393-
- round((self._boundingbox[3] * self._scale) / 2.0)
390+
self.x
391+
+ round(self._anchor_point[0] * self._boundingbox[2] * self._scale)
392+
),
393+
int(
394+
round(
395+
self.y
396+
+ (self._anchor_point[1] * self._boundingbox[3] * self._scale)
397+
- ((self._boundingbox[3] * self._scale) / 2.0)
398+
)
394399
),
395400
)
396401

@@ -400,12 +405,14 @@ def anchored_position(self, new_position):
400405
return # Note: anchor_point must be set before setting anchored_position
401406
new_x = int(
402407
new_position[0]
403-
- self._anchor_point[0] * (self._boundingbox[2] * self._scale)
408+
- round(self._anchor_point[0] * (self._boundingbox[2] * self._scale))
404409
)
405410
new_y = int(
406-
new_position[1]
407-
- (self._anchor_point[1] * self._boundingbox[3] * self._scale)
408-
+ round((self._boundingbox[3] * self._scale) / 2.0)
411+
round(
412+
new_position[1]
413+
- (self._anchor_point[1] * self._boundingbox[3] * self._scale)
414+
+ ((self._boundingbox[3] * self._scale) / 2.0)
415+
)
409416
)
410417
self.x = new_x
411418
self.y = new_y

0 commit comments

Comments
 (0)