Description
The Button class is extending group:
Inside of Button.__init__()
we are calling up to Group.__init__()
with default params:
But we are also creating another new group and storing it at self.group
:
Which we later append the body, outline, and text label to:
If I am understanding correctly then the button instance that we are extending is never being used after being instantiated. Instead everything gets put into the self.group
instance.
In user code the result of this is when we want to use a Button we have to create it and then specifically access the group
property on it when we add it to the screen:
button = Button( ... )
# Add button to the display context
splash.append(button.group)
Adding to the confusion Button itself is also a Group so this code does not throw any errors:
button = Button( ... )
splash.append(button)
But won't result in the button being added to the screen.
I think we can get rid of one of the two Group instances. I think it would make sense to keep the instance that Button is extending and use that one, getting rid of self.group
. This would make Button behave more like the adafruit_display_text.Label
in that the object resulting from __init__()
is ready to be added to the screen, or other Groups, directly. i.e.
text_area = label.Label(terminalio.FONT, text="Hello")
board.DISPLAY.show(text_area)
The adafruit_display_shapes
objects, and adafruit_progressbar.ProgressBar
are a few other examples that work this way.