Table of Contents

Class UiControls

Namespace
MLEM.Ui
Assembly
MLEM.Ui.dll

UiControls holds and manages all of the controls for a UiSystem. UiControls supports keyboard, mouse, gamepad and touch input using an underlying InputHandler.

public class UiControls
Inheritance
UiControls
Inherited Members

Constructors

UiControls(UiSystem, InputHandler)

Creates a new instance of the ui controls. You should rarely have to invoke this manually, since the UiSystem handles it.

public UiControls(UiSystem system, InputHandler inputHandler = null)

Parameters

system UiSystem

The ui system to control with these controls

inputHandler InputHandler

The input handler to use for controlling, or null to create a new one.

Fields

DownButtons

A Keybind that acts as the buttons that select a Element that is below the currently selected element.

public readonly Keybind DownButtons

Field Value

Keybind

GamepadButtons

AA Keybind that acts as the buttons on a gamepad that perform the OnPressed action.

public readonly Keybind GamepadButtons

Field Value

Keybind

GamepadIndex

The zero-based index of the Microsoft.Xna.Framework.Input.GamePad used for gamepad input. If this index is lower than 0, every connected gamepad will trigger input.

public int GamepadIndex

Field Value

int

HandleGamepad

Set this to false to disable gamepad input for these ui controls. Note that this does not disable gamepad input for the underlying InputHandler.

public bool HandleGamepad

Field Value

bool

HandleKeyboard

Set this to false to disable keyboard input for these ui controls. Note that this does not disable keyboard input for the underlying InputHandler.

public bool HandleKeyboard

Field Value

bool

HandleMouse

Set this to false to disable mouse input for these ui controls. Note that this does not disable mouse input for the underlying InputHandler.

public bool HandleMouse

Field Value

bool

HandleTouch

Set this to false to disable touch input for these ui controls. Note that this does not disable touch input for the underlying InputHandler.

public bool HandleTouch

Field Value

bool

Input

The input handler that is used for querying input

public readonly InputHandler Input

Field Value

InputHandler

IsInputOurs

This value ist true if the InputHandler was created by this ui controls instance, or if it was passed in. If the input handler was created by this instance, its Update() method should be called by us.

protected readonly bool IsInputOurs

Field Value

bool

Keybinds

All Keybind instances used by these ui controls. This can be used to easily serialize and deserialize all ui keybinds.

public readonly Keybind[] Keybinds

Field Value

Keybind[]

KeyboardButtons

A list of Microsoft.Xna.Framework.Input.Keys, Microsoft.Xna.Framework.Input.Buttons and/or MouseButton that act as the buttons on the keyboard which perform the OnPressed action. If the Shift is held, these buttons perform OnSecondaryPressed.

public readonly Keybind KeyboardButtons

Field Value

Keybind

LeftButtons

A Keybind that acts as the buttons that select a Element that is to the left of the currently selected element.

public readonly Keybind LeftButtons

Field Value

Keybind

RightButtons

A Keybind that acts as the buttons that select a Element that is to the right of the currently selected element.

public readonly Keybind RightButtons

Field Value

Keybind

SecondaryGamepadButtons

A Keybind that acts as the buttons on a gamepad that perform the OnSecondaryPressed action.

public readonly Keybind SecondaryGamepadButtons

Field Value

Keybind

System

The UiSystem that this ui controls instance is controlling

protected readonly UiSystem System

Field Value

UiSystem

UpButtons

A Keybind that acts as the buttons that select a Element that is above the currently selected element.

public readonly Keybind UpButtons

Field Value

Keybind

Properties

ActiveRoot

The RootElement that is currently active. The active root element is the one with the highest Priority that CanBeActive.

public RootElement ActiveRoot { get; protected set; }

Property Value

RootElement

IsAutoNavMode

If this value is true, the ui controls are in automatic navigation mode. The state of automatic navigation is usually based on the current NavType. This means that the SelectionIndicator will be drawn around the SelectedElement.

public bool IsAutoNavMode { get; set; }

Property Value

bool

MousedElement

The Element that the mouse is currently over.

public Element MousedElement { get; protected set; }

Property Value

Element

NavType

The current UiControls.NavigationType of these ui controls, which represents the last type of interaction that was used to interact with the underlying UiSystem.

public UiControls.NavigationType NavType { get; set; }

Property Value

UiControls.NavigationType

SelectedElement

The element that is currently selected. This is the SelectedElement of the ActiveRoot.

public Element SelectedElement { get; }

Property Value

Element

TouchedElement

The Element that is currently touched.

public Element TouchedElement { get; protected set; }

Property Value

Element

Methods

GetElementUnderPos(Vector2)

Returns the Element in the underlying UiSystem that is currently below the given position. Throughout the ui system, this is used for mouse input querying.

public virtual Element GetElementUnderPos(Vector2 position)

Parameters

position Vector2

The position to query

Returns

Element

The element under the position, or null if there isn't one

GetGamepadNextElement(Direction2)

Returns the next element that should be selected during gamepad navigation, based on the Direction2 that we're looking for elements in.

protected virtual Element GetGamepadNextElement(Direction2 direction)

Parameters

direction Direction2

The direction that we're looking for next elements in

Returns

Element

The first element found in that area

GetSelectedElement(RootElement)

Returns the selected element for the given root element. A property equivalent to this method is SelectedElement.

public Element GetSelectedElement(RootElement root)

Parameters

root RootElement

The root element whose selected element to return

Returns

Element

The given root's selected element, or null if the root doesn't exist, or if there is no selected element for that root.

GetTabNextElement(bool)

Returns the next element to select when pressing the Microsoft.Xna.Framework.Input.Keys.Tab key during keyboard navigation. If the backward boolean is true, the previous element should be returned instead.

protected virtual Element GetTabNextElement(bool backward)

Parameters

backward bool

If we're going backwards (if Shift is held)

Returns

Element

The next or previous element to select

PressElement(Element, bool)

Causes the passed element to be pressed, invoking its OnPressed or OnSecondaryPressed through OnElementPressed or OnElementSecondaryPressed.

public void PressElement(Element element, bool secondary = false)

Parameters

element Element

The element to press.

secondary bool

Whether the secondary action should be invoked, rather than the primary one.

SelectElement(RootElement, Element, bool?, NavigationType?)

Selects the given element that is a child of the given root element. Optionally, automatic navigation can be forced on, causing the SelectionIndicator to be drawn around the element. A simpler version of this method is SelectElement(Element, bool?, NavigationType?).

public void SelectElement(RootElement root, Element element, bool? autoNav = null, UiControls.NavigationType? navType = null)

Parameters

root RootElement

The root element of the Element

element Element

The element to select, or null to deselect the selected element.

autoNav bool?

Whether automatic navigation should be forced on. If this is null, the automatic navigation state will stay the same.

navType UiControls.NavigationType?

An optional UiControls.NavigationType to set. If this is null, the navigation type will stay the same.

SetMousedElement(Element)

Sets the MousedElement to the given value, calling the appropriate events.

public void SetMousedElement(Element element)

Parameters

element Element

The element to set as moused

SetTouchedElement(Element)

Sets the TouchedElement to the given value, calling the appropriate events.

public void SetTouchedElement(Element element)

Parameters

element Element

The element to set as touched

Update()

Update this ui controls instance, causing the underlying InputHandler to be updated, as well as ui input to be queried.

public virtual void Update()

Events

AutoNavModeChanged

An event that is raised when IsAutoNavMode is changed. This can be used for custom actions like hiding the mouse cursor when automatic navigation is enabled.

public event Action<bool> AutoNavModeChanged

Event Type

Action<bool>

NavTypeChanged

An event that is raised when NavType is changed. It receives the previous navigation type, as well as the newly set navigation type.

public event Action<UiControls.NavigationType, UiControls.NavigationType> NavTypeChanged

Event Type

Action<UiControls.NavigationType, UiControls.NavigationType>