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

Cannot sort Optionbutton's items by their text and Id alphabetically #39345

Open
MaaaxiKing opened this issue Jun 6, 2020 · 3 comments
Open

Comments

@MaaaxiKing
Copy link

Godot version:

3.2.1.stable

OS/device including version:

Windows 10 Home 1909

Issue description:

I wanted to sort items of a OptionButton by their text but $OptionButton.items.sort() didn't do anything as far as I could find out. They are also not sorted by their Id.

Steps to reproduce:
Create a scene with root node OptionButton. Add Items to it and put some text in each in an alphabetically unsorted order. Attach a script to it. In _ready():
type items.sort()
Start the scene.
OptionButton items sort bug.zip

Minimal reproduction project:

@MaaaxiKing MaaaxiKing changed the title Cannot sort Optionbutton's items be their text alphabetically Cannot sort Optionbutton's items by their text and Id alphabetically Jun 6, 2020
@KoBeWi
Copy link
Member

KoBeWi commented Jun 6, 2020

Might be related to #38511
items aren't probably intended to be modified manually.

@dominiks
Copy link
Contributor

dominiks commented Jun 7, 2020

At the moment you have to add the items in the order you want them to be in. So you have to clear and refill the items whenever you want to sort them in a different way.

ItemList has a very similar API to the OptionButton but also a sort_items_by_text() function. I think if ItemList has such a function so should the OptionButton.

Would it make sense to add other functions of the ItemList that are missing on the button? Their backends are probably quite different but from the user perspective the APIs seem very similar but OptionButton is missing quite a bit of functionality that the ItemList has.

@MaaaxiKing
Copy link
Author

I think get_item_icon(), get_item_id(), get_item_index(), get_item_metadata(), get_item_text() should be removed and their should be get_item(). You could get the item by maybe doing get_item(text="this_item_text_is_hello") or get_item(id=1) etc. and on this that you should be able to call icon, id, index, metadata. On .items you should be able to call count, so get_item_count( ) would be unnecessary.

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

4 participants