Skip to content

fix anchored positioning for TextBox #222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions adafruit_display_text/text_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def _reset_text(
# Calculate both "tight" and "loose" bounding box dimensions to match label for
# anchor_position calculations
(
box_x,
box_x, # noqa: F841, var assigned not used
tight_box_y,
x_offset,
tight_y_offset,
Expand All @@ -288,8 +288,6 @@ def _reset_text(
y_offset = loose_y_offset

# Calculate the background size including padding
tight_box_x = box_x
box_x = box_x + self._padding_left + self._padding_right
box_y = box_y + self._padding_top + self._padding_bottom

if self.dynamic_height:
Expand Down Expand Up @@ -343,8 +341,8 @@ def _reset_text(
self._bounding_box = (
self._tilegrid.x + self._padding_left,
self._tilegrid.y + self._padding_top,
tight_box_x,
tight_box_y,
self.width,
self.height,
)

if (
Expand Down
13 changes: 7 additions & 6 deletions examples/display_text_text_box_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from adafruit_display_text.text_box import TextBox

display = board.DISPLAY
main_group = displayio.Group()

left_text = ("Left left left left " * 2).rstrip()
Expand All @@ -21,8 +22,8 @@
scale=1,
)

left_text_area.x = 10
left_text_area.y = 10
left_text_area.anchor_point = (0, 0)
left_text_area.anchored_position = (0, 0)
main_group.append(left_text_area)


Expand All @@ -38,8 +39,8 @@
scale=1,
)

center_text_area.x = 10
center_text_area.y = 10 + left_text_area.height + 10
center_text_area.anchor_point = (0.5, 0.5)
center_text_area.anchored_position = (display.width // 2, display.height // 2)
main_group.append(center_text_area)


Expand All @@ -55,8 +56,8 @@
scale=1,
)

right_text_area.x = 10
right_text_area.y = center_text_area.y + center_text_area.height + 10
right_text_area.anchor_point = (1.0, 1.0)
right_text_area.anchored_position = (display.width, display.height)
main_group.append(right_text_area)

board.DISPLAY.root_group = main_group
Expand Down