Skip to content

TextBox anchor_point/anchored_position Doesn't Work Properly #221

Closed
@shubham0x13

Description

@shubham0x13

I'm having trouble getting TextBox to center text properly. Even though I'm using align=TextBox.ALIGN_CENTER along with anchor_point and anchored_position, the rendered text still appears off-center (shifted to the right).

Here's the code I'm using:

import board
import displayio
import terminalio
from adafruit_display_text.text_box import TextBox
from busio import I2C
import adafruit_displayio_ssd1306

main_group = displayio.Group()

displayio.release_displays()
i2c = I2C(board.GP7, board.GP6)
display_bus = displayio.I2CDisplay(i2c, device_address=0x3C)
display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=64)

center_text = "Hello, World"
center_text_area = TextBox(
    terminalio.FONT,
    display.width,  # Maximum text width
    TextBox.DYNAMIC_HEIGHT,
    align=TextBox.ALIGN_CENTER,
    text=center_text,
    background_color=0x000000,
    color=0xFFFFFF,
    scale=1,
)

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)

display.root_group = main_group

while True:
    pass

And here's the display output:
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions