diff --git a/Source/Editor/GUI/Input/SliderControl.cs b/Source/Editor/GUI/Input/SliderControl.cs
index 7a8b82622..8dc129d0a 100644
--- a/Source/Editor/GUI/Input/SliderControl.cs
+++ b/Source/Editor/GUI/Input/SliderControl.cs
@@ -371,6 +371,7 @@ namespace FlaxEditor.GUI.Input
Parent = this,
Location = new Float2(split, 0),
Size = new Float2(Height, TextBoxSize),
+ CanEndEditByClick = true,
};
_textBox.EditEnd += OnTextBoxEditEnd;
}
diff --git a/Source/Editor/GUI/Input/ValueBox.cs b/Source/Editor/GUI/Input/ValueBox.cs
index 7f4fb51e0..6cfbbddfb 100644
--- a/Source/Editor/GUI/Input/ValueBox.cs
+++ b/Source/Editor/GUI/Input/ValueBox.cs
@@ -125,6 +125,7 @@ namespace FlaxEditor.GUI.Input
_min = min;
_max = max;
_slideSpeed = sliderSpeed;
+ CanEndEditByClick = true;
}
///
@@ -173,6 +174,7 @@ namespace FlaxEditor.GUI.Input
private void EndSliding()
{
_isSliding = false;
+ CanEndEditByClick = true;
EndMouseCapture();
if (_cursorChanged)
{
@@ -245,6 +247,7 @@ namespace FlaxEditor.GUI.Input
_startSlideLocation = location;
_startSlideValue = _value;
StartMouseCapture(true);
+ CanEndEditByClick = false;
// Hide cursor and cache location
Cursor = CursorType.Hidden;
diff --git a/Source/Engine/UI/GUI/Common/TextBoxBase.cs b/Source/Engine/UI/GUI/Common/TextBoxBase.cs
index 69b4fa123..78ab040a2 100644
--- a/Source/Engine/UI/GUI/Common/TextBoxBase.cs
+++ b/Source/Engine/UI/GUI/Common/TextBoxBase.cs
@@ -139,6 +139,12 @@ namespace FlaxEngine.GUI
///
public event Action KeyUp;
+ ///
+ /// Gets or sets a value indicating whether the text box can end edit via left click outside of the control
+ ///
+ [HideInEditor]
+ public bool CanEndEditByClick { get; set; } = false;
+
///
/// Gets or sets a value indicating whether this is a multiline text box control.
///
@@ -1041,6 +1047,26 @@ namespace FlaxEngine.GUI
// Animate view offset
_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 (!IsMouseOver && RootWindow.ContainsFocus)
+ {
+ if (Input.GetMouseButtonDown(MouseButton.Left))
+ {
+ RemoveFocus();
+ }
+ else if (Input.GetMouseButtonDown(MouseButton.Right))
+ {
+ // Restore text from start
+ SetSelection(-1);
+ _text = _onStartEditValue;
+ OnTextChanged();
+ RemoveFocus();
+ }
+ }
+ }
base.Update(deltaTime);
}