Table of Contents

Class TextField

Namespace
MLEM.Ui.Elements
Assembly
MLEM.Ui.dll

A text field element for use inside of a UiSystem. A text field is a selectable element that can be typed in, as well as copied and pasted from. If an on-screen keyboard is required, then this text field will automatically open an on-screen keyboard using OpenOnScreenKeyboard(string, string, string, bool). This class interally uses MLEM's TextInput.

public class TextField : Element, IGenericDataHolder
Inheritance
TextField
Implements
Inherited Members
Extension Methods

Constructors

TextField(Anchor, Vector2, Rule, GenericFont, string, bool)

Creates a new text field with the given settings

public TextField(Anchor anchor, Vector2 size, TextField.Rule rule = null, GenericFont font = null, string text = null, bool multiline = false)

Parameters

anchor Anchor

The text field's anchor

size Vector2

The text field's size

rule TextField.Rule

The text field's input rule

font GenericFont

The font to use for drawing text

text string

The text that the text field should contain by default

multiline bool

Whether the text field should support multi-line editing

Fields

CaretWidth

The width that the caret should render with, in pixels

public StyleProp<float> CaretWidth

Field Value

StyleProp<float>

DefaultRule

A TextInput.Rule that allows any visible character and spaces

public static readonly TextField.Rule DefaultRule

Field Value

TextField.Rule

EnterReceiver

An element that should be pressed (using PressElement(Element, bool)) if Microsoft.Xna.Framework.Input.Keys.Enter is pressed while this text field is active. Note that, for text fields that are Multiline, this is ignored. This also occurs once the text input window is successfully closed on a mobile device.

public Element EnterReceiver

Field Value

Element

FileNames

A TextInput.Rule that only allows characters not contained in GetInvalidFileNameChars()

public static readonly TextField.Rule FileNames

Field Value

TextField.Rule

HoveredColor

The color that this text field should display with while it is hovered

public StyleProp<Color> HoveredColor

Field Value

StyleProp<Color>

HoveredTexture

This text field's texture while it is hovered

public StyleProp<NinePatch> HoveredTexture

Field Value

StyleProp<NinePatch>

InputRule

The rule used for text input. Rules allow only certain characters to be allowed inside of a text input.

public TextField.Rule InputRule

Field Value

TextField.Rule

LettersNumbers

A TextInput.Rule that only allows letters and numerals

public static readonly TextField.Rule LettersNumbers

Field Value

TextField.Rule

MobileDescription

The description of the KeyboardInput field on mobile devices and consoles

public string MobileDescription

Field Value

string

MobileTitle

The title of the KeyboardInput field on mobile devices and consoles

public string MobileTitle

Field Value

string

OnTextChange

An event that gets called when Text changes, either through input, or through a manual change.

public TextField.TextChanged OnTextChange

Field Value

TextField.TextChanged

OnlyLetters

A TextInput.Rule that only allows letters

public static readonly TextField.Rule OnlyLetters

Field Value

TextField.Rule

OnlyNumbers

A TextInput.Rule that only allows numerals

public static readonly TextField.Rule OnlyNumbers

Field Value

TextField.Rule

PathNames

A TextInput.Rule that only allows characters not contained in GetInvalidPathChars()

public static readonly TextField.Rule PathNames

Field Value

TextField.Rule

PlaceholderColor

The color that the PlaceholderText should display with

public StyleProp<Color> PlaceholderColor

Field Value

StyleProp<Color>

PlaceholderText

The text that displays in this text field if Text is empty

public string PlaceholderText

Field Value

string

TextColor

The color that this text field's text should display with

public StyleProp<Color> TextColor

Field Value

StyleProp<Color>

TextOffsetX

The x position that text should start rendering at, based on the x position of this text field.

public StyleProp<float> TextOffsetX

Field Value

StyleProp<float>

Texture

This text field's texture

public StyleProp<NinePatch> Texture

Field Value

StyleProp<NinePatch>

Properties

CaretLine

The line of text that the caret is currently on. This can only be only non-0 if Multiline is true.

public int CaretLine { get; }

Property Value

int

CaretPos

The position of the caret within the text. This is always between 0 and the Length of Text

public int CaretPos { get; set; }

Property Value

int

CaretPosInLine

The position in the current CaretLine that the caret is currently on. If Multiline is false, this value is always equal to CaretPos.

public int CaretPosInLine { get; }

Property Value

int

Font

The font that this text field should display text with

public StyleProp<GenericFont> Font { get; set; }

Property Value

StyleProp<GenericFont>

MaskingCharacter

A character that should be displayed instead of this text input's Text content. The amount of masking characters displayed will be equal to the Text's length. This behavior is useful for password inputs or similar.

public char? MaskingCharacter { get; set; }

Property Value

char?

MaximumCharacters

The maximum amount of characters that can be input into this text input. If this is set, the length of Text will never exceed this value.

public int? MaximumCharacters { get; set; }

Property Value

int?

Multiline

Whether this text input should support multi-line editing. If this is true, pressing Microsoft.Xna.Framework.Input.Keys.Enter will insert a new line into the Text if the InputRule allows it. Additionally, text will be rendered with horizontal soft wraps, and lines that are outside of the text input's bounds will be hidden.

public bool Multiline { get; set; }

Property Value

bool

Text

This text input's current text

public string Text { get; }

Property Value

string

TextScale

The scale that this text field should render text with

public StyleProp<float> TextScale { get; set; }

Property Value

StyleProp<float>

Methods

Draw(GameTime, SpriteBatch, float, SpriteBatchContext)

Draws this element and all of its children. Override this method to draw the content of custom elements. Note that, when this is called, SpriteBatch.Begin has already been called with custom Transform etc. applied.

public override void Draw(GameTime time, SpriteBatch batch, float alpha, SpriteBatchContext context)

Parameters

time GameTime

The game's time

batch SpriteBatch

The sprite batch to use for drawing

alpha float

The alpha to draw this element and its children with

context SpriteBatchContext

The sprite batch context to use for drawing

InitStyle(UiStyle)

Initializes this element's StyleProp<T> instances using the ui system's UiStyle.

protected override void InitStyle(UiStyle style)

Parameters

style UiStyle

The new style

InsertText(object, bool)

Inserts the given text at the CaretPos. If the resulting Text exceeds MaximumCharacters, the end will be cropped to fit.

public void InsertText(object text, bool removeMismatching = false)

Parameters

text object

The text to insert

removeMismatching bool

If any characters that don't match the InputRule should be left out

RemoveText(int, int)

Removes the given amount of text at the given index

public void RemoveText(int index, int length)

Parameters

index int

The index

length int

The amount of text to remove

SetAreaAndUpdateChildren(RectangleF)

Sets this element's Area to the given RectangleF and invokes the OnElementAreaUpdated event. This method also updates all of this element's Children's areas. Note that this method does not take into account any auto-sizing, anchoring or positioning, and so it should be used sparingly, if at all.

public override void SetAreaAndUpdateChildren(RectangleF area)

Parameters

area RectangleF
See Also

SetText(object, bool)

Replaces this text input's text with the given text. If the resulting Text exceeds MaximumCharacters, the end will be cropped to fit.

public void SetText(object text, bool removeMismatching = false)

Parameters

text object

The new text

removeMismatching bool

If any characters that don't match the InputRule should be left out

Update(GameTime)

Updates this element and all of its SortedChildren

public override void Update(GameTime time)

Parameters

time GameTime

The game's time