Skip to main content

InputComponent

extends ImageComponent implements IStylable<InputComponent, InputStyle>, IFocusable, ICopyable<InputComponent>

Description

The InputComponent is a neat wrapper around the TextMeshPro TMP_InputField.

It works quite analogously and mostly just offers a code-based access to all of the neccessary features.
Built using TextComponents it is very easy to customize the input field.

note

All relevant fields and functions provided by the underlying TMP_InputField are also provided via the InputComponent, however if you need more granular control GetInput() returns you the raw TextMeshPro component directly.

Additionally the InputComponent makes use of the IFocusable interface, allowing for easy control flows when using them in combination with FocusStates.
When an input is focused, Unity's underlying focused element also switches to the input, allowing for seamless transitions of where your input is displayed (i.e. switching between login fields).

Examples

Simple UI Builder
InputComponent inputField = UI.Input("Your name here...")
.OnChanged(value =>
{
// ... fluent style handler for change event
})
.OnSubmit(value =>
{
// ... and submit event
})
.FontSize(20)
.Size(300, 50)
.Focusable(_state, UserName) // native support for FocusStates
.Parent(canvas);

Implementation