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

Wordwrap in buttons #488

Closed
neilsimp1 opened this issue Nov 9, 2024 · 8 comments
Closed

Wordwrap in buttons #488

neilsimp1 opened this issue Nov 9, 2024 · 8 comments

Comments

@neilsimp1
Copy link
Contributor

Is your feature request related to a problem? Please describe.
I'm trying to handle cases in my program where the text for a button might be a bit long.
I'm able to button.set_max_width() but this only scales the text in order to make it fit.

Describe the solution you'd like
I'd like to be able to wordwrap=True similar to how a Label works. This would increase the height of the button and allow text to flow onto multiple lines.

Describe alternatives you've considered
Creating a custom widget that combines the functionality of Buttons and Labels.

@neilsimp1
Copy link
Contributor Author

Please se #490 :)

@ppizarror
Copy link
Owner

Great contribution! Please add yourself to docs/_source/contributors.rst. Will look tomorrow and upload to pip.


Pablo

@neilsimp1
Copy link
Contributor Author

Done. Thanks for considering my code :)

@ppizarror
Copy link
Owner

ppizarror commented Dec 21, 2024

Hi. I uploaded v4.5.0 to pip.
image
I changed the architecture of your enhancement a bit. I noticed that most code relied on Label, so I inherited it from Button. Always prefer simpler approaches or detect if there are any refactor patterns in the code. This project has a lot of tests, so we are backed.
Also, I added a test for this feature. Thanks!!

@neilsimp1
Copy link
Contributor Author

Thank you! I was worried about repeating code but wasn't confident enough to do such a large refactor.


Unfortunately, after pulling in the latest copy and trying my project, I run in to my original error (the width of the button is wider than that of the frame surrounding it).

It doesn't seem to be doing the word wrap and I think I see why:
https://github.com/ppizarror/pygame-menu/blob/master/pygame_menu/widgets/widget/label.py#L229C13-L229C22
Here, it's getting the max_container_width by looking at the widget's menu width.

In my case, these buttons are within a VFrame, and I need them to not exceed the width of that.

It's hard to see in my screenshot before so here's a screenshot outlining things. The green is a menu, blue are frames.
image

I've updated my code to call the Button without kwargs, and you can see the relevant code here: https://gitlab.com/neilsimp1/pacab/-/blob/main/src/menus/inventorymenu.py?ref_type=heads#L58

Do you have any suggestion if anything can be done on my end to make this look for the frame width instead of the menu width?
Or, does anything need to change in _get_max_container_width() to make it aware of Frames?

@ppizarror
Copy link
Owner

ppizarror commented Dec 23, 2024

As Button passes down all *args and *kwargs to callback I dediced to remove accepting kwargs. ButtonManager processes all arguments and helps to pass them down to the widget.

Also, I fixed the Frame awareness while computing container width. See 96f8a7a. Let me know if that works, so I upload new v4.5.1 to pip.

@ppizarror ppizarror reopened this Dec 23, 2024
@neilsimp1
Copy link
Contributor Author

Brilliant! I updated my local cache of label.py with your fix, and it works now with no other changes.

Thank you!

@ppizarror
Copy link
Owner

Uploaded new v4.5.1 to pip. Please update as this has some interesting features, thanks!.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants