From eab775b9a22cae553de8f4bf600d6e15d0457fed Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Thu, 8 Dec 2022 08:02:43 -0600 Subject: [PATCH] Added RstoreTextFromStart function and changed the calls. Renamed bool. --- Source/Editor/GUI/Input/SliderControl.cs | 2 +- Source/Editor/GUI/Input/ValueBox.cs | 6 +++--- Source/Engine/UI/GUI/Common/TextBoxBase.cs | 25 +++++++++++++--------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/Source/Editor/GUI/Input/SliderControl.cs b/Source/Editor/GUI/Input/SliderControl.cs index 8dc129d0a..6fe9a246e 100644 --- a/Source/Editor/GUI/Input/SliderControl.cs +++ b/Source/Editor/GUI/Input/SliderControl.cs @@ -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; } diff --git a/Source/Editor/GUI/Input/ValueBox.cs b/Source/Editor/GUI/Input/ValueBox.cs index 6cfbbddfb..c25455612 100644 --- a/Source/Editor/GUI/Input/ValueBox.cs +++ b/Source/Editor/GUI/Input/ValueBox.cs @@ -125,7 +125,7 @@ namespace FlaxEditor.GUI.Input _min = min; _max = max; _slideSpeed = sliderSpeed; - CanEndEditByClick = true; + EndEditOnClick = true; } /// @@ -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; diff --git a/Source/Engine/UI/GUI/Common/TextBoxBase.cs b/Source/Engine/UI/GUI/Common/TextBoxBase.cs index 78ab040a2..85b5c537c 100644 --- a/Source/Engine/UI/GUI/Common/TextBoxBase.cs +++ b/Source/Engine/UI/GUI/Common/TextBoxBase.cs @@ -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 /// [HideInEditor] - public bool CanEndEditByClick { get; set; } = false; + public bool EndEditOnClick { get; set; } = false; /// /// 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); } + /// + /// Restores the Text from the start. + /// + public void RestoreTextFromStart() + { + // Restore text from start + SetSelection(-1); + _text = _onStartEditValue; + OnTextChanged(); + } + /// 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; }