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

Add parameter command to Button #508

Merged
merged 14 commits into from
Feb 14, 2024

Conversation

LondonClass
Copy link
Contributor

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)

@MyreMylar MyreMylar closed this Feb 12, 2024
@MyreMylar MyreMylar reopened this Feb 12, 2024
Copy link

codecov bot commented Feb 12, 2024

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (f1a433e) 95.83% compared to head (d0b8c98) 95.71%.
Report is 12 commits behind head on main.

Files Patch % Lines
pygame_gui/elements/ui_button.py 94.28% 2 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

Copy link
Owner

@MyreMylar MyreMylar left a 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.

Copy link
Owner

@MyreMylar MyreMylar left a 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.

@MyreMylar MyreMylar merged commit 38291c9 into MyreMylar:main Feb 14, 2024
11 checks passed
@LondonClass LondonClass deleted the button-modification branch February 15, 2024 02:53
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.

2 participants