Class UIContextMenu

Contains data used for initializing a context menu used on UI elements. When specifying menu items you must provide a path. Path must be formated in a certain way. All path elements must be separated by /, for example "View/Toolbars/Find". "View" would be the top level path element, "Toolbars" a child in its menu that opens up its own submenu, and "Find" a child in the "Toolbars" sub-menu with an optional callback.

A context menu can either by provided to UIElements, or opened manually by calling open.

Hierarchy (view full)

Constructors

  • Creates a new context menu object.

    Parameters

    • OptionalshortcutContext: ShortcutContext

      A shortcut context. If given, this context will be enabled once the menu is opened and disabled once the menu is closed.

    • OptionalisInternalConstructor: boolean

    Returns UIContextMenu

Accessors

  • get customElements(): UIElement[]
  • Gets a list of all added custom elements to the Context Menu.

    Returns UIElement[]

  • set customElements(value): void
  • Parameters

    Returns void

Methods

  • Adds a custom UI Element to the context menu as a sub-item.

    Parameters

    • element: UIElement

      The UI Element to add to the menu as a sub-item.

    Returns void

  • Adds a new item to the menu.

    Parameters

    • path: string

      Path that determines where to add the element. See class information on how to specify paths. All sub-elements of a path will be added automatically.

    • fnOnSelected: (() => void)

      Callback to invoke when the path element is selected.

        • (): void
        • Returns void

    • OptionalfnOnIsActive: (() => boolean)

      Callback to invoke when determining if the menuItem is active.

        • (): boolean
        • Returns boolean

    • OptionalshortcutAction: ShortcutActionBase

      Shortcut action to display next to the item name.

    Returns void

  • Adds a new separator to the menu.

    Parameters

    • Optionalpath: string

      Path that determines where to add the element. See class information on how to specify paths. All sub-elements of a path will be added automatically.

    Returns void

  • Adds a new toggle to the menu.

    Parameters

    • path: string

      Path that determines where to add the element. See class information on how to specify paths. All sub-elements of a path will be added automatically.

    • initialState: boolean

      The initial state of the context menu toggle. If true, the toggle will start in toggled state.

    • callback: (() => void)

      Callback to trigger when the path element is selected.

        • (): void
        • Returns void

    • OptionalshortcutAction: ShortcutActionBase

      Shortcut action to display next to the item name.

    Returns void

  • Closes the context menu if open.

    Returns void

  • Opens a context menu at the specified position relative to the provided ui element base.

    Parameters

    • position: Immutable<Vector2>

      The position where the context menu should be displayed.

    • uiElement: UIElementBase

      The UI element serving as a position reference.

    • OptionaluseNativeMenu: boolean

      Whether the context menu should be displayed using native context menu when available, use the engine context menu otherwise.

    Returns void

  • Opens a context menu at the specified UIElementBase.

    Parameters

    • uiElement: UIElementBase

      The UI element serving as a position reference.

    Returns void

  • Normally menu items use values from their paths as their names. However path labels don't provide a way of localizing the menu item. This method allows you to set specific names (different from path labels) to each menu item. All the values are localized so they will also be updated according to the string table.

    Parameters

    • label: string

      Label of the element.

    • name: I18N

      Name to display when the menu is shown.

    Returns void

  • Creates a new instance of the UIContextMenu class that contains a list of menu items based on the specified enumType.

    Type Parameters

    Parameters

    • enumType: EnumClassOf<T>

      The enumeration type to create the context menu from.

    • onSelected: ((value: EnumValue<T, number>) => void)

      The callback to invoke when a menu item is selected.

        • (value): void
        • Parameters

          Returns void

    • OptionalinitialValue: EnumValue<T, number>

      Optional, the initial value that is selected when the menu is opened.

    • OptionalisIncludingZero: boolean

      Optional, if set to false, will exclude any enum value that is zero. Default is true.

    Returns UIContextMenu

    A new instance of the UIContextMenu class.