UI Navigation¶
Players can drive any UI built from the engine’s UI components with the keyboard or a gamepad. The
player holds Esc or the gamepad Menu button to enter UI navigation mode, and holds it again
to leave. In the mode the actions of other action sets read as released.
A control takes part when its node is active and its UIComponent is interactable and
navigable. Navigation works on the topmost canvas with such controls and skips a canvas whose
root UIComponent is not interactable, as under a modal.
Controls¶
The engine action set UI_NAV_ACTION_SET, rebindable with replace_action; its actions work only
in the mode:
UI_NAV_NEXT,UI_NAV_PREV(Tab,Shift+Tab): the next or previous control.UI_NAV_NAVIGATE(gamepad D-pad, left stick): the nearest control that way.UI_NAV_MOVE(arrows, right stick): acts inside the focused control, for example moves a slider or scrolls a scroll area.UI_NAV_SUBMIT(Enter,Space, gamepad A): clicks the focused control.UI_NAV_CANCEL(gamepad B) and a shortEsc: sendCancel, which closes an open dropdown or leaves a text input. The shortEscis not part of the action set and cannot be rebound.
Going back a screen¶
A Cancel that no control uses reaches the canvas. Listen there and skip the Capture phase:
def screen_back(evt : UINavigationEvent) {
if (evt.phase != UIInputEventPhase.Capture) {
show_previous_screen()
}
}
add_ui_event_listener(screenCanvas, UINavigationEventType.Cancel, @@screen_back)
Your own controls¶
A control that reacts to UI_NAV_MOVE listens for Move on its node and stops it on the axes
it uses; it also stops Scroll (sent while a direction is held) on those axes, or the scroll
area around it scrolls too:
def dial_move(evt : UINavigationEvent) {
if (evt.phase == UIInputEventPhase.Target && evt.steps.x != 0) {
stop_propagation(evt)
turn_dial(evt.currentTarget, evt.steps.x)
}
}
add_ui_event_listener(dial, UINavigationEventType.Move, @@dial_move)