EditText Class
Namespace: Stride.UI.ControlsAssembly: 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
Name | Description | |
---|---|---|
Constructors | ||
EditText() | Create a new instance of EditText. |
|
Fields | ||
TextChangedEvent | Identifies the TextChanged routed event. |
|
Properties | ||
ActiveImage | Gets or sets the image that is displayed in background when the edit is active. |
|
ActualTextSize | Returns the actual size of the text in virtual pixels unit. |
|
CaretColor | Gets or sets the color of the caret. |
|
CaretFrequency | Gets or sets the caret blinking frequency. |
|
CaretPosition | Gets or sets the caret position in the EditText's text. |
|
CaretWidth | Gets or sets the width of the edit text's cursor (in virtual pixels). |
|
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 |
|
Composition | ||
CompositionLength | ||
CompositionStart | ||
DoNotSnapText | Gets or sets the value indicating if the snapping of the Text of the TextBlock to the closest screen pixel should be skipped. |
|
Font | Gets or sets the font of the text block. |
|
IMESelectionColor | Gets or sets the color of the IME composition selection. |
|
InactiveImage | Gets or sets the image that is displayed in background when the edit is inactive. |
|
InputType | Gets or sets the edit text input type by setting a combination of EditText.InputTypeFlags. |
|
IsCaretVisible | Gets the value indicating if the blinking caret is currently visible or not. |
|
IsEnabled | ||
IsReadOnly | Gets or sets whether the control is read-only, or not. |
|
IsSelectionActive | Gets a value that indicates whether the text box has focus and selected text. |
|
IsTouchedDown | Gets a value that indicates whether the is currently touched down. |
|
LineCount | Gets the total number of lines in the text box. |
|
MaxLength | Gets or sets the maximum number of characters that can be manually entered into the text box. |
|
MaxLines | Gets or sets the maximum number of visible lines. |
|
MinLines | Gets or sets the minimum number of visible lines. |
|
MouseOverImage | Gets or sets the image that the button displays when the mouse is over it. |
|
SelectedText | Gets or sets the content of the current selection in the text box. |
|
SelectionColor | Gets or sets the color of the selection. |
|
SelectionLength | Gets or sets a value indicating the number of characters in the current selection in the text box. |
|
SelectionStart | Gets or sets a character index for the beginning of the current selection. |
|
ShouldHideText | Gets a value indicating if the text should be hidden when displayed. |
|
SynchronousCharacterGeneration | Gets or sets the value indicating if the text block should generate Stride.Graphics.Font.RuntimeRasterizedSpriteFont characters synchronously or asynchronously. |
|
Text | Gets or sets the text content of the text box. |
|
TextAlignment | Gets or sets the alignment of the text to display. |
|
TextColor | Gets or sets the color of the text. |
|
TextSize | Gets or sets the size of the text in virtual pixels unit. |
|
TextToDisplay | The actual text to show into the edit text. |
|
Methods | ||
AppendText(String) | Appends a string to the contents of a text control. |
|
ArrangeOverride(Vector3) | ||
CalculateTextSize() | Calculate and returns the size of the Text in virtual pixels size. |
|
CalculateTextSize(String) | Calculate and returns the size of the provided |
|
Clear() | Clears all the content from the text box. |
|
FindNearestCharacterIndex(Vector2) | Find the index of the nearest character to the provided position. |
|
MeasureOverride(Vector3) | ||
OnIsReadOnlyChanged() | Function triggered when the value of IsReadOnly changed. |
|
OnMaxLengthChanged() | Function triggered when the value of MaxLength changed. |
|
OnMaxLinesChanged() | Function triggered when the value of MaxLines changed. |
|
OnMinLinesChanged() | Function triggered when the value of MinLines changed. |
|
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. |
|
OnTouchDown(TouchEventArgs) | ||
OnTouchLeave(TouchEventArgs) | ||
OnTouchMove(TouchEventArgs) | ||
OnTouchUp(TouchEventArgs) | ||
ResetCaretBlinking() | Reset the caret blinking to initial state (visible). |
|
Select(Int32, Int32, Boolean) | Selects a range of text in the text box. |
|
SelectAll(Boolean) | Selects all the contents of the text editing control. |
|
Update(GameTime) | ||
Events | ||
TextChanged | Occurs when the text selection has changed. |
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
Type | Description |
---|---|
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
Type | Description |
---|---|
ISpriteProvider |
ActualTextSize
Returns the actual size of the text in virtual pixels unit.
public float ActualTextSize { get; }
Property Value
Type | Description |
---|---|
System.Single |
Remarks
See Also
CaretColor
Gets or sets the color of the caret.
[DataMember]
[Display(null, "Appearance")]
public Color CaretColor { get; set; }
Property Value
Type | Description |
---|---|
Color |
CaretFrequency
Gets or sets the caret blinking frequency.
[DataMember]
[DataMemberRange(0, 3)]
[Display(null, "Behavior")]
public float CaretFrequency { get; set; }
Property Value
Type | Description |
---|---|
System.Single |
Remarks
The value is coerced in the range [0, System.Single.MaxValue].
CaretPosition
Gets or sets the caret position in the EditText's text.
public int CaretPosition { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
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
Type | Description |
---|---|
System.Single |
Remarks
The value is coerced in the range [0, System.Single.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
public Func<char, bool> CharacterFilterPredicate { get; set; }
Property Value
Type | Description |
---|---|
System.Func<System.Char, System.Boolean> |
Remarks
If CharacterFilterPredicate is not set all characters are accepted.
Composition
public string Composition { get; }
Property Value
Type | Description |
---|---|
System.String |
CompositionLength
public int CompositionLength { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
CompositionStart
public int CompositionStart { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
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
Type | Description |
---|---|
System.Boolean |
Remarks
When
Font
Gets or sets the font of the text block.
[DataMember]
[Display(null, "Appearance")]
public SpriteFont Font { get; set; }
Property Value
Type | Description |
---|---|
SpriteFont |
IMESelectionColor
Gets or sets the color of the IME composition selection.
[DataMember]
[Display(null, "Appearance")]
public Color IMESelectionColor { get; set; }
Property Value
Type | Description |
---|---|
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
Type | Description |
---|---|
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
Type | Description |
---|---|
EditText.InputTypeFlags |
IsCaretVisible
Gets the value indicating if the blinking caret is currently visible or not.
public bool IsCaretVisible { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsEnabled
public override bool IsEnabled { set; }
Property Value
Type | Description |
---|---|
System.Boolean |
Overrides
IsReadOnly
Gets or sets whether the control is read-only, or not.
[DataMember]
[Display(null, "Behavior")]
public bool IsReadOnly { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsSelectionActive
Gets a value that indicates whether the text box has focus and selected text.
public bool IsSelectionActive { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsTouchedDown
Gets a value that indicates whether the is currently touched down.
protected virtual bool IsTouchedDown { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
LineCount
Gets the total number of lines in the text box.
public int LineCount { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
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
Type | Description |
---|---|
System.Int32 |
Remarks
The value is coerced in the range [1, System.Int32.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
Type | Description |
---|---|
System.Int32 |
Remarks
The value is coerced in the range [int, System.Int32.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
Type | Description |
---|---|
System.Int32 |
Remarks
The value is coerced in the range [1, System.Int32.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
Type | Description |
---|---|
ISpriteProvider |
SelectedText
Gets or sets the content of the current selection in the text box.
public string SelectedText { get; set; }
Property Value
Type | Description |
---|---|
System.String |
Exceptions
Type | Condition |
---|---|
System.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
Type | Description |
---|---|
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
Type | Description |
---|---|
System.Int32 |
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
Type | Description |
---|---|
System.Int32 |
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
Type | Description |
---|---|
System.Boolean |
SynchronousCharacterGeneration
Gets or sets the value indicating if the text block should generate Stride.Graphics.Font.RuntimeRasterizedSpriteFont characters synchronously or asynchronously.
[DataMember]
public bool SynchronousCharacterGeneration { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
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
Type | Description |
---|---|
System.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
Type | Description |
---|---|
TextAlignment |
TextColor
Gets or sets the color of the text.
[DataMember]
[Display(null, "Appearance")]
public Color TextColor { get; set; }
Property Value
Type | Description |
---|---|
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
Type | Description |
---|---|
System.Single |
Remarks
The value is coerced in the range [0, System.Single.MaxValue].
TextToDisplay
The actual text to show into the edit text.
public string TextToDisplay { get; }
Property Value
Type | Description |
---|---|
System.String |
Methods
AppendText(String)
Appends a string to the contents of a text control.
public void AppendText(string textData)
Parameters
Type | Name | Description |
---|---|---|
System.String | textData | A string that specifies the text to append to the current contents of the text control. |
ArrangeOverride(Vector3)
protected override Vector3 ArrangeOverride(Vector3 finalSizeWithoutMargins)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | finalSizeWithoutMargins |
Returns
Type | Description |
---|---|
Vector3 |
Overrides
CalculateTextSize()
Calculate and returns the size of the Text in virtual pixels size.
public Vector2 CalculateTextSize()
Returns
Type | Description |
---|---|
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
Type | Name | Description |
---|---|---|
System.String | textToMeasure | The text to measure |
Returns
Type | Description |
---|---|
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
Type | Name | Description |
---|---|---|
Vector2 | position | The position in edit text space |
Returns
Type | Description |
---|---|
System.Int32 | The 0-based index of the nearest character |
MeasureOverride(Vector3)
protected override Vector3 MeasureOverride(Vector3 availableSizeWithoutMargins)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | availableSizeWithoutMargins |
Returns
Type | Description |
---|---|
Vector3 |
Overrides
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
Type | Name | Description |
---|---|---|
RoutedEventArgs | args | The arguments of the event |
OnTouchDown(TouchEventArgs)
protected override void OnTouchDown(TouchEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
TouchEventArgs | args |
Overrides
OnTouchLeave(TouchEventArgs)
protected override void OnTouchLeave(TouchEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
TouchEventArgs | args |
Overrides
OnTouchMove(TouchEventArgs)
protected override void OnTouchMove(TouchEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
TouchEventArgs | args |
Overrides
OnTouchUp(TouchEventArgs)
protected override void OnTouchUp(TouchEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
TouchEventArgs | args |
Overrides
ResetCaretBlinking()
Reset the caret blinking to initial state (visible).
public void ResetCaretBlinking()
Select(Int32, Int32, Boolean)
Selects a range of text in the text box.
public void Select(int start, int length, bool caretAtBeginning = false)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | start | The zero-based character index of the first character in the selection. |
System.Int32 | length | The length of the selection, in characters. |
System.Boolean | caretAtBeginning | 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(Boolean)
Selects all the contents of the text editing control.
public void SelectAll(bool caretAtBeginning = false)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | caretAtBeginning | Indicate if the caret should be at the beginning or the end of the selection |
Update(GameTime)
protected override void Update(GameTime time)
Parameters
Type | Name | Description |
---|---|---|
GameTime | time |
Overrides
| Improve this Doc View SourceEvents
TextChanged
Occurs when the text selection has changed.
public event EventHandler<RoutedEventArgs> TextChanged
Event Type
Type | Description |
---|---|
System.EventHandler<RoutedEventArgs> |
Remarks
A click event is bubbling