Class TextBoxBase
Base class for all text box controls which can gather text input from the user.
Implements
Namespace: FlaxEngine.GUI
Assembly: FlaxEngine.CSharp.dll
Syntax
public abstract class TextBoxBase : ContainerControl, IComparable, IDrawable
Constructors
TextBoxBase()
TextBoxBase(Boolean, Single, Single, Single)
Initializes a new instance of the TextBoxBase class.
Declaration
protected TextBoxBase(bool isMultiline, float x, float y, float width = 120F)
Parameters
System.Boolean
isMultiline
Enable/disable multiline text input support. |
System.Single
x
The control position X coordinate. |
System.Single
y
The control position Y coordinate. |
System.Single
width
The control width. |
Fields
_animateTime
The animate time for selection.
Declaration
protected float _animateTime
Field Value
System.Single
|
_changeCursor
If the cursor should change to an IBeam
Declaration
protected bool _changeCursor
Field Value
System.Boolean
|
_isEditing
Flag used to indicate whenever user is editing the text.
Declaration
protected bool _isEditing
Field Value
System.Boolean
|
_isMultiline
Flag used to indicate whenever text can contain multiple lines.
Declaration
protected bool _isMultiline
Field Value
System.Boolean
|
_isReadOnly
Flag used to indicate whenever text is read-only and cannot be modified by the user.
Declaration
protected bool _isReadOnly
Field Value
System.Boolean
|
_isSelectable
Flag used to indicate whenever text is selectable.
Declaration
protected bool _isSelectable
Field Value
System.Boolean
|
_isSelecting
Flag used to indicate whenever user is selecting text.
Declaration
protected bool _isSelecting
Field Value
System.Boolean
|
_maxLength
The maximum length of the text.
Declaration
protected int _maxLength
Field Value
System.Int32
|
_onStartEditValue
The text value captured when user started editing text. Used to detect content modification.
Declaration
protected string _onStartEditValue
Field Value
System.String
|
_selectionEnd
The selection end position (character index).
Declaration
protected int _selectionEnd
Field Value
System.Int32
|
_selectionStart
The selection start position (character index).
Declaration
protected int _selectionStart
Field Value
System.Int32
|
_targetViewOffset
_text
The current text value.
Declaration
protected string _text
Field Value
System.String
|
_textSize
_viewOffset
DefaultHeight
Default height of the text box
Declaration
public static float DefaultHeight
Field Value
System.Single
|
DefaultMargin
Left and right margin for text inside the text box bounds rectangle
Declaration
public static float DefaultMargin
Field Value
System.Single
|
DelChar
The delete control character (used for text filtering).
Declaration
protected const char DelChar = '\u007f'
Field Value
System.Char
|
Separators
The text separators (used for words skipping).
Declaration
protected static readonly char[] Separators
Field Value
System.Char[]
|
Properties
BackgroundSelectedColor
Gets or sets textbox background color when the control is selected (has focus).
Declaration
[EditorDisplay("Background Style", null)]
[EditorOrder(2001)]
[Tooltip("The textbox background color when the control is selected (has focus).")]
[ExpandGroups]
public Color BackgroundSelectedColor { get; set; }
Property Value
Color
|
BackgroundSelectedFlashSpeed
Gets or sets the speed of the selection background flashing animation.
Declaration
[EditorDisplay("Background Style", null)]
[EditorOrder(2002)]
[Tooltip("The speed of the selection background flashing animation.")]
public float BackgroundSelectedFlashSpeed { get; set; }
Property Value
System.Single
|
BorderColor
Gets or sets the color of the border (Transparent if not used).
Declaration
[EditorDisplay("Border Style", null)]
[EditorOrder(2012)]
[Tooltip("The color of the border (Transparent if not used).")]
public Color BorderColor { get; set; }
Property Value
Color
|
BorderSelectedColor
Gets or sets the color of the border when control is focused (Transparent if not used).
Declaration
[EditorDisplay("Border Style", null)]
[EditorOrder(2013)]
[Tooltip("The color of the border when control is focused (Transparent if not used)")]
public Color BorderSelectedColor { get; set; }
Property Value
Color
|
BorderThickness
Gets or sets the border thickness.
Declaration
[EditorDisplay("Border Style", null)]
[EditorOrder(2011)]
[Tooltip("The thickness of the border.")]
[Limit(0F, 3.40282347E+38F, 1F)]
public float BorderThickness { get; set; }
Property Value
System.Single
|
CaretBounds
Calculates the caret rectangle.
Declaration
protected Rectangle CaretBounds { get; }
Property Value
Rectangle
|
CaretColor
Gets or sets the color of the caret (Transparent if not used).
Declaration
[EditorDisplay("Caret Style", null)]
[EditorOrder(2020)]
[Tooltip("The color of the caret (Transparent if not used).")]
[ExpandGroups]
public Color CaretColor { get; set; }
Property Value
Color
|
CaretFlashSpeed
Gets or sets the speed of the caret flashing animation.
Declaration
[EditorDisplay("Caret Style", null)]
[EditorOrder(2021)]
[Tooltip("The speed of the caret flashing animation.")]
public float CaretFlashSpeed { get; set; }
Property Value
System.Single
|
CaretPosition
Gets current caret position (index of the character)
Declaration
protected int CaretPosition { get; }
Property Value
System.Int32
|
ClipText
Gets or sets a value indicating whether apply clipping mask on text during rendering.
Declaration
[EditorOrder(529)]
public bool ClipText { get; set; }
Property Value
System.Boolean
|
HasBorder
Gets or sets whether to have a border.
Declaration
[EditorDisplay("Border Style", null)]
[EditorOrder(2010)]
[Tooltip("Whether to have a border.")]
[ExpandGroups]
public bool HasBorder { get; set; }
Property Value
System.Boolean
|
HasSelection
Returns true if any text is selected, otherwise false
Declaration
public bool HasSelection { get; }
Property Value
System.Boolean
|
IsEditing
Gets a value indicating whether user is editing the text.
Declaration
public bool IsEditing { get; }
Property Value
System.Boolean
|
IsMultiline
Gets or sets a value indicating whether this is a multiline text box control.
Declaration
[EditorOrder(40)]
[Tooltip("If checked, the textbox will support multiline text input.")]
public bool IsMultiline { get; set; }
Property Value
System.Boolean
|
IsMultilineScrollable
Gets or sets a value indicating whether you can scroll the text in the text box (eg. with a mouse wheel).
Declaration
[EditorOrder(41)]
public bool IsMultilineScrollable { get; set; }
Property Value
System.Boolean
|
IsReadOnly
Gets or sets a value indicating whether text in the text box is read-only.
Declaration
[EditorOrder(60)]
[Tooltip("If checked, text in the text box is read-only.")]
public bool IsReadOnly { get; set; }
Property Value
System.Boolean
|
IsSelectable
Gets or sets a value indicating whether text can be selected in text box.
Declaration
[EditorOrder(62)]
[Tooltip("If checked, text can be selected in text box.")]
public bool IsSelectable { get; set; }
Property Value
System.Boolean
|
MaxLength
Gets or sets the maximum number of characters the user can type into the text box control.
Declaration
[EditorOrder(50)]
[Tooltip("The maximum number of characters the user can type into the text box control.")]
public int MaxLength { get; set; }
Property Value
System.Int32
|
SelectedText
Gets the currently selected text in the control.
Declaration
public string SelectedText { get; }
Property Value
System.String
|
SelectionLeft
Index of the character on left edge of the selection
Declaration
protected int SelectionLeft { get; }
Property Value
System.Int32
|
SelectionLength
Gets the number of characters selected in the text box.
Declaration
public int SelectionLength { get; }
Property Value
System.Int32
|
SelectionRange
Gets or sets the selection range.
Declaration
[EditorOrder(50)]
public TextRange SelectionRange { get; set; }
Property Value
TextRange
|
SelectionRight
Index of the character on right edge of the selection
Declaration
protected int SelectionRight { get; }
Property Value
System.Int32
|
Text
Gets or sets text property.
Declaration
[EditorOrder(0)]
[MultilineText]
[Tooltip("The entered text.")]
public string Text { get; set; }
Property Value
System.String
|
TextClipRectangle
Gets rectangle used to clip text
Declaration
protected virtual Rectangle TextClipRectangle { get; }
Property Value
Rectangle
|
TextLength
Gets length of the text
Declaration
public int TextLength { get; }
Property Value
System.Int32
|
TextRectangle
Gets rectangle with area for text
Declaration
protected virtual Rectangle TextRectangle { get; }
Property Value
Rectangle
|
TextSize
Gets the size of the text (cached).
Declaration
public Float2 TextSize { get; }
Property Value
Float2
|
ViewOffset
Gets the current view offset (text scrolling offset). Includes the smoothing.
Declaration
public Float2 ViewOffset { get; }
Property Value
Float2
|
Methods
CharIndexAtPoint(ref Float2)
Gets the character the index at point (eg. mouse location in control-space).
Declaration
public virtual int CharIndexAtPoint(ref Float2 location)
Parameters
Float2
location
The location (in control-space). |
Returns
System.Int32
The character index under the location |
Clear()
Clears all text from the text box control.
Declaration
public virtual void Clear()
ClearSelection()
Clear selection range
Declaration
public virtual void ClearSelection()
Copy()
Copies the current selection in the text box to the Clipboard.
Declaration
public virtual void Copy()
Cut()
Moves the current selection in the text box to the Clipboard.
Declaration
public virtual void Cut()
Deselect()
Sets the selection to empty value.
Declaration
public virtual void Deselect()
Duplicate()
Duplicates the current selection in the text box.
Declaration
public virtual void Duplicate()
GetCharPosition(Int32, out Single)
Calculates character position for given character index.
Declaration
public abstract Float2 GetCharPosition(int index, out float height)
Parameters
System.Int32
index
The text position to get it's coordinates. |
System.Single
height
The character height (at the given character position). |
Returns
Float2
The character position (upper left corner which can be used for a caret position). |
GetTextSize()
Calculates total text size. Called by OnTextChanged() to cache the text size.
Declaration
public abstract Float2 GetTextSize()
Returns
Float2
The total text size. |
HitTestText(Float2)
Calculates hit character index at given location.
Declaration
public abstract int HitTestText(Float2 location)
Parameters
Float2
location
The location to test. |
Returns
System.Int32
The selected character position index (can be equal to text length if location is outside of the layout rectangle). |
Insert(Char)
Inserts the specified character (at the current selection).
Declaration
public virtual void Insert(char c)
Parameters
System.Char
c
The character. |
Insert(String)
Inserts the specified text (at the current selection).
Declaration
public virtual void Insert(string str)
Parameters
System.String
str
The string. |
MoveDown(Boolean, Boolean)
Moves the caret down.
Declaration
protected virtual void MoveDown(bool shift, bool ctrl)
Parameters
System.Boolean
shift
Shift is held. |
System.Boolean
ctrl
Control is held. |
MoveLeft(Boolean, Boolean)
Moves the caret left.
Declaration
protected virtual void MoveLeft(bool shift, bool ctrl)
Parameters
System.Boolean
shift
Shift is held. |
System.Boolean
ctrl
Control is held. |
MoveRight(Boolean, Boolean)
Moves the caret right.
Declaration
protected virtual void MoveRight(bool shift, bool ctrl)
Parameters
System.Boolean
shift
Shift is held. |
System.Boolean
ctrl
Control is held. |
MoveUp(Boolean, Boolean)
Moves the caret up.
Declaration
protected virtual void MoveUp(bool shift, bool ctrl)
Parameters
System.Boolean
shift
Shift is held. |
System.Boolean
ctrl
Control is held. |
NavigationFocus()
OnCharInput(Char)
On input character
Declaration
public override bool OnCharInput(char c)
Parameters
System.Char
c
Input character |
Returns
System.Boolean
True if event has been handled, otherwise false |
Overrides
OnEditBegin()
Action called when user starts text editing
Declaration
protected virtual void OnEditBegin()
OnEditEnd()
Action called when user ends text editing.
Declaration
protected virtual void OnEditEnd()
OnEndMouseCapture()
When mouse goes up/down not over the control but it has user focus so remove that focus from it (used by scroll bars, sliders etc.)
Declaration
public override void OnEndMouseCapture()
Overrides
OnGotFocus()
When control gets input focus
Declaration
public override void OnGotFocus()
Overrides
OnIsMultilineChanged()
Called when is multiline gets changed.
Declaration
protected virtual void OnIsMultilineChanged()
OnIsReadOnlyChanged()
Called when is read only gets changed.
Declaration
protected virtual void OnIsReadOnlyChanged()
OnIsSelectableChanged()
Called when is selectable flag gets changed.
Declaration
protected virtual void OnIsSelectableChanged()
OnKeyDown(KeyboardKeys)
When key goes down
Declaration
public override bool OnKeyDown(KeyboardKeys key)
Parameters
KeyboardKeys
key
Key value |
Returns
System.Boolean
True if event has been handled, otherwise false |
Overrides
OnKeyUp(KeyboardKeys)
When key goes up
Declaration
public override void OnKeyUp(KeyboardKeys key)
Parameters
KeyboardKeys
key
Key value |
Overrides
OnLostFocus()
When control losts input focus
Declaration
public override void OnLostFocus()
Overrides
OnMouseDown(Float2, MouseButton)
When mouse goes down over control's area
Declaration
public override bool OnMouseDown(Float2 location, MouseButton button)
Parameters
Float2
location
Mouse location in Control Space |
MouseButton
button
Mouse buttons state (flags) |
Returns
System.Boolean
True if event has been handled, otherwise false |
Overrides
OnMouseEnter(Float2)
When mouse enters control's area
Declaration
public override void OnMouseEnter(Float2 location)
Parameters
Float2
location
Mouse location in Control Space |
Overrides
OnMouseLeave()
When mouse leaves control's area
Declaration
public override void OnMouseLeave()
Overrides
OnMouseMove(Float2)
When mouse moves over control's area
Declaration
public override void OnMouseMove(Float2 location)
Parameters
Float2
location
Mouse location in Control Space |
Overrides
OnMouseUp(Float2, MouseButton)
When mouse goes up over control's area
Declaration
public override bool OnMouseUp(Float2 location, MouseButton button)
Parameters
Float2
location
Mouse location in Control Space |
MouseButton
button
Mouse buttons state (flags) |
Returns
System.Boolean
True if event has been handled, otherwise false |
Overrides
OnMouseWheel(Float2, Single)
When mouse wheel moves
Declaration
public override bool OnMouseWheel(Float2 location, float delta)
Parameters
Float2
location
Mouse location in Control Space |
System.Single
delta
Mouse wheel move delta. A positive value indicates that the wheel was rotated forward, away from the user; a negative value indicates that the wheel was rotated backward, toward the user. Normalized to [-1;1] range. |
Returns
System.Boolean
True if event has been handled |
Overrides
OnSelectingBegin()
Action called when user starts text selecting
Declaration
protected virtual void OnSelectingBegin()
OnSelectingEnd()
Action called when user ends text selecting
Declaration
protected virtual void OnSelectingEnd()
OnSubmit()
Generic user interaction event for a control used by UI navigation (eg. user submits on the currently focused control).
Declaration
public override void OnSubmit()
Overrides
OnTargetViewOffsetChanged()
Called when target view offset gets changed.
Declaration
protected virtual void OnTargetViewOffsetChanged()
OnTextChanged()
Action called when text gets modified.
Declaration
protected virtual void OnTextChanged()
Paste()
Replaces the current selection in the text box with the contents of the Clipboard.
Declaration
public virtual void Paste()
ResetViewOffset()
Resets the view offset (text scroll view).
Declaration
public virtual void ResetViewOffset()
RestoreTextFromStart()
Restores the Text from the start.
Declaration
public void RestoreTextFromStart()
ScrollToCaret()
Ensures that the caret is visible in the TextBox window, by scrolling the TextBox control surface if necessary.
Declaration
public virtual void ScrollToCaret()
SelectAll()
Selects all text in the text box.
Declaration
public virtual void SelectAll()
SetSelection(Int32, Boolean)
Sets the caret position.
Declaration
protected virtual void SetSelection(int caret, bool withScroll = true)
Parameters
System.Int32
caret
The caret position. |
System.Boolean
withScroll
If set to |
SetSelection(Int32, Int32, Boolean)
Sets the selection.
Declaration
protected virtual void SetSelection(int start, int end, bool withScroll = true)
Parameters
System.Int32
start
The selection start character. |
System.Int32
end
The selection end character. |
System.Boolean
withScroll
If set to |
SetText(String)
Sets the text (forced, even if user is editing it).
Declaration
[NoAnimate]
public void SetText(string value)
Parameters
System.String
value
The value. |
SetTextAsUser(String)
Sets the text as it was entered by user (focus, change value, defocus).
Declaration
[NoAnimate]
public void SetTextAsUser(string value)
Parameters
System.String
value
The value. |
Update(Single)
Perform control update and all its children
Declaration
public override void Update(float deltaTime)
Parameters
System.Single
deltaTime
Delta time in seconds |
Overrides
Events
EditEnd
Event fired when text gets changed after editing (user accepted entered value).
Declaration
public event Action EditEnd
Event Type
System.Action
|
KeyDown
Event fired when a key is down.
Declaration
public event Action<KeyboardKeys> KeyDown
Event Type
System.Action<KeyboardKeys>
|
KeyUp
Event fired when a key is up.
Declaration
public event Action<KeyboardKeys> KeyUp
Event Type
System.Action<KeyboardKeys>
|
TargetViewOffsetChanged
Occurs when target view offset gets changed.
Declaration
public event Action TargetViewOffsetChanged
Event Type
System.Action
|
TextBoxEditEnd
Event fired when text gets changed after editing (user accepted entered value).
Declaration
public event Action<TextBoxBase> TextBoxEditEnd
Event Type
System.Action<TextBoxBase>
|
TextChanged
Event fired when text gets changed
Declaration
public event Action TextChanged
Event Type
System.Action
|