Added RstoreTextFromStart function and changed the calls. Renamed bool.

This commit is contained in:
Chandler Cox
2022-12-08 08:02:43 -06:00
parent 9b82860154
commit eab775b9a2
3 changed files with 19 additions and 14 deletions

View File

@@ -371,7 +371,7 @@ namespace FlaxEditor.GUI.Input
Parent = this,
Location = new Float2(split, 0),
Size = new Float2(Height, TextBoxSize),
CanEndEditByClick = true,
EndEditOnClick = true,
};
_textBox.EditEnd += OnTextBoxEditEnd;
}

View File

@@ -125,7 +125,7 @@ namespace FlaxEditor.GUI.Input
_min = min;
_max = max;
_slideSpeed = sliderSpeed;
CanEndEditByClick = true;
EndEditOnClick = true;
}
/// <summary>
@@ -174,7 +174,7 @@ namespace FlaxEditor.GUI.Input
private void EndSliding()
{
_isSliding = false;
CanEndEditByClick = true;
EndEditOnClick = true;
EndMouseCapture();
if (_cursorChanged)
{
@@ -247,7 +247,7 @@ namespace FlaxEditor.GUI.Input
_startSlideLocation = location;
_startSlideValue = _value;
StartMouseCapture(true);
CanEndEditByClick = false;
EndEditOnClick = false;
// Hide cursor and cache location
Cursor = CursorType.Hidden;

View File

@@ -143,7 +143,7 @@ namespace FlaxEngine.GUI
/// Gets or sets a value indicating whether the text box can end edit via left click outside of the control
/// </summary>
[HideInEditor]
public bool CanEndEditByClick { get; set; } = false;
public bool EndEditOnClick { get; set; } = false;
/// <summary>
/// Gets or sets a value indicating whether this is a multiline text box control.
@@ -1049,7 +1049,7 @@ namespace FlaxEngine.GUI
_viewOffset = isDeltaSlow ? _targetViewOffset : Float2.Lerp(_viewOffset, _targetViewOffset, deltaTime * 20.0f);
// Clicking outside of the text box will end text editing. Left will keep the value, right will restore original value
if (_isEditing && CanEndEditByClick)
if (_isEditing && EndEditOnClick)
{
if (!IsMouseOver && RootWindow.ContainsFocus)
{
@@ -1059,10 +1059,7 @@ namespace FlaxEngine.GUI
}
else if (Input.GetMouseButtonDown(MouseButton.Right))
{
// Restore text from start
SetSelection(-1);
_text = _onStartEditValue;
OnTextChanged();
RestoreTextFromStart();
RemoveFocus();
}
}
@@ -1071,6 +1068,17 @@ namespace FlaxEngine.GUI
base.Update(deltaTime);
}
/// <summary>
/// Restores the Text from the start.
/// </summary>
public void RestoreTextFromStart()
{
// Restore text from start
SetSelection(-1);
_text = _onStartEditValue;
OnTextChanged();
}
/// <inheritdoc />
public override void OnGotFocus()
{
@@ -1326,13 +1334,10 @@ namespace FlaxEngine.GUI
}
case KeyboardKeys.Escape:
{
// Restore text from start
SetSelection(-1);
_text = _onStartEditValue;
RestoreTextFromStart();
if (!IsNavFocused)
RemoveFocus();
OnTextChanged();
return true;
}