UIDropdown

Classes

UIDropDown : UIComponent

A drop-down list component that can be used to select an item from a list.

Usage example:

def init_dropdown() {
    get_component(node) $(var dropdown : UIDropDown?) {
        dropdown.items = ["Option 1", "Option 2", "Option 3"]
        dropdown.onChange = @(newIndex : int) { print("Selected index changed to {newIndex}") }
    }
}
Fields:
  • items : array<string> - List of items to display in the dropdown.

  • dropdownNode : NodeId - Node that appears when the dropdown is opened, a descendant of the node with this UIDropDown. It should likely either be the same node as itemsContainerNode or one of its parents. Its UI components and those under itemsContainerNode, other than the items, are kept out of keyboard navigation (navigable = false).

  • itemsContainerNode : NodeId - Node that will be the parent for dropdown item nodes: dropdownNode or a descendant of it. If not set, dropdownNode will be used.

  • textField : UIText? - The text field component to display the selected item.

  • itemPrefab : PrefabId - Prefab for the dropdown items (should have UIText and UIFrame components, and an interactable and navigable UIComponent such as UIButton on its root node for keyboard navigation to reach them).

  • onChange : lambda<(index:int):void> - Called when the selection changes.

UIDropDown.on_initialize()

Initializes the drop-down list and sets up button handlers.

UIDropDown.on_update()

Updates the drop-down list if the items have changed, which closes the open list, and closes the open list when the focus leaves the dropdown or the dropdown stops being interactable.

UIDropDown.on_destroy()

Removes the event listeners.

UIDropDown.select(newIndex: int; doFade: bool)

Sets the selected index and updates UI.

Arguments:
  • newIndex : int

  • doFade : bool

UIDropDown.invalidate(doFade: bool)

Updates the displayed selected item text.

Arguments:
  • doFade : bool

UIDropDown.handleNavigationMove(steps: int)

Moves the focus from the focused item of the open list by steps items, skipping the items that are not interactable, navigable and active; at the first or last such item the focus stays. Does nothing when no item of the open list has the focus.

Arguments:
  • steps : int

UIDropDown.toggle_dropdown()

Toggles the drop-down list open/closed, see open_dropdown and close_dropdown.

UIDropDown.open_dropdown()

Opens the drop-down list and focuses the selected item if it is interactable, navigable and active, else the next such item, else the previous one, or the dropdown itself when there is none. Does nothing when the dropdown is not interactable or not active in the hierarchy.

UIDropDown.close_dropdown()

Closes the drop-down list. The focus on one of its items returns to the dropdown, or is cleared when the dropdown is not interactable or not active in the hierarchy.

Properties:

UIDropDown.selectedIndex: int

Returns the currently selected index.

UIDropDown.selectedIndex =(newIndex: int)

Sets the selected index and updates UI.

Arguments:
  • newIndex : int

UIDropDown.itemNodes: array<NodeId>

Returns the list of item nodes.