From 5dadaf70f98cb9cde966e93ef4edf69e8f046ac9 Mon Sep 17 00:00:00 2001 From: Wojciech Figat Date: Mon, 8 Aug 2022 11:18:16 +0200 Subject: [PATCH] Add option to disable selecting text in text box --- Source/Engine/UI/GUI/Common/TextBoxBase.cs | 36 ++++++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/Source/Engine/UI/GUI/Common/TextBoxBase.cs b/Source/Engine/UI/GUI/Common/TextBoxBase.cs index 36c6fc1f4..41d8b9b44 100644 --- a/Source/Engine/UI/GUI/Common/TextBoxBase.cs +++ b/Source/Engine/UI/GUI/Common/TextBoxBase.cs @@ -84,6 +84,11 @@ namespace FlaxEngine.GUI /// protected bool _isReadOnly; + /// + /// Flag used to indicate whenever text is selectable. + /// + protected bool _isSelectable = true; + /// /// The maximum length of the text. /// @@ -186,12 +191,28 @@ namespace FlaxEngine.GUI if (_isReadOnly != value) { _isReadOnly = value; - OnIsReadOnlyChanged(); } } } + /// + /// Gets or sets a value indicating whether text can be selected in text box. + /// + [EditorOrder(62), Tooltip("If checked, text can be selected in text box.")] + public bool IsSelectable + { + get => _isSelectable; + set + { + if (_isSelectable != value) + { + _isSelectable = value; + OnIsSelectableChanged(); + } + } + } + /// /// Gets or sets a value indicating whether apply clipping mask on text during rendering. /// @@ -906,6 +927,13 @@ namespace FlaxEngine.GUI { } + /// + /// Called when is selectable flag gets changed. + /// + protected virtual void OnIsSelectableChanged() + { + } + /// /// Action called when user starts text selecting /// @@ -1064,7 +1092,7 @@ namespace FlaxEngine.GUI if (base.OnMouseDown(location, button)) return true; - if (button == MouseButton.Left && _text.Length > 0) + if (button == MouseButton.Left && _text.Length > 0 && _isSelectable) { Focus(); OnSelectingBegin(); @@ -1103,7 +1131,7 @@ namespace FlaxEngine.GUI if (base.OnMouseUp(location, button)) return true; - if (button == MouseButton.Left) + if (button == MouseButton.Left && _isSelectable) { OnSelectingEnd(); return true; @@ -1134,6 +1162,8 @@ namespace FlaxEngine.GUI { if (base.OnCharInput(c)) return true; + if (IsReadOnly) + return false; Insert(c); return true; }