You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I observed a strange behavior when using the .hidden flag of the displayio.Group where the group is actually visible, even when group.hidden is set to True.
If the group.hidden is set to True before content is appended into it, the .hidden flag is ignored.
The group.hidden flag's proper behavior can only be recovered if it set to False and then back to True again.
Here's the example code to replicate the issue. This was tested on the PyPortal.
CircuitPython version info: Adafruit CircuitPython 6.1.0 on 2021-01-21; Adafruit PyPortal with samd51j20
# Demo of strange group behavior group.hidden is set True before content is appended#importtimeimportboardimportdisplayio# start display for example with PyPortaldisplay=board.DISPLAYbitmap=displayio.Bitmap(50,50, 2)
palette=displayio.Palette(2)
palette[0] =0xAA0000tilegrid=displayio.TileGrid(bitmap, pixel_shader=palette)
group=displayio.Group(x=(320-bitmap.width)//2, y=(240-bitmap.height)//2, max_size=1)
group.hidden=True##### If this statement is included before the tilegrid is appended##### onto the group, the group is incorrectly visible until##### the `group.hidden` is set False and then back to True########## If this line is commented out, it works as expected.print("1 group.hidden: {}".format(group.hidden))
group.append(tilegrid)
print("2 group.hidden: {}".format(group.hidden))
group.hidden=Trueprint("3 group.hidden: {}".format(group.hidden))
display.show(group)
display.refresh()
print("Red square should be hidden.") # Red square is visible with current codetime.sleep(5)
group.hidden=Trueprint("Set /`group.hidden = True/` again. Red square should be hidden.")
print("4 group.hidden: {}".format(group.hidden))
time.sleep(5) # Red square is visible with current codegroup.hidden=Falseprint("Set /`group.hidden = False/`, Red square should be visible.")
print("5 group.hidden: {}".format(group.hidden))
time.sleep(5)
group.hidden=Trueprint("Set /`group.hidden = True/` another time. Red square should be hidden.")
print("6 group.hidden: {}".format(group.hidden))
time.sleep(5)
group.hidden=Falseprint("Set /`group.hidden = False/`, Red square should be visible.")
print("7 group.hidden: {}".format(group.hidden))
whileTrue:
pass
The text was updated successfully, but these errors were encountered:
The root cause of this is related to the use of two separate properties to control hidden behaviour of Group and TileGrid.
The Group contains two properties that help hide graphical content:
hidden
hidden_by_parent
I'm not clear on the logic behind hidden_by_parent so I'm interested to better understand the importance of that.
Here is cause of the issue. Whenever content is appended (and maybe inserted) into a Group, the hidden property is not transferred into the content as hidden_by_parent. Then, when the display checks which Groups refresh regions should be rendered, these artificially "non-hidden" appended display elements get displayed.
Digging a bit deeper, I see that the Group "get_refresh_areas" function doesn't check the hidden property before deciding what areas should be displayed. In contrast, the TileGrid "refresh" and "get_refresh_areas" code does check whether they are hidden.
I see two possible solutions:
Simple - Whenever inserting or appending content into a group, set the content's hidden_by_parent property to match the Parent's group->hidden status. Note: Will need to iterate down any content.
Complex - Get rid of this hidden_by_parent attribute. Instead, in Group's get_refresh_areas and refresh, if a hidden Group is encountered, don't refresh any of this Group's content. Benefit: This would allow different "depths" of hidden-ness, that is Children could retain their hidden properties even if the Parent's hidden properties changes.
I think the simple route is your only route. The complex route risks not actually updating a portion of the screen because dirty areas only come from TileGrids IIRC. TileGrids need to know when they are hidden so they can provide the area where they were rendered last (but not where they are now.) hidden_by_parent is separate from hidden because the public hidden attribute is for the TileGrid only.
I observed a strange behavior when using the
.hidden
flag of thedisplayio.Group
where the group is actually visible, even whengroup.hidden
is set toTrue
.If the
group.hidden
is set toTrue
before content is appended into it, the.hidden
flag is ignored.The
group.hidden
flag's proper behavior can only be recovered if it set toFalse
and then back toTrue
again.Here's the example code to replicate the issue. This was tested on the PyPortal.
CircuitPython version info:
Adafruit CircuitPython 6.1.0 on 2021-01-21; Adafruit PyPortal with samd51j20
The text was updated successfully, but these errors were encountered: