OptionButton
Dropdown selection with separate row indices, IDs and item data.
OptionButton displays the selected item’s label. Add rows through AddItem/AddIconItem; the first available item is selected automatically without ItemSelected. AddSeparator creates a separator row and also increases ItemCount. Defaults are FitToLongestItem = true, AllowReselect = false and Selected = -1 before selection exists.
Do not confuse indices and IDs. Select, Selected and ItemSelected arguments use zero-based row indices, counting separators. GetSelectedId returns the assigned ID; GetItemIndex(id) finds its index or -1. Assign unique IDs yourself: automatic IDs come from creation-time indices and are not persistent keys when rebuilding lists. Metadata can hold application values independently of labels.
Select(index) does not emit ItemSelected, even with AllowReselect = true. To load a saved setting, call Select(GetItemIndex(savedId)) after checking the lookup result, then explicitly apply it to your model. Select(-1) clears selection and label; GetSelectedId returns -1 and GetSelectedMetadata returns Nil. Use nonnegative indices for other operations.
SetItemDisabled blocks user selection rather than programmatic Select: code can select a disabled row or separator. Check IsItemDisabled/IsItemSeparator before selecting in code. GetSelectableItem(false/true) finds the first/last available index rather than ID; returns -1 when none exists.
Explicitly restore selection after structural changes. Current RemoveItem does not decrement the saved index when removing an earlier row and can leave it out of bounds. The first SetItemCount after adding rows in code can also reset the index to -1 while a row remains checked. Save a stable ID before mutation, find it again afterward and call Select, or choose an available fallback. Do not read selected metadata/ID through a stale index.
ItemSelected reports the menu-selected index; ItemFocused reports a highlighted row rather than confirmation. AllowReselect permits repeat notification when selecting the same menu item again. FitToLongestItem accounts for all labels/icons and popup width; its cache refresh is deferred. false follows current button content and can change button width on selection.
GetPopup returns an internal PopupMenu owned by the button. Do not free or reparent it. Use OptionButton methods to edit rows: direct PopupMenu mutation can bypass label, selection and cache updates. SearchBarEnabled enables a search field; SearchBarMinItemCount sets a threshold counting nonseparator rows; fuzzy settings control matching with misses. These configure the menu rather than changing IDs or metadata.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
OptionButtonConstructor
public OptionButton();Creates an empty selector: Selected = -1, FitToLongestItem = true, AllowReselect = false, ToggleMode = true, ActionMode = Press. PopupMenu is created as a hidden internal child.
Properties8
AllowReselectProperty
public bool AllowReselect { get; set; }Allows repeated ItemSelected for the same menu row, default false. Does not make Select emit the signal.
FitToLongestItemProperty
public bool FitToLongestItem { get; set; }Closed-button size accounts for all items and popup width, default true. Cache updates are deferred; false follows current label/icon and can change width on selection.
ItemCountProperty
public int ItemCount { get; set; }Count of all rows including separators. Setter creates empty rows or truncates the tail; count must be nonnegative. First change after runtime additions can reset current index: explicitly Select afterward.
SearchBarEnabledProperty
public bool SearchBarEnabled { get; set; }Enables popup search field, default false. Visibility also depends on SearchBarMinItemCount; does not select items or change IDs.
SearchBarFuzzySearchEnabledProperty
public bool SearchBarFuzzySearchEnabled { get; set; }Matching with permitted misses, default true. Does not itself enable the search field; allowed misses are configured separately.
SearchBarFuzzySearchMaxMissesProperty
public int SearchBarFuzzySearchMaxMisses { get; set; }Nonnegative maximum fuzzy-search misses, default 2. Not the visible result count.
SearchBarMinItemCountProperty
public int SearchBarMinItemCount { get; set; }Nonnegative search visibility threshold counting nonseparator rows, default 0. Applies when SearchBarEnabled is on.
SelectedProperty
public int Selected { get; set; }Current row index, -1 for no selection. Setter/Select do not emit ItemSelected and can select disabled/separator rows. Explicitly restore selection by stable ID after structural changes.
Methods44
AddIconItemvoid
public void AddIconItem(Texture2D texture, string label, int id = -1);Adds an item with shared Texture2D, label and ID. Automatic ID depends on creation-time index; first available row is selected without a signal.
| Name | Type | Default |
|---|---|---|
texture | Texture2D | — |
label | string | — |
id | int | -1 |
textureAdds an item with shared Texture2D, label and ID. Automatic ID depends on creation-time index; first available row is selected without a signal.
labelAdds an item with shared Texture2D, label and ID. Automatic ID depends on creation-time index; first available row is selected without a signal.
idItem ID. On addition -1 uses creation-time index; for lookup supply a saved unique ID.
AddItemvoid
public void AddItem(string label, int id = -1);Adds a labeled item with an ID. id = -1 uses creation-time index. The first available item is selected without ItemSelected; index and ID need not match.
| Name | Type | Default |
|---|---|---|
label | string | — |
id | int | -1 |
labelAdds a labeled item with an ID. id = -1 uses creation-time index. The first available item is selected without ItemSelected; index and ID need not match.
idItem ID. On addition -1 uses creation-time index; for lookup supply a saved unique ID.
AddSeparatorvoid
public void AddSeparator(string text = "");Adds a separator row with optional text. Increases ItemCount and affects following row indices; not an ordinary selectable item.
| Name | Type | Default |
|---|---|---|
text | string | "" |
textAdds a separator row with optional text. Increases ItemCount and affects following row indices; not an ordinary selectable item.
Clearvoid
public void Clear();Removes all rows, clears label/icon and sets Selected = -1. Does not emit ItemSelected.
GetAllowReselectbool
public bool GetAllowReselect();Allows repeated ItemSelected for the same menu row, default false. Does not make Select emit the signal.
booltrue when menu reselection can repeat ItemSelected.
GetItemAutoTranslateModeEntity.AutoTranslateModeEnum
public Entity.AutoTranslateModeEnum GetItemAutoTranslateMode(int idx);Item-label translation mode: Inherit, Always or Disabled. Setting the selected row refreshes its display. Does not translate IDs/metadata.
| Name | Type | Default |
|---|---|---|
idx | int | — |
idxZero-based row index rather than ID; Select accepts -1 to clear. Use an existing nonnegative index for other mutations.
Entity.AutoTranslateModeEnumStored item Entity.AutoTranslateModeEnum.
GetItemCountint
public int GetItemCount();Count of all rows including separators. Setter creates empty rows or truncates the tail; count must be nonnegative. First change after runtime additions can reset current index: explicitly Select afterward.
intCount of all rows including separators.
GetItemIconTexture2D
public Texture2D GetItemIcon(int idx);Shared row Texture2D, or null; setting the selected row updates the closed-button icon.
| Name | Type | Default |
|---|---|---|
idx | int | — |
idxZero-based row index rather than ID; Select accepts -1 to clear. Use an existing nonnegative index for other mutations.
Texture2DShared row Texture2D, or null.
GetItemIdint
public int GetItemId(int idx);Returns assigned row ID. idx = -1 returns -1 for no selection rather than the last row ID.
| Name | Type | Default |
|---|---|---|
idx | int | — |
idxZero-based row index rather than ID; Select accepts -1 to clear. Use an existing nonnegative index for other mutations.
intAssigned ID rather than row index.
GetItemIndexint
public int GetItemIndex(int id);Finds the first row with the ID; returns index or -1. IDs are not enforced unique, so assign unique application keys yourself.
| Name | Type | Default |
|---|---|---|
id | int | — |
idItem ID. On addition -1 uses creation-time index; for lookup supply a saved unique ID.
intFirst matching ID’s index, or -1.
GetItemMetadataVariant
public Variant GetItemMetadata(int idx);Application Variant data independent of label and ID. Mutable resources/containers can remain shared.
| Name | Type | Default |
|---|---|---|
idx | int | — |
idxZero-based row index rather than ID; Select accepts -1 to clear. Use an existing nonnegative index for other mutations.
VariantRow application Variant.
GetItemTextstring
public string GetItemText(int idx);Source row label; setting the selected row updates the closed button. Item translation mode controls translation.
| Name | Type | Default |
|---|---|---|
idx | int | — |
idxZero-based row index rather than ID; Select accepts -1 to clear. Use an existing nonnegative index for other mutations.
stringSource row label.
GetItemTooltipstring
public string GetItemTooltip(int idx);Row tooltip in the popup. Not the selected-button label or selection data.
| Name | Type | Default |
|---|---|---|
idx | int | — |
idxZero-based row index rather than ID; Select accepts -1 to clear. Use an existing nonnegative index for other mutations.
stringStored row tooltip text.
GetPopupPopupMenu
public PopupMenu GetPopup();Returns shared internal PopupMenu. Do not free/reparent it. Edit rows through OptionButton methods to keep label, selection and cache consistent.
PopupMenuShared internal PopupMenu owned by the button.
GetSearchBarFuzzySearchMaxMissesint
public int GetSearchBarFuzzySearchMaxMisses();Nonnegative maximum fuzzy-search misses, default 2. Not the visible result count.
intStored SearchBarFuzzySearchMaxMisses setting.
GetSearchBarMinItemCountint
public int GetSearchBarMinItemCount();Nonnegative search visibility threshold counting nonseparator rows, default 0. Applies when SearchBarEnabled is on.
intStored SearchBarMinItemCount setting.
GetSelectableItemint
public int GetSelectableItem(bool fromLast = false);Finds first/last index excluding disabled/separator rows. Returns -1 if none exists. Does not select the row or return its ID.
| Name | Type | Default |
|---|---|---|
fromLast | bool | false |
fromLastfalse for first available index, true for last.
intFirst/last available index, or -1.
GetSelectedint
public int GetSelected();Current row index, -1 for no selection. Setter/Select do not emit ItemSelected and can select disabled/separator rows. Explicitly restore selection by stable ID after structural changes.
intCurrent index or -1; can be stale after removing an earlier row.
GetSelectedIdint
public int GetSelectedId();Returns current row ID, or -1 for no selection. Restore a valid index after removing an earlier row; do not use stale Selected.
intAssigned selected-row ID, or -1 for no selection.
GetSelectedMetadataVariant
public Variant GetSelectedMetadata();Returns current row data, or Variant Nil with no selection. Explicitly restore selection first if list mutation may have left Selected stale.
VariantSelected-row Variant, or Nil for no selection.
HasSelectableItemsbool
public bool HasSelectableItems();Whether at least one row is neither disabled nor separator. Does not validate current Selected.
booltrue when at least one enabled nonseparator item exists.
IsFitToLongestItembool
public bool IsFitToLongestItem();Closed-button size accounts for all items and popup width, default true. Cache updates are deferred; false follows current label/icon and can change width on selection.
booltrue when minimum size accounts for all items/popup.
IsItemDisabledbool
public bool IsItemDisabled(int idx);Disables user selection of a row. Does not clear existing selection or block programmatic Select of that index.
| Name | Type | Default |
|---|---|---|
idx | int | — |
idxZero-based row index rather than ID; Select accepts -1 to clear. Use an existing nonnegative index for other mutations.
booltrue when the row is disabled for user selection.
IsItemSeparatorbool
public bool IsItemSeparator(int idx);Tests whether a row is a separator. Separators count toward ItemCount/indices but are skipped by GetSelectableItem.
| Name | Type | Default |
|---|---|---|
idx | int | — |
idxZero-based row index rather than ID; Select accepts -1 to clear. Use an existing nonnegative index for other mutations.
booltrue for a separator row.
IsSearchBarEnabledbool
public bool IsSearchBarEnabled();Enables popup search field, default false. Visibility also depends on SearchBarMinItemCount; does not select items or change IDs.
boolStored SearchBarEnabled setting.
IsSearchBarFuzzySearchEnabledbool
public bool IsSearchBarFuzzySearchEnabled();Matching with permitted misses, default true. Does not itself enable the search field; allowed misses are configured separately.
boolStored SearchBarFuzzySearchEnabled setting.
RemoveItemvoid
public void RemoveItem(int idx);Removes a row by index. Removing the selected row clears selection. Current removal before the selected row does not decrement stored index; save its ID first and restore Select(GetItemIndex(id)) after checking the result.
| Name | Type | Default |
|---|---|---|
idx | int | — |
idxZero-based row index rather than ID; Select accepts -1 to clear. Use an existing nonnegative index for other mutations.
Selectvoid
public void Select(int idx);Selects an existing row index without ItemSelected; -1 clears selection. Do not pass an ID. Does not exclude disabled/separator rows or automatically update application state.
| Name | Type | Default |
|---|---|---|
idx | int | — |
idxZero-based row index rather than ID; Select accepts -1 to clear. Use an existing nonnegative index for other mutations.
SetAllowReselectvoid
public void SetAllowReselect(bool allow);Allows repeated ItemSelected for the same menu row, default false. Does not make Select emit the signal.
| Name | Type | Default |
|---|---|---|
allow | bool | — |
allowAllows repeated ItemSelected for the same menu row, default false. Does not make Select emit the signal.
SetDisableShortcutsvoid
public void SetDisableShortcuts(bool disabled);Disables local list/base-button shortcut handling. Does not change application InputMap or disable ordinary Select/list methods.
| Name | Type | Default |
|---|---|---|
disabled | bool | — |
disabledDisables local list/base-button shortcut handling. Does not change application InputMap or disable ordinary Select/list methods.
SetFitToLongestItemvoid
public void SetFitToLongestItem(bool fit);Closed-button size accounts for all items and popup width, default true. Cache updates are deferred; false follows current label/icon and can change width on selection.
| Name | Type | Default |
|---|---|---|
fit | bool | — |
fitClosed-button size accounts for all items and popup width, default true. Cache updates are deferred; false follows current label/icon and can change width on selection.
SetItemAutoTranslateModevoid
public void SetItemAutoTranslateMode(int idx, Entity.AutoTranslateModeEnum mode);Item-label translation mode: Inherit, Always or Disabled. Setting the selected row refreshes its display. Does not translate IDs/metadata.
| Name | Type | Default |
|---|---|---|
idx | int | — |
mode | Entity.AutoTranslateModeEnum | — |
idxZero-based row index rather than ID; Select accepts -1 to clear. Use an existing nonnegative index for other mutations.
modeItem-label translation mode: Inherit, Always or Disabled. Setting the selected row refreshes its display. Does not translate IDs/metadata.
SetItemCountvoid
public void SetItemCount(int count);Count of all rows including separators. Setter creates empty rows or truncates the tail; count must be nonnegative. First change after runtime additions can reset current index: explicitly Select afterward.
| Name | Type | Default |
|---|---|---|
count | int | — |
countCount of all rows including separators. Setter creates empty rows or truncates the tail; count must be nonnegative. First change after runtime additions can reset current index: explicitly Select afterward.
SetItemDisabledvoid
public void SetItemDisabled(int idx, bool disabled);Disables user selection of a row. Does not clear existing selection or block programmatic Select of that index.
| Name | Type | Default |
|---|---|---|
idx | int | — |
disabled | bool | — |
idxZero-based row index rather than ID; Select accepts -1 to clear. Use an existing nonnegative index for other mutations.
disabledDisables user selection of a row. Does not clear existing selection or block programmatic Select of that index.
SetItemIconvoid
public void SetItemIcon(int idx, Texture2D texture);Shared row Texture2D, or null; setting the selected row updates the closed-button icon.
| Name | Type | Default |
|---|---|---|
idx | int | — |
texture | Texture2D | — |
idxZero-based row index rather than ID; Select accepts -1 to clear. Use an existing nonnegative index for other mutations.
textureShared row Texture2D, or null; setting the selected row updates the closed-button icon.
SetItemIdvoid
public void SetItemId(int idx, int id);Sets an existing row ID without changing index. Uniqueness is not enforced; avoid duplicate IDs.
| Name | Type | Default |
|---|---|---|
idx | int | — |
id | int | — |
idxZero-based row index rather than ID; Select accepts -1 to clear. Use an existing nonnegative index for other mutations.
idItem ID. On addition -1 uses creation-time index; for lookup supply a saved unique ID.
SetItemMetadatavoid
public void SetItemMetadata(int idx, Variant metadata);Application Variant data independent of label and ID. Mutable resources/containers can remain shared.
| Name | Type | Default |
|---|---|---|
idx | int | — |
metadata | Variant | — |
idxZero-based row index rather than ID; Select accepts -1 to clear. Use an existing nonnegative index for other mutations.
metadataApplication Variant data independent of label and ID. Mutable resources/containers can remain shared.
SetItemTextvoid
public void SetItemText(int idx, string text);Source row label; setting the selected row updates the closed button. Item translation mode controls translation.
| Name | Type | Default |
|---|---|---|
idx | int | — |
text | string | — |
idxZero-based row index rather than ID; Select accepts -1 to clear. Use an existing nonnegative index for other mutations.
textSource row label; setting the selected row updates the closed button. Item translation mode controls translation.
SetItemTooltipvoid
public void SetItemTooltip(int idx, string tooltip);Row tooltip in the popup. Not the selected-button label or selection data.
| Name | Type | Default |
|---|---|---|
idx | int | — |
tooltip | string | — |
idxZero-based row index rather than ID; Select accepts -1 to clear. Use an existing nonnegative index for other mutations.
tooltipRow tooltip in the popup. Not the selected-button label or selection data.
SetSearchBarEnabledvoid
public void SetSearchBarEnabled(bool enabled);Enables popup search field, default false. Visibility also depends on SearchBarMinItemCount; does not select items or change IDs.
| Name | Type | Default |
|---|---|---|
enabled | bool | — |
enabledEnables popup search field, default false. Visibility also depends on SearchBarMinItemCount; does not select items or change IDs.
SetSearchBarFuzzySearchEnabledvoid
public void SetSearchBarFuzzySearchEnabled(bool enabled);Matching with permitted misses, default true. Does not itself enable the search field; allowed misses are configured separately.
| Name | Type | Default |
|---|---|---|
enabled | bool | — |
enabledMatching with permitted misses, default true. Does not itself enable the search field; allowed misses are configured separately.
SetSearchBarFuzzySearchMaxMissesvoid
public void SetSearchBarFuzzySearchMaxMisses(int maxMisses);Nonnegative maximum fuzzy-search misses, default 2. Not the visible result count.
| Name | Type | Default |
|---|---|---|
maxMisses | int | — |
maxMissesNonnegative maximum fuzzy-search misses, default 2. Not the visible result count.
SetSearchBarMinItemCountvoid
public void SetSearchBarMinItemCount(int count);Nonnegative search visibility threshold counting nonseparator rows, default 0. Applies when SearchBarEnabled is on.
| Name | Type | Default |
|---|---|---|
count | int | — |
countNonnegative search visibility threshold counting nonseparator rows, default 0. Applies when SearchBarEnabled is on.
ShowPopupvoid
public void ShowPopup();Opens the list when a Viewport exists. Neither Select nor item confirmation. Direct calls bypass Press’s Disabled check; call for an active in-tree button.
Signals and events2
ItemFocusedEvent
public event OptionButton.ItemFocusedEventHandler ItemFocused;Highlighted row index, long in C#. Not confirmation and need not equal Selected.
| Name | Type | Default |
|---|---|---|
index | long | — |
indexZero-based row index, long in the C# signal, not ID.
ItemSelectedEvent
public event OptionButton.ItemSelectedEventHandler ItemSelected;Menu-selected row index, long in C#. Not an ID. Select and automatic selection during addition do not emit it; AllowReselect controls same-row reselection.
| Name | Type | Default |
|---|---|---|
index | long | — |
indexZero-based row index, long in the C# signal, not ID.
Theme properties
These are Theme resource keys, not C# properties. Use the matching Control GetTheme…() and AddTheme…Override() methods for each value type.
| Key and type | Description |
|---|---|
arrow_marginint | The horizontal space between the arrow icon and the right edge of the button. Default:4 |
modulate_arrowint | If different than 0 |
arrowTexture2D | The arrow icon to be drawn on the right end of the button. |