adafruit / circuitpython

CircuitPython - a Python implementation for teaching coding with microcontrollers
https://circuitpython.org
Other
4k stars 1.18k forks source link

displayio Label text Y position ignored after first refresh #8637

Closed bradanlane closed 6 months ago

bradanlane commented 9 months ago

CircuitPython version

CircuitPython 8.2.8 running on Solderparty RP2040 Stamp

Code/REPL

displayio.release_displays()
spi = busio.SPI(SCK_PIN, MOSI_PIN)
display_bus = displayio.FourWire(spi, command=DC_PIN, chip_select=CS_PIN, reset=RESET_PIN, baudrate=1000000)
time.sleep(1)
display = adafruit_ssd1608.SSD1608(display_bus, width=200, height=200, busy_pin=BUSY_PIN)

display_group = displayio.Group()
background_bitmap = displayio.Bitmap(INK_WIDTH, INK_HEIGHT, 1)
palette = displayio.Palette(1)
palette[0] = INK_WHITE

group_tile = displayio.TileGrid(background_bitmap, pixel_shader=palette)
display_group.append(group_tile)
display.root_group = display_group

display.show(display_group)
display.refresh()
time.sleep(display.time_to_refresh + 0.1)

display_group.append(displayio.Group(scale=4, x=70, y=100))
text_area = label.Label(terminalio.FONT, text="LED", color=INK_BLACK)

text_area.x = 70
text_area.y = 100
text_area.scale = 4
display_group[1].y=100
display_group[1] = text_area

# without these two lines, the "LED" text will appear at the top of the display rather than at y=100
display.show(None)
display.show(display_group)

display.refresh()

Behavior

With the code, the display refreshes and then the text “LED” renders meant the middle of the SSD1608 200x200 ePaper display.

without the extra display.show(None) and display.show(display_group) the text displays at the top of the screen near the middle. It is as if the y value is ignored.

Description

I see this issue has been closed. I am testing an SSD1608 and see that the text_area.y is ignored. i.e. on first refresh the test is in the correct location. On the subsequent refresh the x position is correct the y position it at the top of the display.

The workaround is to use the same trick suggested by @anecdata in #

Additional information

No response

tannewt commented 6 months ago

This works on 8.2.8 and 00824ad12229af15541d1431cf31f216e8e3587d on a MagTag. It may have been a library bug. I'm using display text 3.0.6.

Full test code:

import displayio
import board
import terminalio
import time

from adafruit_display_text import label

display = board.DISPLAY

INK_WIDTH = display.width
INK_HEIGHT = display.height

INK_WHITE = 0xffffff
INK_BLACK = 0x000000

display_group = displayio.Group()
background_bitmap = displayio.Bitmap(INK_WIDTH, INK_HEIGHT, 1)
palette = displayio.Palette(1)
palette[0] = INK_WHITE

group_tile = displayio.TileGrid(background_bitmap, pixel_shader=palette)
display_group.append(group_tile)
display.root_group = display_group

time.sleep(display.time_to_refresh + 0.1)
display.refresh()

display_group.append(displayio.Group(scale=4, x=70, y=100))
text_area = label.Label(terminalio.FONT, text="LED", color=INK_BLACK)

text_area.x = 70
text_area.y = 100
text_area.scale = 4
display_group[1].y=100
display_group[1] = text_area

# without these two lines, the "LED" text will appear at the top of the display rather than at y=100
time.sleep(display.time_to_refresh + 0.1)
display.refresh()