Class: UIMenu
The `UIMenu` class represents a menu UI widget with customizable options
such as axis, rows, columns, disabled item, multiple selection, and selectable items.
It support both mouse and keys navigation.
It emit 'E_ITEM_FOCUSED', 'E_ITEM_UNFOCUSED', 'E_ITEM_SELECTED', 'E_ITEM_UNSELECTED' and E_UNSELECTED events.
- inherit from: UIWidget
- parent of: UIMenuListView, UIMenuText
Constructors
- new UIMenu(options): UIMenu
The constructor.
- options: An object containing various options for configuring the behavior of the menu.
Methods
- addWidget(widget: UIWidget, index: number): void
The "addWidget" function adds a UI widget item to the menu.
- widget: The `widget` item.
- index: The `index` parameter is an optional parameter of type `number` that
specifies the position at which the widget should be inserted in the menu. If no index is
provided (default value is -1), the widget will be added at the end of the menu.
- animate(animation: string): void
The "animate" function trigger animation to the widget `node` HTMLElement.
- animation: The `animation` parameter is a string that represents the name of the
animation to be applied to the `node` HTMLElement.
- appendChild(child: HTMLElement): void
The "appendChild" function appends a given HTML element as a child to the widget node.
- child: The `child` parameter is an instance of the `HTMLElement` class. It
represents an HTML element that you want to append to the widget node.
- appendStyles(styles: string): void
The "appendStyles" function appends CSS styles to the `node` HTMLElement.
- styles: The `styles` parameter is a string that represents CSS styles that you want
to append to the `cssText` property of the `node` object.
- clear(): void
The "clear" function remove all widget items.
- delete(): void
The "delete" function free all resources.
Warning: you need to call this method to free allocation for this object.
- focus(focusIndex: MenuFocus): void
The "focus" function.
- focusWidget(index: number, preventScroll: boolean, emit: boolean): void
The "focusWidget" function is used to focus on a specific widget item, scroll to it if necessary, and
emit an 'E_ITEM_FOCUSED' event.
- index: The index position of the widget that you want to focus on.
- preventScroll: A boolean value indicating whether to prevent scrolling to
the focused widget if it is not currently visible within the viewport.
- emit: The `emit` parameter is a boolean value that determines whether an
event should be emitted after focusing the widget.
- getFocusedWidgetId()
The "getFocusedWidgetId" function returns the ID of the focused widget, or null if there is no
focused widget.
- getFocusedWidgetIndex(): number
The "getFocusedWidgetIndex" function returns the index position of the focused widget item, or -1 if no widget is
focused.
- getId(): string
- getNode(): HTMLDivElement
The "getNode" function returns the root `node` HTMLElement of the widget.
- getPosition(): vec2
The "getPosition" function returns the relative x and y coordinates of the widget `node` HTMLElement.
- getScreenPosition(): vec2
The "getScreenPosition" function returns the left and top coordinates of the widget `node` HTMLElement on
the screen.
- getSelectedWidgetId()
The "getSelectedWidgetId" function returns the ID of the first selected widget, or null if no widget
is selected.
- getSelectedWidgetIds()
The "getSelectedWidgetIds" function returns an array of string IDs of selected widget items.
- getSelectedWidgetIndex(): number
The "getSelectedWidgetIndex" function returns the index position of the first selected widget item or -1 if no
widget is selected.
- getSelectedWidgetIndexes()
The "getSelectedWidgetIndexes" function returns an array of index position of selected widget items.
- getWidget(index: number): UIWidget
The "getWidget" function returns the UIWidget at the specified index.
- index: The index parameter is a number that represents the position of the widget
in an array or collection.
- getWidgets()
The "getWidgets" function returns the widgets property.
- handleWidgetClicked(widget: UIWidget): void
- handleWidgetHover(widget: UIWidget): void
- isEnabled(): boolean
The "isEnabled" function checks if widget is enabled or not.
- isFocused(): boolean
The "isFocused" function checks if widget is focused.
- isSelected(): boolean
The "isSelected" function checks if widget is selected or not.
- isVisible(): boolean
The "isVisible" function checks if the widget is visible.
- onAction(actionId: string): void
The "onAction" function.
- removeChild(index: number): void
The "removeChild" function removes a child element from the widget node.
- index: The index parameter is the position of the child element that you want to
remove from the widget node.
- removeWidget(index: number): void
The "removeWidget" function removes a UI widget item from the menu.
- index: The index parameter is the position of the widget in the menu to removed.
- selectWidget(index: number, emit: boolean): void
The "selectWidget" function selects a specific widget item and emits an 'E_ITEM_SELECTED' event.
- index: The index position of the widget that you want to select on.
- emit: The `emit` parameter is a boolean value that determines whether an
event should be emitted after selecting the widget.
- setEnabled(enabled: boolean): void
The "setEnabled" function sets the enabled state flag.
It is just to expose a convenient option to the user, this flag has not effect on the UI manager.
Nota bene: toggle the `u-disabled` class on `node`.
- enabled: The `enabled` parameter is a boolean value that determines whether the
widget is enabled or disabled.
- setEnabledWidget(index: number, enabled: boolean): void
The "setEnabledWidget" function sets the enabled state of a specific widget item.
- index: The index position of the widget that you want to enabled on.
- enabled: The "enabled" parameter is a boolean value that determines whether the
widget should be enabled or disabled.
- setEnabledWidgets(enabled: boolean): void
The "setEnabledWidgets" function sets the enabled state of all widget items.
- enabled: The "enabled" parameter is a boolean value that determines whether the
widgets should be enabled or disabled.
- setId(id: string): void
The "setId" function sets the id property.
- id: A string representing the unique identifier to be set.
- setPosition(x: number, y: number): void
The "setPosition" function sets the left and top position to the widget `node` HTMLElement.
Nota bene: works only if position is `absolute`.
- x: The horizontal position of the element on the page.
- y: The vertical position of the element on the page.
- setSelected(selected: boolean): void
The "setSelected" function sets the selected state flag.
It is just to expose a convenient option to the user, this flag has not effect on the UI manager.
Nota bene: toggle the `u-selected` class on `node`.
- selected: The `selected` parameter is a boolean value that indicates whether the
element should be selected or not.
- setVisible(visible: boolean): void
The "setVisible" function sets the visibility state.
Nota bene: toggle the `u-hidden` class on `node`.
- visible: The `visible` parameter is a boolean value that determines whether the
element should be visible or hidden. If `visible` is true, the element will be displayed, otherwise
it will be hidden.
- unfocus(): void
The "unfocus" function removes the `u-focused` class from the `node` HTMLElement.
It emits an 'E_UNFOCUSED' event and unsubscribes the inputManager from input action event.
- unfocusWidget(emit: boolean): void
The "unfocusWidget" function unfocuses widgets, and emits an 'E_ITEM_UNFOCUSED' event.
- emit: The `emit` parameter is a boolean value that determines whether an
event should be emitted after focusing the widget.
- unselectWidget(index: number, emit: boolean): void
The "unselectWidget" function unselects a specific widget item and emits an 'E_ITEM_UNSELECTED' event.
- index: The index position of the widget that you want to unselect on.
- emit: The `emit` parameter is a boolean value that determines whether an
event should be emitted after unselecting the widget.
- unselectWidgets(emit: boolean): void
The "unselectWidgets" function deselects all widgets and emits an 'E_UNSELECTED' event.
- emit: The `emit` parameter is a boolean value that determines whether an
event should be emitted after unselecting all widgets.
- update(ts: number): void
The "update" function.
- ts: The `ts` parameter stands for "timestep".