UIComponent, ui events¶
See UI Navigation for keyboard and gamepad control of the UI.
Enumerations¶
- UIFocusEventType¶
The type of the focus event.
- Values:
FocusIn = 0x0 - The element has received focus.
FocusOut = 0x1 - The element has lost focus.
- UIInputEventPhase¶
The phase of the input event.
- Values:
Capture = 0 - The event is captured by ancestors before the target.
Target = 1 - The event is at the target node.
Bubble = 2 - The event is bubbling up the hierarchy after the target.
- UIMouseEventType¶
The type of the mouse event.
- Values:
MouseDown = 0x0 - The mouse button is pressed.
MouseUp = 0x1 - The mouse button is released.
MouseMove = 0x2 - The mouse cursor is over the target and is moving.
MouseOver = 0x3 - The mouse cursor enters the target.
MouseOut = 0x4 - The mouse cursor leaves the target.
MouseClick = 0x5 - Click event (mouse button is pressed and released on the same target, or a
UI_NAV_SUBMITpress, Enter, Space or gamepad A by default, on the focused node in UI navigation mode when it is a navigation candidate).MouseWheel = 0x6 - The mouse wheel is scrolled over the target.
The type of the UI navigation event.
- Values:
Move = 0x0 - A direction of
UI_NAV_MOVEis pressed or repeats in UI navigation mode (arrows, right stick).Scroll = 0x1 - A direction of
UI_NAV_MOVEis held in UI navigation mode (arrows, right stick): sent every frame from the frame after the press, after Move, while the node focused at the last step keeps the focus.Cancel = 0x2 -
UI_NAV_CANCEL(gamepad B) or a short Esc in UI navigation mode: sent to the focused node if it is a candidate of the topmost canvas with candidates, otherwise to that canvas, or to the topmost canvas when none has candidates. An open UIDropDown closes its list and a focused UITextInput gives up the focus; otherwise it bubbles on, so a listener on the canvas node that skips the Capture phase gets the Cancels no control handled. A global listener also gets the Cancels that a control handled.
Classes¶
- UIComponent : Component¶
Note
UIFrame component is automatically added to the node if it is not already present
Base class for all UI components. Component that marks a node as “interactive” in the UI system. Controls whether the node receives input events (mouse, focus).
- Fields:
navigable : bool = true - Whether keyboard and gamepad navigation can focus the node; the mouse and set_ui_focus_node ignore it.
- UIComponent.on_initialize()¶
Applies the interactable state to the UIVisualState components of the node.
- UIComponent.invalidateInteractable(doFade: bool)¶
Applies the current interactable flag to all UIVisualState instances attached to the node.
Used to allow visual components to switch between disabled/enabled visual states.
Does nothing before the component is on a node (new UIButton(interactable = false)); on_initialize applies the state.
- Arguments:
doFade : bool
- Properties:
- UIComponent.interactable: bool¶
Returns the current interactable state. :Returns: * bool - True if the node is interactive and accepts input events.
- UIComponent.interactable =(value: bool)¶
Sets the interactable state. If the value changes, invalidateInteractable() is invoked to update related visual components.
- Arguments:
value : bool
- UIVisualState : Component¶
Note
UIFrame component is automatically added to the node if it is not already present
A component that manages the visual state of a UI element.
- UIVisualState.setInteractable(val: bool; doFade: bool)¶
Sets whether the component is interactable.
- Arguments:
val : bool
doFade : bool
Structures¶
- UIInputEvent¶
The base structure for input events.
- Fields:
canvas : NodeId - The canvas node where the event occurred.
phase : UIInputEventPhase - The phase of the input event.
target : NodeId - The original node that triggered the event (e.g., the node where the mouse was clicked).
currentTarget : NodeId - The node currently handling the event during propagation (changes as the event bubbles or captures through the hierarchy).
- UIMouseEvent : UIInputEvent¶
The structure for mouse events.
- Fields:
eventType : UIMouseEventType - The type of the mouse event.
mouseButton : MouseButton - The mouse button that triggered the event (Left for a click from the keyboard).
wheelDelta : float - The mouse wheel delta (only for MouseWheel events). Positive values indicate scrolling up/away from the user.
shifts : KeyboardShifts - Keyboard shift state during the event (primarily for MouseWheel events).
- UIFocusEvent : UIInputEvent¶
The structure for UI focus events. Only nodes with UIComponent.interactable = true receive focus events.
- Fields:
eventType : UIFocusEventType - The type of the UI event.
The structure for UI navigation events, sent in UI navigation mode to the focused node when it is a candidate of the topmost canvas with candidates; Cancel otherwise goes to that canvas.
- Fields:
eventType : UINavigationEventType - The type of the UI navigation event.
steps : int2 - Move: 1 or -1 on one axis for a direction of
UI_NAV_MOVEpressed or repeating this frame (the other is 0): x is Right minus Left, y is Down minus Up.amount : float2 - Scroll: the held direction on one axis (the other is 0), from -1 to 1 (analog on the stick): x is Right minus Left, y is Down minus Up.
Functions¶
UINavigationEvent!= (a: UINavigationEvent; b: UINavigationEvent) : bool
UINavigationEvent== (a: UINavigationEvent; b: UINavigationEvent) : bool
add_ui_event_listener (event_type: UIFocusEventType; listener: function<(evt:UIFocusEvent):void>)
add_ui_event_listener (event_type: UIMouseEventType; listener: function<(evt:UIMouseEvent):void>)
get_ui_mouse_position (node: NodeId; var res: float3&) : bool
remove_ui_event_listener (event_type: UIFocusEventType; listener: function<(evt:UIFocusEvent):void>)
remove_ui_event_listener (event_type: UIMouseEventType; listener: function<(evt:UIMouseEvent):void>)
stop_immediate_propagation (event: UIMouseEvent|UIFocusEvent|UINavigationEvent) : auto
stop_propagation (event: UIMouseEvent|UIFocusEvent|UINavigationEvent) : auto
- UIFocusEvent!=(a: UIFocusEvent; b: UIFocusEvent): bool¶
Compares two UIFocusEvent structures. :Arguments: * a : UIFocusEvent
b : UIFocusEvent
- Returns:
bool - True if the structures are not equal, false otherwise.
- UIFocusEvent==(a: UIFocusEvent; b: UIFocusEvent): bool¶
Compares two UIFocusEvent structures. :Arguments: * a : UIFocusEvent
b : UIFocusEvent
- Returns:
bool - True if the structures are equal, false otherwise.
- UIInputEvent!=(a: UIInputEvent; b: UIInputEvent): bool¶
Compares two UIInputEvent structures. :Arguments: * a : UIInputEvent
b : UIInputEvent
- Returns:
bool - True if the structures are not equal, false otherwise.
- UIInputEvent==(a: UIInputEvent; b: UIInputEvent): bool¶
Compares two UIInputEvent structures. :Arguments: * a : UIInputEvent
b : UIInputEvent
- Returns:
bool - True if the structures are equal, false otherwise.
- UIMouseEvent!=(a: UIMouseEvent; b: UIMouseEvent): bool¶
Compares two UIMouseEvent structures. :Arguments: * a : UIMouseEvent
b : UIMouseEvent
- Returns:
bool - True if the structures are not equal, false otherwise.
- UIMouseEvent==(a: UIMouseEvent; b: UIMouseEvent): bool¶
Compares two UIMouseEvent structures. :Arguments: * a : UIMouseEvent
b : UIMouseEvent
- Returns:
bool - True if the structures are equal, false otherwise.
Compares two UINavigationEvent structures. :Arguments: * a : UINavigationEvent
- Returns:
bool - True if the structures are not equal, false otherwise.
Compares two UINavigationEvent structures. :Arguments: * a : UINavigationEvent
- Returns:
bool - True if the structures are equal, false otherwise.
- add_ui_event_listener(event_type: UIFocusEventType; listener: function<(evt:UIFocusEvent):void>)¶
Adds a global listener for UI focus events.
Usage example:
def focus_event_handler(evt : UIFocusEvent) {
if (evt.phase == UIInputEventPhase.Target) {
print("{evt.currentTarget} is focused!")
}
}
...
add_ui_event_listener(btn, UIFocusEventType.FocusIn, @@focus_event_handler)
- Arguments:
event_type : UIFocusEventType
listener : function<(evt: UIFocusEvent):void>
- add_ui_event_listener(event_type: UIMouseEventType; listener: function<(evt:UIMouseEvent):void>)
Adds a global listener for UI mouse events.
Usage example:
def mouse_event_handler(evt : UIMouseEvent) {
if (evt.phase == UIInputEventPhase.Target) {
print("{evt.currentTarget} is clicked!")
}
}
...
add_ui_event_listener(UIMouseEventType.MouseClick, @@mouse_event_handler)
Note
Only nodes with UIComponent.interactable = true receive focus events. Focus events are only sent in the Target phase (no Capture or Bubble).
- Arguments:
event_type : UIMouseEventType
listener : function<(evt: UIMouseEvent):void>
Adds a global listener for UI navigation events.
Usage example:
def move_handler(evt : UINavigationEvent) {
if (evt.phase == UIInputEventPhase.Target) {
print("Arrows {evt.steps} on {evt.currentTarget}")
}
}
...
add_ui_event_listener(UINavigationEventType.Move, @@move_handler)
Note
Navigation events go to the focused node in UI navigation mode when it is a candidate of the topmost canvas with candidates; Cancel otherwise goes to that canvas.
- Arguments:
event_type : UINavigationEventType
listener : function<(evt: UINavigationEvent):void>
- add_ui_event_listener(node: NodeId; event_type: UIFocusEventType; listener: function<(evt:UIFocusEvent):void>)
Adds a listener for a UI focus event for a specific node.
Usage example:
def button_focus_event_handler(evt : UIFocusEvent) {
if (evt.phase == UIInputEventPhase.Target) {
print("Button {evt.currentTarget} is focused!")
}
}
...
add_ui_event_listener(btn, UIFocusEventType.FocusIn, @@button_focus_event_handler)
Note
Only nodes with UIComponent.interactable = true receive focus events. Focus events are only sent in the Target phase (no Capture or Bubble).
- Arguments:
node : NodeId
event_type : UIFocusEventType
listener : function<(evt: UIFocusEvent):void>
- add_ui_event_listener(node: NodeId; event_type: UIMouseEventType; listener: function<(evt:UIMouseEvent):void>)
Adds a listener for a UI mouse event for a specific node.
Usage example:
def button_mouse_event_handler(evt : UIMouseEvent) {
if (evt.phase == UIInputEventPhase.Target) {
print("Button {evt.currentTarget} is clicked!")
}
}
...
add_ui_event_listener(btn, UIMouseEventType.MouseClick, @@button_mouse_click_event_handler)
- Arguments:
node : NodeId
event_type : UIMouseEventType
listener : function<(evt: UIMouseEvent):void>
Adds a listener for a UI navigation event for a specific node.
Usage example:
def slider_move_handler(evt : UINavigationEvent) {
if (evt.phase == UIInputEventPhase.Target && evt.steps.x != 0) {
print("Move the value of {evt.currentTarget} by {evt.steps.x} steps")
stop_propagation(evt)
}
}
...
add_ui_event_listener(slider, UINavigationEventType.Move, @@slider_move_handler)
Note
Navigation events go to the focused node in UI navigation mode when it is a candidate of the topmost canvas with candidates, with Capture, Target and Bubble phases; Cancel otherwise goes to that canvas.
- Arguments:
node : NodeId
event_type : UINavigationEventType
listener : function<(evt: UINavigationEvent):void>
- get_root_canvas(node: NodeId): UICanvas?¶
Returns the UICanvas the node belongs to: the canvas of the node itself or of its nearest ancestor.
- Arguments:
node : NodeId - The node to find the canvas for.
- Returns:
UICanvas? - The canvas component, or null when the node is not under a canvas.
- get_ui_focused_node(): NodeId¶
Returns the currently focused UI node.
- get_ui_mouse_position(node: NodeId): float3¶
Gets the mouse position in the local space of the node.
- Arguments:
node : NodeId - The node to get the mouse position for.
- Returns:
float3 - The mouse position in the local space of the node. Zero if position cannot be calculated.
- get_ui_mouse_position(node: NodeId; res: float3&): bool
Gets the mouse position in the local space of the node.
- Arguments:
node : NodeId - The node to get the mouse position for.
res : float3& - The resulting mouse position in the local space of the node.
- Returns:
bool - True if position is calculated, false otherwise.
- is_mouse_inside_frame(frame: UIFrame?): bool¶
Checks if the mouse is inside the given UI frame.
- Arguments:
frame : UIFrame? - The UI frame to check.
- Returns:
bool - True if the mouse is inside the frame, false otherwise.
Returns true in UI navigation mode for a key bound to an enabled UI_NAV_NEXT or UI_NAV_PREV (Tab by default)
of the active UI_NAV_ACTION_SET, with any modifiers, so a focused text input does not type it. The keys of UI_NAV_SUBMIT still type.
- Arguments:
key : KeyCode - The key of a keyboard event the text input reads.
- Returns:
bool - True if the text input must not type the key, false otherwise.
- remove_ui_event_listener(event_type: UIFocusEventType; listener: function<(evt:UIFocusEvent):void>)¶
Removes a global listener for UI focus events.
Usage example:
remove_ui_event_listener(btn, UIFocusEventType.FocusIn, @@focus_event_handler)
- Arguments:
event_type : UIFocusEventType
listener : function<(evt: UIFocusEvent):void>
- remove_ui_event_listener(event_type: UIMouseEventType; listener: function<(evt:UIMouseEvent):void>)
Removes a global listener for UI mouse events.
Usage example:
remove_ui_event_listener(UIMouseEventType.MouseClick, @@mouse_event_handler)
- Arguments:
event_type : UIMouseEventType
listener : function<(evt: UIMouseEvent):void>
Removes a global listener for UI navigation events.
Usage example:
remove_ui_event_listener(UINavigationEventType.Move, @@move_handler)
- Arguments:
event_type : UINavigationEventType
listener : function<(evt: UINavigationEvent):void>
- remove_ui_event_listener(node: NodeId; event_type: UIFocusEventType; listener: function<(evt:UIFocusEvent):void>)
Removes a listener for a UI focus event for a specific node.
Usage example:
remove_ui_event_listener(btn, UIFocusEventType.FocusIn, @@button_focus_event_handler)
- Arguments:
node : NodeId
event_type : UIFocusEventType
listener : function<(evt: UIFocusEvent):void>
- remove_ui_event_listener(node: NodeId; event_type: UIMouseEventType; listener: function<(evt:UIMouseEvent):void>)
Removes a listener for a UI mouse events for a specific node.
Usage example:
remove_ui_event_listener(btn, UIMouseEventType.MouseClick, @@button_mouse_click_event_handler)
- Arguments:
node : NodeId
event_type : UIMouseEventType
listener : function<(evt: UIMouseEvent):void>
Removes a listener for a UI navigation event for a specific node.
Usage example:
remove_ui_event_listener(slider, UINavigationEventType.Move, @@slider_move_handler)
- Arguments:
node : NodeId
event_type : UINavigationEventType
listener : function<(evt: UINavigationEvent):void>
- set_ui_focus_node(comp: UIComponent const?): bool¶
Sets the UI input/focus to the specified UIComponent. This function attempts to make the given UI component the current focus target. If another component was previously focused, it will lose focus. set_ui_focus_node(null) can be used to clear the current focus.
- Arguments:
comp : UIComponent? - The UI component to focus.
- Returns:
bool - True if the focus was successfully set, false otherwise.
Note
Only nodes with UIComponent.interactable = true can receive focus.
Stops the propagation of the event. Propagation stops immediately after the current event handler is finished.
- Arguments:
event : option< UIMouseEvent| UIFocusEvent| UINavigationEvent> - The event to stop the propagation for.
Usage example:
def button_mouse_click_event_handler(evt : UIMouseEvent) {
if (evt.phase == UIInputEventPhase.Target) {
print("Button {evt.target} is clicked!")
stop_immediate_propagation(evt)
}
}
...
add_ui_event_listener(btn, UIMouseEventType.MouseClick, @@button_mouse_click_event_handler)
Stops the propagation of the event. This function doesn’t affect currentTarget’s listeners, all of them will be called.
- Arguments:
event : option< UIMouseEvent| UIFocusEvent| UINavigationEvent> - The event to stop the propagation for.
Usage example:
def button_mouse_click_event_handler(evt : UIMouseEvent) {
if (evt.phase == UIInputEventPhase.Target) {
print("Mouse is down on node {evt.target}")
stop_propagation(evt)
}
}
...
add_ui_event_listener(btn, UIMouseEventType.MouseClick, @@button_mouse_click_event_handler)