From b7848599cd43a1da2b479e69ebabdb5336c60619 Mon Sep 17 00:00:00 2001 From: Krzysztof Gutkowski Date: Tue, 9 Jun 2026 13:00:59 +0200 Subject: [PATCH] Allow specifying `LengthLimit` on form text boxes (#37927) Will come in handy for stuff like the multiplayer match creation screen. [Screencast_20260527_162854.webm](https://github.com/user-attachments/assets/03d36104-da6c-4cdf-a1ad-439ddfd2036a) --- .../Visual/UserInterface/TestSceneFormControls.cs | 7 +++++++ osu.Game/Graphics/UserInterfaceV2/FormTextBox.cs | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneFormControls.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneFormControls.cs index 5d4ef422a4..2463ab6741 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneFormControls.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneFormControls.cs @@ -67,6 +67,13 @@ namespace osu.Game.Tests.Visual.UserInterface TabbableContentContainer = this, }, new FormTextBox + { + Caption = "Length limited text", + PlaceholderText = "I can only hold 10 characters!", + LengthLimit = 10, + TabbableContentContainer = this, + }, + new FormTextBox { Caption = "Artist", HintText = "Poot artist here!", diff --git a/osu.Game/Graphics/UserInterfaceV2/FormTextBox.cs b/osu.Game/Graphics/UserInterfaceV2/FormTextBox.cs index 7b97c8baf3..b393c56795 100644 --- a/osu.Game/Graphics/UserInterfaceV2/FormTextBox.cs +++ b/osu.Game/Graphics/UserInterfaceV2/FormTextBox.cs @@ -77,6 +77,11 @@ namespace osu.Game.Graphics.UserInterfaceV2 /// public LocalisableString PlaceholderText { get; init; } + /// + /// Maximum allowed length of text. + /// + public int? LengthLimit { get; init; } + private FormControlBackground background = null!; private Box flashLayer = null!; private InnerTextBox textBox = null!; @@ -120,6 +125,7 @@ namespace osu.Game.Graphics.UserInterfaceV2 t.RelativeSizeAxes = Axes.X; t.Width = 1; t.PlaceholderText = PlaceholderText; + t.LengthLimit = LengthLimit; t.Current = Current; t.CommitOnFocusLost = true; t.OnCommit += (textBox, newText) =>