Class TextField
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
AnchorThe text field's anchor
size
Vector2The text field's size
rule
TextField.RuleThe text field's input rule
font
GenericFontThe font to use for drawing text
text
stringThe text that the text field should contain by default
multiline
boolWhether 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
DefaultRule
A TextInput.Rule that allows any visible character and spaces
public static readonly TextField.Rule DefaultRule
Field Value
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
FileNames
A TextInput.Rule that only allows characters not contained in GetInvalidFileNameChars()
public static readonly TextField.Rule FileNames
Field Value
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
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
LettersNumbers
A TextInput.Rule that only allows letters and numerals
public static readonly TextField.Rule LettersNumbers
Field Value
MobileDescription
The description of the KeyboardInput
field on mobile devices and consoles
public string MobileDescription
Field Value
MobileTitle
The title of the KeyboardInput
field on mobile devices and consoles
public string MobileTitle
Field Value
OnTextChange
An event that gets called when Text changes, either through input, or through a manual change.
public TextField.TextChanged OnTextChange
Field Value
OnlyLetters
A TextInput.Rule that only allows letters
public static readonly TextField.Rule OnlyLetters
Field Value
OnlyNumbers
A TextInput.Rule that only allows numerals
public static readonly TextField.Rule OnlyNumbers
Field Value
PathNames
A TextInput.Rule that only allows characters not contained in GetInvalidPathChars()
public static readonly TextField.Rule PathNames
Field Value
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
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
Texture
This text field's texture
public StyleProp<NinePatch> Texture
Field Value
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
CaretPos
public int CaretPos { get; set; }
Property Value
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
Font
The font that this text field should display text with
public StyleProp<GenericFont> Font { get; set; }
Property Value
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
Text
This text input's current text
public string Text { get; }
Property Value
TextScale
The scale that this text field should render text with
public StyleProp<float> TextScale { get; set; }
Property Value
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
GameTimeThe game's time
batch
SpriteBatchThe sprite batch to use for drawing
alpha
floatThe alpha to draw this element and its children with
context
SpriteBatchContextThe 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
UiStyleThe 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
objectThe text to insert
removeMismatching
boolIf 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
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
objectThe new text
removeMismatching
boolIf 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
GameTimeThe game's time