Skip to content

Commit 966c3ad

Browse files
Merge pull request #186 from Neradoc/fix-bitmap-label-anchored-position
Fix the position of bitmap_label with padding and anchored_position
2 parents 9112015 + 14b1e72 commit 966c3ad

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

adafruit_display_text/bitmap_label.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class Label(LabelBase):
8181
:param str label_direction: string defining the label text orientation. There are 5
8282
configurations possibles ``LTR``-Left-To-Right ``RTL``-Right-To-Left
8383
``UPD``-Upside Down ``UPR``-Upwards ``DWR``-Downwards. It defaults to ``LTR``
84-
:param bool verbose: print debugging information in some internal functions. Default to False
84+
:param bool verbose: print debugging information in some internal functions. Default to False
8585
8686
"""
8787

@@ -185,6 +185,7 @@ def _reset_text(
185185
y_offset = loose_y_offset
186186

187187
# Calculate the background size including padding
188+
tight_box_x = box_x
188189
box_x = box_x + self._padding_left + self._padding_right
189190
box_y = box_y + self._padding_top + self._padding_bottom
190191

@@ -245,17 +246,23 @@ def _reset_text(
245246
# Update bounding_box values. Note: To be consistent with label.py,
246247
# this is the bounding box for the text only, not including the background.
247248
if self._label_direction in ("UPR", "DWR"):
249+
if self._label_direction == "UPR":
250+
top = self._padding_right
251+
left = self._padding_top
252+
if self._label_direction == "DWR":
253+
top = self._padding_left
254+
left = self._padding_bottom
248255
self._bounding_box = (
249-
self._tilegrid.x,
250-
self._tilegrid.y,
256+
self._tilegrid.x + left,
257+
self._tilegrid.y + top,
251258
tight_box_y,
252-
box_x,
259+
tight_box_x,
253260
)
254261
else:
255262
self._bounding_box = (
256-
self._tilegrid.x,
257-
self._tilegrid.y,
258-
box_x,
263+
self._tilegrid.x + self._padding_left,
264+
self._tilegrid.y + self._padding_top,
265+
tight_box_x,
259266
tight_box_y,
260267
)
261268

0 commit comments

Comments
 (0)