Skip to content

Commit 19fba30

Browse files
committed
fix anchored positioning for TextBox, update example to use it.
1 parent cf697a8 commit 19fba30

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

adafruit_display_text/text_box.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ def _reset_text(
264264
# Calculate both "tight" and "loose" bounding box dimensions to match label for
265265
# anchor_position calculations
266266
(
267-
box_x,
267+
box_x, # noqa: F841, var assigned not used
268268
tight_box_y,
269269
x_offset,
270270
tight_y_offset,
@@ -288,8 +288,6 @@ def _reset_text(
288288
y_offset = loose_y_offset
289289

290290
# Calculate the background size including padding
291-
tight_box_x = box_x
292-
box_x = box_x + self._padding_left + self._padding_right
293291
box_y = box_y + self._padding_top + self._padding_bottom
294292

295293
if self.dynamic_height:
@@ -343,8 +341,8 @@ def _reset_text(
343341
self._bounding_box = (
344342
self._tilegrid.x + self._padding_left,
345343
self._tilegrid.y + self._padding_top,
346-
tight_box_x,
347-
tight_box_y,
344+
self.width,
345+
self.height,
348346
)
349347

350348
if (

examples/display_text_text_box_simpletest.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from adafruit_display_text.text_box import TextBox
99

10+
display = board.DISPLAY
1011
main_group = displayio.Group()
1112

1213
left_text = ("Left left left left " * 2).rstrip()
@@ -21,8 +22,8 @@
2122
scale=1,
2223
)
2324

24-
left_text_area.x = 10
25-
left_text_area.y = 10
25+
left_text_area.anchor_point = (0, 0)
26+
left_text_area.anchored_position = (0, 0)
2627
main_group.append(left_text_area)
2728

2829

@@ -38,8 +39,8 @@
3839
scale=1,
3940
)
4041

41-
center_text_area.x = 10
42-
center_text_area.y = 10 + left_text_area.height + 10
42+
center_text_area.anchor_point = (0.5, 0.5)
43+
center_text_area.anchored_position = (display.width // 2, display.height // 2)
4344
main_group.append(center_text_area)
4445

4546

@@ -55,8 +56,8 @@
5556
scale=1,
5657
)
5758

58-
right_text_area.x = 10
59-
right_text_area.y = center_text_area.y + center_text_area.height + 10
59+
right_text_area.anchor_point = (1.0, 1.0)
60+
right_text_area.anchored_position = (display.width, display.height)
6061
main_group.append(right_text_area)
6162

6263
board.DISPLAY.root_group = main_group

0 commit comments

Comments
 (0)