Skip to content

Button extends Group and holds a Group #22

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

Closed
FoamyGuy opened this issue Aug 10, 2020 · 1 comment
Closed

Button extends Group and holds a Group #22

FoamyGuy opened this issue Aug 10, 2020 · 1 comment

Comments

@FoamyGuy
Copy link

The Button class is extending group:

class Button(displayio.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:

self.group = displayio.Group()

Which we later append the body, outline, and text label to:

self.group.append(self.body)

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.

@FoamyGuy
Copy link
Author

resolved by #23

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

No branches or pull requests

1 participant