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

Document using negative indices in OptionButton's set_item_*() methods #104131

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Calinou
Copy link
Member

@Calinou Calinou commented Mar 14, 2025

This also adds a code sample that shuffles items in an OptionButton, which acts as a showcase for demonstrating programmatic usage.

Run 1 Run 2
image image

@Calinou Calinou requested a review from a team as a code owner March 14, 2025 16:58
@Calinou Calinou added enhancement documentation cherrypick:4.4 Considered for cherry-picking into a future 4.4.x release labels Mar 14, 2025
@Calinou Calinou added this to the 4.5 milestone Mar 14, 2025
This also adds a code sample that shuffles items in an OptionButton,
which acts as a showcase for demonstrating programmatic usage.
@Calinou Calinou force-pushed the doc-optionbutton-set-negative-id branch from e492fa2 to e01432e Compare March 14, 2025 17:00
Copy link
Contributor

@Mickeon Mickeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a fan of the new example. It's very, very... specific and assumes a lot from the user.

The negative indices mention is a good thing. Although, as annoying as it would be, this information technically belongs to each individual method's description.

[b]Note:[/b] The ID values used for items are limited to 32 bits, not full 64 bits of [int]. This has a range of [code]-2^32[/code] to [code]2^32 - 1[/code], i.e. [code]-2147483648[/code] to [code]2147483647[/code].
[b]Note:[/b] The [member Button.text] and [member Button.icon] properties are set automatically based on the selected item. They shouldn't be changed manually.
[b]Example:[/b] Shuffle all existing items in an OptionButton by programmatically getting the items, clearing the list and re-adding the items in a different order:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[b]Example:[/b] Shuffle all existing items in an OptionButton by programmatically getting the items, clearing the list and re-adding the items in a different order:
[b]Example:[/b] Shuffle all items in an [OptionButton] by fetching the items, clearing the list, and re-adding the items in a different order:

@@ -6,8 +6,47 @@
<description>
[OptionButton] is a type of button that brings up a dropdown with selectable items when pressed. The item selected becomes the "current" item and is displayed as the button text.
See also [BaseButton] which contains common properties and methods associated with this node.
Like [PopupMenu], all [code]set_item_*[/code] methods allow negative item indices, i.e. [code]-1[/code] to access the last item, [code]-2[/code] to select the second-to-last item, and so on.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Like [PopupMenu], all [code]set_item_*[/code] methods allow negative item indices, i.e. [code]-1[/code] to access the last item, [code]-2[/code] to select the second-to-last item, and so on.
Like [PopupMenu], all [code]set_item_*[/code] methods allow negative item indices. This means an index of [code]-1[/code] can be used to access the last item, [code]-2[/code] to access the second-to-last item, and so on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherrypick:4.4 Considered for cherry-picking into a future 4.4.x release documentation enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants