Table of Contents

Class TextField

Namespace
UILib.Components
Assembly
UILib.dll

A component which holds text that a user can edit.

public class TextField : UIComponent
Inheritance
TextField
Inherited Members

Constructors

TextField(string, int)

Initializes a text field.

public TextField(string text, int fontSize)

Parameters

text string

The placeholder text

fontSize int

The font size to use

Properties

background

The background of this text field.

public Image background { get; }

Property Value

Image

clearMode

In which cases will this text field wipe its input and value.

Note: Clear modes will override equivalent retain modes.

Default: None

public TextField.ClearMode clearMode { get; }

Property Value

TextField.ClearMode

input

The label containing the user input.

public Label input { get; }

Property Value

Label

onCancel

Invokes listeners when the user cancels entering text.

public UnityEvent onCancel { get; }

Property Value

UnityEvent

onInputChanged

Invokes listeners when the user starts typing something in the input field.

The value listeners receive is the text the user is typing not the value which is actually stored in this text field.

public ValueEvent<string> onInputChanged { get; }

Property Value

ValueEvent<string>

onInvalidSubmit

Invokes listeners with the user's input when they submit something invalid.

public ValueEvent<string> onInvalidSubmit { get; }

Property Value

ValueEvent<string>

onValidSubmit

Invokes listeners with the current value stored when the user submits it.

The value listeners receive is the value stored in this text field.

If you have set a predicate, this only triggers if the user's input was valid.

public ValueEvent<string> onValidSubmit { get; }

Property Value

ValueEvent<string>

placeholder

The placeholder label.

public Label placeholder { get; }

Property Value

Label

retainFocus

Whether this text field will retain its focus after the user submits an input.

False by default.

public bool retainFocus { get; }

Property Value

bool

retainMode

In which extra cases will this text field retain the current user input.

The input will always be retained on a valid submit.

Default: None

public TextField.RetainMode retainMode { get; }

Property Value

TextField.RetainMode

submitMode

Which extra interactions with the text field will count as a submit.

Default: None

public TextField.SubmitMode submitMode { get; }

Property Value

TextField.SubmitMode

userInput

The current user input (displayed text).

public string userInput { get; }

Property Value

string

value

The current value stored in this text field. This only updates whenever the user submits a valid input.

public string value { get; }

Property Value

string

Methods

SetAlignment(AnchorType)

Sets the alignment of the text.

public void SetAlignment(AnchorType alignment)

Parameters

alignment AnchorType

The alignment to use

SetClearMode(ClearMode)

Sets when this text field should clear the user input and its value.

Note: Clear modes will override equivalent retain modes.

public void SetClearMode(TextField.ClearMode clearMode)

Parameters

clearMode TextField.ClearMode

When to clear

SetPredicate(Func<string, bool>)

Sets the predicate to use for validating the user's input.

public void SetPredicate(Func<string, bool> predicate)

Parameters

predicate Func<string, bool>

The predicate to use

SetRetainFocus(bool)

Sets whether this text field should retain focus.

public void SetRetainFocus(bool retainFocus)

Parameters

retainFocus bool

Whether to retain focus

SetRetainMode(RetainMode)

Sets in which cases this text field will retain the current user input.

The input will always be retained on a valid submit.

public void SetRetainMode(TextField.RetainMode retainMode)

Parameters

retainMode TextField.RetainMode

Which cases the input should be retained

SetSubmitMode(SubmitMode)

Sets which interactions with this text field will count as a submit.

public void SetSubmitMode(TextField.SubmitMode submitMode)

Parameters

submitMode TextField.SubmitMode

Which cases will count as a submit

SetText(string)

Sets the text displayed by this text field.

public void SetText(string text)

Parameters

text string

The text to display

SetThisTheme(Theme)

Allows setting the theme of this text field.

This handles setting the theme specifically for this component, not its children. It's protected to allow overriding if you were to create a subclass.

In most cases, you'd probably want to use SetTheme(Theme) instead.

protected override void SetThisTheme(Theme theme)

Parameters

theme Theme

The theme to apply

SetValue(string)

Sets the current value stored in this text field. Updates the internal value and the text displayed in the input field.

public void SetValue(string value)

Parameters

value string

The value to set