Skip to content
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

Tilegrid transpose fix #4331

Merged
merged 3 commits into from
Mar 5, 2021
Merged

Conversation

dhalbert
Copy link
Collaborator

@dhalbert dhalbert commented Mar 4, 2021

Fixes #4284.

Setting TileGrid.transpose_xy forces the x,y, height, and width to be recalculated using _update_current_x() and _update_current_y(). Those routines did not handle the case of absolute_transform being NULL, and used NULL as a pointer to a transform, so they got random values.

This fix guards against that. It also makes null_transform, an identity transform defined for use in vectorio, be a global. I used it in the fix.

An alternative fix would be to never use a NULL pointer as absolute_transform, and use &null_transform to signify the identity transform. However, absolute_transform == NULL is overloaded as a signal the object has no parent, and so some other indicator (like a new bool) would have to be added to indicate no parent. I chose not to make that change now.

I tested this with a simple quotes example on a PyPortal Titano. @jposada202020 if you would like to test this in the context of your full program, that would be great. Thanks.

@dhalbert dhalbert requested a review from tannewt March 4, 2021 20:06
@jposada202020
Copy link
Collaborator

Yes, I will try this tonight, Both in the "simple" code example and in the New Veritcal label proposal. Thanks @dhalbert . I will report my tests in here.

@jposada202020
Copy link
Collaborator

This was tested in using the new proposal Vertical Library PR122 adafruit/Adafruit_CircuitPython_Display_Text#122

in
Adafruit CircuitPython 6.1.0 on 2021-01-21; Seeeduino Wio Terminal with samd51p19

Results

image

and in the MAGTAG
Adafruit CircuitPython 6.2.0-beta.3-14-gb1268107a-dirty on 2021-03-04; Adafruit MagTag with ESP32S2

Results

image

Test code

import board
import displayio
from adafruit_bitmap_font import bitmap_font
from adafruit_display_text import vertical_label
from adafruit_display_text import label
import time
import digitalio

display = board.DISPLAY

# wait until we can draw
time.sleep(display.time_to_refresh)

# main group to hold everything
group = displayio.Group()

# white background. Scaled to save RAM
bg_bitmap = displayio.Bitmap(display.width // 8, display.height // 8, 1)
bg_palette = displayio.Palette(1)
bg_palette[0] = 0xFFFFFF
bg_sprite = displayio.TileGrid(bg_bitmap, x=0, y=0, pixel_shader=bg_palette)
bg_group = displayio.Group(scale=8)
bg_group.append(bg_sprite)
group.append(bg_group)


text = "Reporting"
MEDIUM_FONT = bitmap_font.load_font("/fonts/Helvetica-Bold-16.bdf")
BIG_FONT = bitmap_font.load_font("/fonts/LeagueSpartan-Bold-16.bdf")


bitmap = displayio.Bitmap(320, 3, 2)
palette = displayio.Palette(2)
palette[0] = 0x004400
palette[1] = 0x00FFFF
tile_grid = displayio.TileGrid(bitmap, pixel_shader=palette, x=0, y=115)

bitmap2 = displayio.Bitmap(3, 260, 2)
tile_grid2 = displayio.TileGrid(bitmap2, pixel_shader=palette, x=120, y=10)



text_areah = label.Label(
    BIG_FONT,
    text=text,
    color=0xFFFFFF,
    background_color=0x666666,
    x=0,
    y=100,
)

group.append(text_areah)


text_area3 = vertical_label.Label(BIG_FONT,
 text="Pythoñ", 
 color=0x00FF00, 
 background_color=0x990022,  
 background_tight=False, 
 padding_top=5, 
 padding_bottom=0, 
 padding_left=0,
 padding_right=0,
 x=120,
 y=80,
 base_alignment= True,
 scale=1,)
group.append(text_area3)

text_area4 = vertical_label.Label(MEDIUM_FONT,
 text="Circuit", 
 color=0x00FF00, 
 background_color=0x990099,  
 background_tight=False, 
 padding_top=4, 
 padding_bottom=15, 
 padding_left=10,
 padding_right=3,
 base_alignment= True,
 x=100,
 y=80
 ,)
group.append(text_area4)
text_area = vertical_label.Label(MEDIUM_FONT, text="V6.2.0",
 color=0x00FF00, background_color=0x330099, padding_left=0,
  padding_right=0, padding_bottom=0, padding_top=0, anchor_point=(0.0, 0.0),
  anchored_position=(130,120),
  scale=2,)
text_area2 = label.Label(MEDIUM_FONT,
 text=text, color=0xAA5522, 
 background_color=0x22FF44, 
 padding_left=0, 
 padding_right=0, 
 padding_bottom=0, 
 padding_top=0, 
 x=20,
 y=140)

group.append(text_area)
group.append(text_area2)

group.append(tile_grid)
group.append(tile_grid2)

# show the main group and refresh.
display.show(group)
display.refresh()

while True:
  pass

Copy link
Member

@jepler jepler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me, but I didn't test.

@dhalbert dhalbert merged commit c68073e into adafruit:main Mar 5, 2021
@dhalbert dhalbert deleted the tilegrid-transpose-fix branch March 5, 2021 02:53
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR regresses TinyUSB from 52855 to 28029

@tannewt tannewt mentioned this pull request Mar 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using displayio.Tilegrid.transpose_xy will crash the MAGTAG sending it to Safe Mode
4 participants