ppizarror / pygame-menu

A menu for pygame. Simple, and easy to use
https://pygame-menu.readthedocs.io/
Other
544 stars 141 forks source link

compute _selection_box_width of dropselect automatically to fit items. #387

Closed larryw3i closed 2 years ago

larryw3i commented 2 years ago

Can the width of dropselect's options be set to auto? #386 It works for me now.

larryw3i commented 2 years ago

Looking forward to the new release.

ppizarror commented 2 years ago

Hi. All tests have failed :(. I think this solution requires another re-thinking. Maybe, an additional option like update_with_auto_by_items must be added.

larryw3i commented 2 years ago

_selection_box_width has indeed been changed -->
https://github.com/ppizarror/pygame-menu/blob/master/test/test_widget_dropselect.py#L35#L40
Because its default value is 0, I think it's reasonable.
https://github.com/ppizarror/pygame-menu/runs/5217122378?check_suite_focus=true#step:5:711
😂

larryw3i commented 2 years ago

Shall I update the test file?

larryw3i commented 2 years ago

I think I have used custom function to solve this problem, thank you very much, pygame_ menu is powerful, I will close issue and pull request.

    def update_selection_box_width(self):
        for ds in [
            self.subject_dropselect,
            self.subject_game_dropselect,
            self.difficulty_dropselect]:
            ds._selection_box_width = max(
                [b.get_width() for b in ds._option_buttons]
            ) + ds._selection_box_inflate[0]
            ds._make_selection_drop()
            ds.render()
ppizarror commented 2 years ago

Great. Thanks for your intention to fix this issue. If you have any feature suggestion or want to contribute with a new widget it would be fantastic. Greetings!