-
Notifications
You must be signed in to change notification settings - Fork 86
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
Add parameter command to Button #508
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #508 +/- ##
==========================================
- Coverage 95.83% 95.71% -0.13%
==========================================
Files 83 84 +1
Lines 11605 11676 +71
==========================================
+ Hits 11122 11176 +54
- Misses 483 500 +17 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks pretty good! It passes the existing testing (and adds some new tests) so we won't break anyone's code. I had a few ideas for making it a bit easier to use and clarify the documentation. Should be a familiar API to people coming across from tkinter which has a similar way of responding to button presses.
I think this could be expanded to hover events too without many changes but no need to do everything in one PR. I think PRs are often better kept focused as it makes them easier to review and judge their impacts.
rename to on_element_event for easy extension to other elements
short is good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK! Looks good to me.
Should I promote this to hover method? Or promote it to other elements?
Use Cases:
(1)hello_button = UIButton((350, 280), 'Hello', command=lambda _: print("hello"))
(2)command_dict = {pygame_gui.UI_BUTTON_START_PRESS:lambda _: print("START_PRESS"),
pygame_gui.UI_BUTTON_PRESSED:lambda _: print("PRESSED"),
pygame_gui.UI_BUTTON_DOUBLE_CLICKED:lambda _: print("DOUBLE_CLICKED")}
command_button = UIButton((350, 280), 'Command', command=command_dict)