From 4d4571ee55e5ceeba8e4c032ddac63677b4a1fc2 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Fri, 6 Mar 2026 20:02:24 -0600 Subject: [PATCH] Allow -1 for Max textbox length Allow -1 to be "no" length or max length. add bottom limit of -1. --- Source/Engine/UI/GUI/Common/TextBoxBase.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Source/Engine/UI/GUI/Common/TextBoxBase.cs b/Source/Engine/UI/GUI/Common/TextBoxBase.cs index 7deb9a367..489e4c93d 100644 --- a/Source/Engine/UI/GUI/Common/TextBoxBase.cs +++ b/Source/Engine/UI/GUI/Common/TextBoxBase.cs @@ -191,14 +191,18 @@ namespace FlaxEngine.GUI /// /// Gets or sets the maximum number of characters the user can type into the text box control. /// - [EditorOrder(50), Tooltip("The maximum number of characters the user can type into the text box control.")] + [EditorOrder(50), Limit(-1), Tooltip("The maximum number of characters the user can type into the text box control.")] public int MaxLength { get => _maxLength; set { - if (_maxLength <= 0) - throw new ArgumentOutOfRangeException(nameof(MaxLength)); + // Cap at min of -1 for no max length + if (value <= 0) + { + _maxLength = -1; + return; + } if (_maxLength != value) { @@ -381,7 +385,7 @@ namespace FlaxEngine.GUI value = value.Replace(DelChar.ToString(), ""); // Clamp length - if (value.Length > MaxLength) + if (value.Length > MaxLength && MaxLength != -1) value = value.Substring(0, MaxLength); // Ensure to use only single line @@ -514,7 +518,7 @@ namespace FlaxEngine.GUI AutoFocus = true; _isMultiline = isMultiline; - _maxLength = 2147483646; + _maxLength = -1; _selectionStart = _selectionEnd = -1; var style = Style.Current; @@ -710,7 +714,7 @@ namespace FlaxEngine.GUI str = str.Replace("\n", ""); int selectionLength = SelectionLength; - int charactersLeft = MaxLength - _text.Length + selectionLength; + int charactersLeft = (MaxLength != -1 ? MaxLength : int.MaxValue) - _text.Length + selectionLength; Assert.IsTrue(charactersLeft >= 0); if (charactersLeft == 0) return;