Allow overriding most of the methods in TextBoxBase

This commit is contained in:
Ari Vuollet
2021-02-20 23:07:21 +02:00
parent 09be8994e9
commit e2590b5f11
2 changed files with 40 additions and 20 deletions

View File

@@ -61,7 +61,7 @@ namespace FlaxEngine.GUI
/// <summary> /// <summary>
/// Updates the text blocks. /// Updates the text blocks.
/// </summary> /// </summary>
protected void UpdateTextBlocks() protected virtual void UpdateTextBlocks()
{ {
Profiler.BeginEvent("RichTextBoxBase.UpdateTextBlocks"); Profiler.BeginEvent("RichTextBoxBase.UpdateTextBlocks");

View File

@@ -422,7 +422,7 @@ namespace FlaxEngine.GUI
/// <summary> /// <summary>
/// Clears all text from the text box control. /// Clears all text from the text box control.
/// </summary> /// </summary>
public void Clear() public virtual void Clear()
{ {
Text = string.Empty; Text = string.Empty;
} }
@@ -430,7 +430,7 @@ namespace FlaxEngine.GUI
/// <summary> /// <summary>
/// Clear selection range /// Clear selection range
/// </summary> /// </summary>
public void ClearSelection() public virtual void ClearSelection()
{ {
OnSelectingEnd(); OnSelectingEnd();
SetSelection(-1); SetSelection(-1);
@@ -439,7 +439,7 @@ namespace FlaxEngine.GUI
/// <summary> /// <summary>
/// Resets the view offset (text scroll view). /// Resets the view offset (text scroll view).
/// </summary> /// </summary>
public void ResetViewOffset() public virtual void ResetViewOffset()
{ {
TargetViewOffset = Vector2.Zero; TargetViewOffset = Vector2.Zero;
} }
@@ -455,7 +455,7 @@ namespace FlaxEngine.GUI
/// <summary> /// <summary>
/// Copies the current selection in the text box to the Clipboard. /// Copies the current selection in the text box to the Clipboard.
/// </summary> /// </summary>
public void Copy() public virtual void Copy()
{ {
var selectedText = SelectedText; var selectedText = SelectedText;
if (selectedText.Length > 0) if (selectedText.Length > 0)
@@ -468,7 +468,7 @@ namespace FlaxEngine.GUI
/// <summary> /// <summary>
/// Moves the current selection in the text box to the Clipboard. /// Moves the current selection in the text box to the Clipboard.
/// </summary> /// </summary>
public void Cut() public virtual void Cut()
{ {
var selectedText = SelectedText; var selectedText = SelectedText;
if (selectedText.Length > 0) if (selectedText.Length > 0)
@@ -490,7 +490,7 @@ namespace FlaxEngine.GUI
/// <summary> /// <summary>
/// Replaces the current selection in the text box with the contents of the Clipboard. /// Replaces the current selection in the text box with the contents of the Clipboard.
/// </summary> /// </summary>
public void Paste() public virtual void Paste()
{ {
if (IsReadOnly) if (IsReadOnly)
return; return;
@@ -508,7 +508,7 @@ namespace FlaxEngine.GUI
/// <summary> /// <summary>
/// Duplicates the current selection in the text box. /// Duplicates the current selection in the text box.
/// </summary> /// </summary>
public void Duplicate() public virtual void Duplicate()
{ {
if (IsReadOnly) if (IsReadOnly)
return; return;
@@ -526,7 +526,7 @@ namespace FlaxEngine.GUI
/// <summary> /// <summary>
/// Ensures that the caret is visible in the TextBox window, by scrolling the TextBox control surface if necessary. /// Ensures that the caret is visible in the TextBox window, by scrolling the TextBox control surface if necessary.
/// </summary> /// </summary>
public void ScrollToCaret() public virtual void ScrollToCaret()
{ {
// If it's empty // If it's empty
if (_text.Length == 0) if (_text.Length == 0)
@@ -547,7 +547,7 @@ namespace FlaxEngine.GUI
/// <summary> /// <summary>
/// Selects all text in the text box. /// Selects all text in the text box.
/// </summary> /// </summary>
public void SelectAll() public virtual void SelectAll()
{ {
if (TextLength > 0) if (TextLength > 0)
{ {
@@ -558,7 +558,7 @@ namespace FlaxEngine.GUI
/// <summary> /// <summary>
/// Sets the selection to empty value. /// Sets the selection to empty value.
/// </summary> /// </summary>
public void Deselect() public virtual void Deselect()
{ {
SetSelection(-1); SetSelection(-1);
} }
@@ -568,7 +568,7 @@ namespace FlaxEngine.GUI
/// </summary> /// </summary>
/// <param name="location">The location (in control-space).</param> /// <param name="location">The location (in control-space).</param>
/// <returns>The character index under the location</returns> /// <returns>The character index under the location</returns>
public int CharIndexAtPoint(ref Vector2 location) public virtual int CharIndexAtPoint(ref Vector2 location)
{ {
return HitTestText(location + _viewOffset); return HitTestText(location + _viewOffset);
} }
@@ -577,7 +577,7 @@ namespace FlaxEngine.GUI
/// Inserts the specified character (at the current selection). /// Inserts the specified character (at the current selection).
/// </summary> /// </summary>
/// <param name="c">The character.</param> /// <param name="c">The character.</param>
public void Insert(char c) public virtual void Insert(char c)
{ {
Insert(c.ToString()); Insert(c.ToString());
} }
@@ -586,7 +586,7 @@ namespace FlaxEngine.GUI
/// Inserts the specified text (at the current selection). /// Inserts the specified text (at the current selection).
/// </summary> /// </summary>
/// <param name="str">The string.</param> /// <param name="str">The string.</param>
public void Insert(string str) public virtual void Insert(string str)
{ {
if (IsReadOnly) if (IsReadOnly)
return; return;
@@ -622,7 +622,12 @@ namespace FlaxEngine.GUI
OnTextChanged(); OnTextChanged();
} }
private void MoveRight(bool shift, bool ctrl) /// <summary>
/// Moves the caret right.
/// </summary>
/// <param name="shift">Shift is held.</param>
/// <param name="ctrl">Control is held.</param>
protected virtual void MoveRight(bool shift, bool ctrl)
{ {
if (HasSelection && !shift) if (HasSelection && !shift)
{ {
@@ -647,7 +652,12 @@ namespace FlaxEngine.GUI
} }
} }
private void MoveLeft(bool shift, bool ctrl) /// <summary>
/// Moves the caret left.
/// </summary>
/// <param name="shift">Shift is held.</param>
/// <param name="ctrl">Control is held.</param>
protected virtual void MoveLeft(bool shift, bool ctrl)
{ {
if (HasSelection && !shift) if (HasSelection && !shift)
{ {
@@ -672,7 +682,12 @@ namespace FlaxEngine.GUI
} }
} }
private void MoveDown(bool shift, bool ctrl) /// <summary>
/// Moves the caret down.
/// </summary>
/// <param name="shift">Shift is held.</param>
/// <param name="ctrl">Control is held.</param>
protected virtual void MoveDown(bool shift, bool ctrl)
{ {
if (HasSelection && !shift) if (HasSelection && !shift)
{ {
@@ -693,7 +708,12 @@ namespace FlaxEngine.GUI
} }
} }
private void MoveUp(bool shift, bool ctrl) /// <summary>
/// Moves the caret up.
/// </summary>
/// <param name="shift">Shift is held.</param>
/// <param name="ctrl">Control is held.</param>
protected virtual void MoveUp(bool shift, bool ctrl)
{ {
if (HasSelection && !shift) if (HasSelection && !shift)
{ {
@@ -719,7 +739,7 @@ namespace FlaxEngine.GUI
/// </summary> /// </summary>
/// <param name="caret">The caret position.</param> /// <param name="caret">The caret position.</param>
/// <param name="withScroll">If set to <c>true</c> with auto-scroll.</param> /// <param name="withScroll">If set to <c>true</c> with auto-scroll.</param>
protected void SetSelection(int caret, bool withScroll = true) protected virtual void SetSelection(int caret, bool withScroll = true)
{ {
SetSelection(caret, caret); SetSelection(caret, caret);
} }
@@ -730,7 +750,7 @@ namespace FlaxEngine.GUI
/// <param name="start">The selection start character.</param> /// <param name="start">The selection start character.</param>
/// <param name="end">The selection end character.</param> /// <param name="end">The selection end character.</param>
/// <param name="withScroll">If set to <c>true</c> with auto-scroll.</param> /// <param name="withScroll">If set to <c>true</c> with auto-scroll.</param>
protected void SetSelection(int start, int end, bool withScroll = true) protected virtual void SetSelection(int start, int end, bool withScroll = true)
{ {
// Update parameters // Update parameters
int textLength = _text.Length; int textLength = _text.Length;