From 34aff4a2b6057370fada9af6c60863e8ee24958b Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Wed, 22 Feb 2023 17:34:33 -0600 Subject: [PATCH] Added a change cursor boolean to `TextBoxBase` and made it so the cursor changes to default when hovering over the cancel button. --- Source/Editor/GUI/Input/SearchBox.cs | 6 ++++++ Source/Engine/UI/GUI/Common/TextBoxBase.cs | 13 ++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Source/Editor/GUI/Input/SearchBox.cs b/Source/Editor/GUI/Input/SearchBox.cs index 8ffd0874a..994ef14b1 100644 --- a/Source/Editor/GUI/Input/SearchBox.cs +++ b/Source/Editor/GUI/Input/SearchBox.cs @@ -49,6 +49,12 @@ namespace FlaxEditor.GUI.Input ClearSearchButton.LocalY += 2; ClearSearchButton.LocalX -= 2; ClearSearchButton.Clicked += Clear; + ClearSearchButton.HoverBegin += () => + { + _changeCursor = false; + Cursor = CursorType.Default; + }; + ClearSearchButton.HoverEnd += () => _changeCursor = true; TextChanged += () => ClearSearchButton.Visible = !string.IsNullOrEmpty(Text); } diff --git a/Source/Engine/UI/GUI/Common/TextBoxBase.cs b/Source/Engine/UI/GUI/Common/TextBoxBase.cs index 12760c176..732b867d6 100644 --- a/Source/Engine/UI/GUI/Common/TextBoxBase.cs +++ b/Source/Engine/UI/GUI/Common/TextBoxBase.cs @@ -114,6 +114,11 @@ namespace FlaxEngine.GUI /// protected float _animateTime; + /// + /// If the cursor should change to an IBeam + /// + protected bool _changeCursor = true; + /// /// Event fired when text gets changed /// @@ -1131,7 +1136,7 @@ namespace FlaxEngine.GUI /// public override void OnMouseEnter(Float2 location) { - if (_isEditing) + if (_isEditing && _changeCursor) Cursor = CursorType.IBeam; base.OnMouseEnter(location); @@ -1159,8 +1164,8 @@ namespace FlaxEngine.GUI // Modify selection end SetSelection(_selectionStart, currentIndex); } - - if (Cursor == CursorType.Default && _isEditing) + + if (Cursor == CursorType.Default && _isEditing && _changeCursor) Cursor = CursorType.IBeam; } @@ -1200,6 +1205,8 @@ namespace FlaxEngine.GUI if (button == MouseButton.Left && !IsFocused) { Focus(); + if (_changeCursor) + Cursor = CursorType.IBeam; return true; }