Table of Contents

Class EditText

Namespace
Stride.UI.Controls
Assembly
Stride.UI.dll

Represent an edit text where the user can enter text.

[DataContract("EditText")]
[Display(null, "Input")]
public class EditText : Control, IUIElementUpdate, IUIElementChildren, IIdentifiable
Inheritance
EditText
Implements
Inherited Members
Extension Methods

Constructors

EditText()

Create a new instance of EditText.

public EditText()

Fields

TextChangedEvent

Identifies the TextChanged routed event.

public static readonly RoutedEvent<RoutedEventArgs> TextChangedEvent

Field Value

RoutedEvent<RoutedEventArgs>

Properties

ActiveImage

Gets or sets the image that is displayed in background when the edit is active.

[DataMember]
[Display(null, "Appearance")]
public ISpriteProvider ActiveImage { get; set; }

Property Value

ISpriteProvider

ActualTextSize

Returns the actual size of the text in virtual pixels unit.

public float ActualTextSize { get; }

Property Value

float

Remarks

If TextSize is IsNaN(float), returns the default size of the Font.

See Also

CaretColor

Gets or sets the color of the caret.

[DataMember]
[Display(null, "Appearance")]
public Color CaretColor { get; set; }

Property Value

Color

CaretFrequency

Gets or sets the caret blinking frequency.

[DataMember]
[DataMemberRange(0, 3)]
[Display(null, "Behavior")]
public float CaretFrequency { get; set; }

Property Value

float

Remarks

The value is coerced in the range [0, MaxValue].

CaretPosition

Gets or sets the caret position in the EditText's text.

public int CaretPosition { get; set; }

Property Value

int

CaretWidth

Gets or sets the width of the edit text's cursor (in virtual pixels).

[DataMember]
[DataMemberRange(0, 2)]
[Display(null, "Appearance")]
public float CaretWidth { get; set; }

Property Value

float

Remarks

The value is coerced in the range [0, MaxValue].

CharacterFilterPredicate

Gets or sets the filter used to determine whether the inputed characters are valid or not. Accepted character are characters that the provided predicate function returns true.

public Func<char, bool> CharacterFilterPredicate { get; set; }

Property Value

Func<char, bool>

Remarks

If CharacterFilterPredicate is not set all characters are accepted.

Composition

public string Composition { get; }

Property Value

string

CompositionLength

public int CompositionLength { get; }

Property Value

int

CompositionStart

public int CompositionStart { get; }

Property Value

int

DoNotSnapText

Gets or sets the value indicating if the snapping of the Text of the TextBlock to the closest screen pixel should be skipped.

[DataMember]
[Display(null, "Behavior")]
public bool DoNotSnapText { get; set; }

Property Value

bool

Remarks

When true, the element's text is never snapped. When false, it is snapped only if the font is dynamic and the element is rendered by a SceneUIRenderer.

Font

Gets or sets the font of the text block.

[DataMember]
[Display(null, "Appearance")]
public SpriteFont Font { get; set; }

Property Value

SpriteFont

IMESelectionColor

Gets or sets the color of the IME composition selection.

[DataMember]
[Display(null, "Appearance")]
public Color IMESelectionColor { get; set; }

Property Value

Color

InactiveImage

Gets or sets the image that is displayed in background when the edit is inactive.

[DataMember]
[Display(null, "Appearance")]
public ISpriteProvider InactiveImage { get; set; }

Property Value

ISpriteProvider

InputType

Gets or sets the edit text input type by setting a combination of EditText.InputTypeFlags.

[DataMember]
[Display(null, "Behavior")]
public EditText.InputTypeFlags InputType { get; set; }

Property Value

EditText.InputTypeFlags

IsCaretVisible

Gets the value indicating if the blinking caret is currently visible or not.

public bool IsCaretVisible { get; }

Property Value

bool

IsEnabled

Gets or sets a value indicating whether this element is enabled in the user interface (UI).

public override bool IsEnabled { set; }

Property Value

bool

IsReadOnly

Gets or sets whether the control is read-only, or not.

[DataMember]
[Display(null, "Behavior")]
public bool IsReadOnly { get; set; }

Property Value

bool

IsSelectionActive

Gets a value that indicates whether the text box has focus and selected text.

public bool IsSelectionActive { get; set; }

Property Value

bool

IsTouchedDown

Gets a value that indicates whether the is currently touched down.

protected virtual bool IsTouchedDown { get; set; }

Property Value

bool

LineCount

Gets the total number of lines in the text box.

public int LineCount { get; }

Property Value

int

MaxLength

Gets or sets the maximum number of characters that can be manually entered into the text box.

[DataMember]
[DataMemberRange(1, 0)]
[Display(null, "Behavior")]
public int MaxLength { get; set; }

Property Value

int

Remarks

The value is coerced in the range [1, MaxValue].

MaxLines

Gets or sets the maximum number of visible lines.

[DataMember]
[DataMemberRange(1, 0)]
[Display(null, "Behavior")]
public int MaxLines { get; set; }

Property Value

int

Remarks

The value is coerced in the range [int, MaxValue].

MinLines

Gets or sets the minimum number of visible lines.

[DataMember]
[DataMemberRange(1, 0)]
[Display(null, "Behavior")]
public int MinLines { get; set; }

Property Value

int

Remarks

The value is coerced in the range [1, MaxValue].

MouseOverImage

Gets or sets the image that the button displays when the mouse is over it.

[DataMember]
[Display(null, "Appearance")]
public ISpriteProvider MouseOverImage { get; set; }

Property Value

ISpriteProvider

SelectedText

Gets or sets the content of the current selection in the text box.

public string SelectedText { get; set; }

Property Value

string

Exceptions

ArgumentNullException

The provided string value is null

SelectionColor

Gets or sets the color of the selection.

[DataMember]
[Display(null, "Appearance")]
public Color SelectionColor { get; set; }

Property Value

Color

SelectionLength

Gets or sets a value indicating the number of characters in the current selection in the text box.

public int SelectionLength { get; set; }

Property Value

int

Remarks

If the provided length of the selection is too big, the selection is extended until the end of the current text

SelectionStart

Gets or sets a character index for the beginning of the current selection.

public int SelectionStart { get; set; }

Property Value

int

Remarks

If the provided selection start index is too big, the caret is placed at the end of the current text

ShouldHideText

Gets a value indicating if the text should be hidden when displayed.

protected bool ShouldHideText { get; }

Property Value

bool

SynchronousCharacterGeneration

Gets or sets the value indicating if the text block should generate RuntimeRasterizedSpriteFont characters synchronously or asynchronously.

[DataMember]
public bool SynchronousCharacterGeneration { get; set; }

Property Value

bool

Remarks

If synchronous generation is activated, the game will be block until all the characters have finished to be generate. If asynchronous generation is activated, some characters can appears with one or two frames of delay.

Text

Gets or sets the text content of the text box.

[DataMember]
public string Text { get; set; }

Property Value

string

Remarks

Setting explicitly the text sets the cursor at the end of the new text.

TextAlignment

Gets or sets the alignment of the text to display.

[DataMember]
[Display(null, "Appearance")]
public TextAlignment TextAlignment { get; set; }

Property Value

TextAlignment

TextColor

Gets or sets the color of the text.

[DataMember]
[Display(null, "Appearance")]
public Color TextColor { get; set; }

Property Value

Color

TextSize

Gets or sets the size of the text in virtual pixels unit.

[DataMember]
[DataMemberRange(0, 2)]
[Display(null, "Appearance")]
public float TextSize { get; set; }

Property Value

float

Remarks

The value is coerced in the range [0, MaxValue].

TextToDisplay

The actual text to show into the edit text.

public string TextToDisplay { get; }

Property Value

string

Methods

AppendText(string)

Appends a string to the contents of a text control.

public void AppendText(string textData)

Parameters

textData string

A string that specifies the text to append to the current contents of the text control.

ArrangeOverride(Vector3)

When overridden in a derived class, positions possible child elements and determines a size for a UIElement derived class.

protected override Vector3 ArrangeOverride(Vector3 finalSizeWithoutMargins)

Parameters

finalSizeWithoutMargins Vector3

The final area within the parent that this element should use to arrange itself and its children.

Returns

Vector3

The actual size used.

CalculateTextSize()

Calculate and returns the size of the Text in virtual pixels size.

public Vector2 CalculateTextSize()

Returns

Vector2

The size of the Text in virtual pixels.

CalculateTextSize(string)

Calculate and returns the size of the provided textToMeasure"/> in virtual pixels size.

protected Vector2 CalculateTextSize(string textToMeasure)

Parameters

textToMeasure string

The text to measure

Returns

Vector2

The size of the text in virtual pixels

Clear()

Clears all the content from the text box.

public void Clear()

FindNearestCharacterIndex(Vector2)

Find the index of the nearest character to the provided position.

protected virtual int FindNearestCharacterIndex(Vector2 position)

Parameters

position Vector2

The position in edit text space

Returns

int

The 0-based index of the nearest character

MeasureOverride(Vector3)

When overridden in a derived class, measures the size in layout required for possible child elements and determines a size for the UIElement-derived class.

protected override Vector3 MeasureOverride(Vector3 availableSizeWithoutMargins)

Parameters

availableSizeWithoutMargins Vector3

The available size that this element can give to child elements. Infinity can be specified as a value to indicate that the element will size to whatever content is available.

Returns

Vector3

The size desired by the children

OnIsReadOnlyChanged()

Function triggered when the value of IsReadOnly changed.

protected virtual void OnIsReadOnlyChanged()

OnMaxLengthChanged()

Function triggered when the value of MaxLength changed.

protected virtual void OnMaxLengthChanged()

OnMaxLinesChanged()

Function triggered when the value of MaxLines changed.

protected virtual void OnMaxLinesChanged()

OnMinLinesChanged()

Function triggered when the value of MinLines changed.

protected virtual void OnMinLinesChanged()

OnTextChanged(RoutedEventArgs)

The class handler of the event TextChanged. This method can be overridden in inherited classes to perform actions common to all instances of a class.

protected virtual void OnTextChanged(RoutedEventArgs args)

Parameters

args RoutedEventArgs

The arguments of the event

OnTouchDown(TouchEventArgs)

The class handler of the event TouchDown. This method can be overridden in inherited classes to perform actions common to all instances of a class.

protected override void OnTouchDown(TouchEventArgs args)

Parameters

args TouchEventArgs

The arguments of the event

OnTouchLeave(TouchEventArgs)

The class handler of the event TouchLeave. This method can be overridden in inherited classes to perform actions common to all instances of a class.

protected override void OnTouchLeave(TouchEventArgs args)

Parameters

args TouchEventArgs

The arguments of the event

OnTouchMove(TouchEventArgs)

The class handler of the event TouchMove. This method can be overridden in inherited classes to perform actions common to all instances of a class.

protected override void OnTouchMove(TouchEventArgs args)

Parameters

args TouchEventArgs

The arguments of the event

OnTouchUp(TouchEventArgs)

The class handler of the event TouchUp. This method can be overridden in inherited classes to perform actions common to all instances of a class.

protected override void OnTouchUp(TouchEventArgs args)

Parameters

args TouchEventArgs

The arguments of the event

ResetCaretBlinking()

Reset the caret blinking to initial state (visible).

public void ResetCaretBlinking()

Select(int, int, bool)

Selects a range of text in the text box.

public void Select(int start, int length, bool caretAtBeginning = false)

Parameters

start int

The zero-based character index of the first character in the selection.

length int

The length of the selection, in characters.

caretAtBeginning bool

Indicate if the caret should be at the beginning or the end of the selection

Remarks

If the value of start is too big the caret is positioned at the end of the current text. If the value of length is too big the selection is extended to the end current text.

SelectAll(bool)

Selects all the contents of the text editing control.

public void SelectAll(bool caretAtBeginning = false)

Parameters

caretAtBeginning bool

Indicate if the caret should be at the beginning or the end of the selection

Update(GameTime)

Method called by Update(GameTime). This method can be overridden by inherited classes to perform time-based actions. This method is not in charge to recursively call the update on child elements, this is automatically done.

protected override void Update(GameTime time)

Parameters

time GameTime

The current time of the game

Events

TextChanged

Occurs when the text selection has changed.

public event EventHandler<RoutedEventArgs> TextChanged

Event Type

EventHandler<RoutedEventArgs>

Remarks

A click event is bubbling