OptionButton

package
v0.0.0-...-fa94a0d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 18, 2025 License: MIT Imports: 30 Imported by: 0

Documentation

Overview

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.

Note: The IDs used for items are limited to signed 32-bit integers, not the full 64 bits of int. These have a range of -2^31 to 2^31 - 1, that is, -2147483648 to 2147483647.

Note: The Button.Text and Button.Icon properties are set automatically based on the selected item. They shouldn't be changed manually.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Advanced

type Advanced = class

Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.

type Any

type Any interface {
	gd.IsClass
	AsOptionButton() Instance
}

type Expanded

type Expanded = MoreArgs

type Extension

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension

func (*Extension[T]) AsBaseButton

func (self *Extension[T]) AsBaseButton() BaseButton.Instance

func (*Extension[T]) AsButton

func (self *Extension[T]) AsButton() Button.Instance

func (*Extension[T]) AsCanvasItem

func (self *Extension[T]) AsCanvasItem() CanvasItem.Instance

func (*Extension[T]) AsControl

func (self *Extension[T]) AsControl() Control.Instance

func (*Extension[T]) AsNode

func (self *Extension[T]) AsNode() Node.Instance

func (*Extension[T]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

func (*Extension[T]) AsOptionButton

func (self *Extension[T]) AsOptionButton() Instance

type ID

type ID Object.ID

ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

type Instance

type Instance [1]gdclass.OptionButton

Instance of the class with convieniently typed arguments and results.

var Nil Instance

Nil is a nil/null instance of the class. Equivalent to the zero value.

func New

func New() Instance

func (Instance) AddIconItem

func (self Instance) AddIconItem(texture Texture2D.Instance, label string)

Adds an item, with a 'texture' icon, text 'label' and (optionally) 'id'. If no 'id' is passed, the item index will be used as the item's ID. New items are appended at the end.

Note: The item will be selected if there are no other items.

func (Instance) AddItem

func (self Instance) AddItem(label string)

Adds an item, with text 'label' and (optionally) 'id'. If no 'id' is passed, the item index will be used as the item's ID. New items are appended at the end.

Note: The item will be selected if there are no other items.

func (Instance) AddSeparator

func (self Instance) AddSeparator()

Adds a separator to the list of items. Separators help to group items, and can optionally be given a 'text' header. A separator also gets an index assigned, and is appended at the end of the item list.

func (Instance) AllowReselect

func (self Instance) AllowReselect() bool

func (Instance) AsBaseButton

func (self Instance) AsBaseButton() BaseButton.Instance

func (Instance) AsButton

func (self Instance) AsButton() Button.Instance

func (Instance) AsCanvasItem

func (self Instance) AsCanvasItem() CanvasItem.Instance

func (Instance) AsControl

func (self Instance) AsControl() Control.Instance

func (Instance) AsNode

func (self Instance) AsNode() Node.Instance

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) AsOptionButton

func (self Instance) AsOptionButton() Instance

func (Instance) Clear

func (self Instance) Clear()

Clears all the items in the OptionButton.

func (Instance) FitToLongestItem

func (self Instance) FitToLongestItem() bool

func (Instance) GetItemAutoTranslateMode

func (self Instance) GetItemAutoTranslateMode(idx int) Node.AutoTranslateMode

Returns the auto translate mode of the item at index 'idx'.

func (Instance) GetItemIcon

func (self Instance) GetItemIcon(idx int) Texture2D.Instance

Returns the icon of the item at index 'idx'.

func (Instance) GetItemId

func (self Instance) GetItemId(idx int) int

Returns the ID of the item at index 'idx'.

func (Instance) GetItemIndex

func (self Instance) GetItemIndex(id int) int

Returns the index of the item with the given 'id'.

func (Instance) GetItemMetadata

func (self Instance) GetItemMetadata(idx int) any

Retrieves the metadata of an item. Metadata may be any type and can be used to store extra information about an item, such as an external string ID.

func (Instance) GetItemText

func (self Instance) GetItemText(idx int) string

Returns the text of the item at index 'idx'.

func (Instance) GetItemTooltip

func (self Instance) GetItemTooltip(idx int) string

Returns the tooltip of the item at index 'idx'.

func (Instance) GetPopup

func (self Instance) GetPopup() PopupMenu.Instance

Returns the PopupMenu contained in this button.

Warning: This is a required internal node, removing and freeing it may cause a crash. If you wish to hide it or any of its children, use their Window.Visible property.

func (Instance) GetSelectableItem

func (self Instance) GetSelectableItem() int

Returns the index of the first item which is not disabled, or marked as a separator. If 'from_last' is true, the items will be searched in reverse order.

Returns -1 if no item is found.

func (Instance) GetSelectedId

func (self Instance) GetSelectedId() int

Returns the ID of the selected item, or -1 if no item is selected.

func (Instance) GetSelectedMetadata

func (self Instance) GetSelectedMetadata() any

Gets the metadata of the selected item. Metadata for items can be set using SetItemMetadata.

func (Instance) HasSelectableItems

func (self Instance) HasSelectableItems() bool

Returns true if this button contains at least one item which is not disabled, or marked as a separator.

func (Instance) ID

func (self Instance) ID() ID

func (Instance) IsItemDisabled

func (self Instance) IsItemDisabled(idx int) bool

Returns true if the item at index 'idx' is disabled.

func (Instance) IsItemSeparator

func (self Instance) IsItemSeparator(idx int) bool

Returns true if the item at index 'idx' is marked as a separator.

func (Instance) ItemCount

func (self Instance) ItemCount() int

func (Instance) MoreArgs

func (self Instance) MoreArgs() MoreArgs

MoreArgs enables certain functions to be called with additional 'optional' arguments.

func (Instance) OnItemFocused

func (self Instance) OnItemFocused(cb func(index int), flags ...Signal.Flags)

func (Instance) OnItemSelected

func (self Instance) OnItemSelected(cb func(index int), flags ...Signal.Flags)

func (Instance) RemoveItem

func (self Instance) RemoveItem(idx int)

Removes the item at index 'idx'.

func (Instance) Select

func (self Instance) Select(idx int)

Selects an item by index and makes it the current item. This will work even if the item is disabled.

Passing -1 as the index deselects any currently selected item.

func (Instance) Selected

func (self Instance) Selected() int

func (Instance) SetAllowReselect

func (self Instance) SetAllowReselect(value bool)

func (Instance) SetDisableShortcuts

func (self Instance) SetDisableShortcuts(disabled bool)

If true, shortcuts are disabled and cannot be used to trigger the button.

func (Instance) SetFitToLongestItem

func (self Instance) SetFitToLongestItem(value bool)

func (Instance) SetItemAutoTranslateMode

func (self Instance) SetItemAutoTranslateMode(idx int, mode Node.AutoTranslateMode)

Sets the auto translate mode of the item at index 'idx'.

Items use [Node.AutoTranslateModeInherit] by default, which uses the same auto translate mode as the OptionButton itself.

func (Instance) SetItemCount

func (self Instance) SetItemCount(value int)

func (Instance) SetItemDisabled

func (self Instance) SetItemDisabled(idx int, disabled bool)

Sets whether the item at index 'idx' is disabled.

Disabled items are drawn differently in the dropdown and are not selectable by the user. If the current selected item is set as disabled, it will remain selected.

func (Instance) SetItemIcon

func (self Instance) SetItemIcon(idx int, texture Texture2D.Instance)

Sets the icon of the item at index 'idx'.

func (Instance) SetItemId

func (self Instance) SetItemId(idx int, id int)

Sets the ID of the item at index 'idx'.

func (Instance) SetItemMetadata

func (self Instance) SetItemMetadata(idx int, metadata any)

Sets the metadata of an item. Metadata may be of any type and can be used to store extra information about an item, such as an external string ID.

func (Instance) SetItemText

func (self Instance) SetItemText(idx int, text string)

Sets the text of the item at index 'idx'.

func (Instance) SetItemTooltip

func (self Instance) SetItemTooltip(idx int, tooltip string)

Sets the tooltip of the item at index 'idx'.

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) ShowPopup

func (self Instance) ShowPopup()

Adjusts popup position and sizing for the OptionButton, then shows the PopupMenu. Prefer this over using get_popup().popup().

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

type MoreArgs

type MoreArgs [1]gdclass.OptionButton

MoreArgs is a container for Instance functions with additional 'optional' arguments.

func (MoreArgs) AddIconItem

func (self MoreArgs) AddIconItem(texture Texture2D.Instance, label string, id int)

Adds an item, with a 'texture' icon, text 'label' and (optionally) 'id'. If no 'id' is passed, the item index will be used as the item's ID. New items are appended at the end.

Note: The item will be selected if there are no other items.

func (MoreArgs) AddItem

func (self MoreArgs) AddItem(label string, id int)

Adds an item, with text 'label' and (optionally) 'id'. If no 'id' is passed, the item index will be used as the item's ID. New items are appended at the end.

Note: The item will be selected if there are no other items.

func (MoreArgs) AddSeparator

func (self MoreArgs) AddSeparator(text string)

Adds a separator to the list of items. Separators help to group items, and can optionally be given a 'text' header. A separator also gets an index assigned, and is appended at the end of the item list.

func (MoreArgs) GetSelectableItem

func (self MoreArgs) GetSelectableItem(from_last bool) int

Returns the index of the first item which is not disabled, or marked as a separator. If 'from_last' is true, the items will be searched in reverse order.

Returns -1 if no item is found.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL