From: eoineoineoin Date: Wed, 4 Sep 2024 14:20:00 +0000 (+0100) Subject: Improvements to hand labeler UI (#31833) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=7fd92abeeb866a0cc07a1cdf059aae1ce7427674;p=space-station-14.git Improvements to hand labeler UI (#31833) Give line edit focus when window is opened No longer require pressing enter to set the text Give feedback when user hits the maximum label length Co-authored-by: Eoin Mcloughlin --- diff --git a/Content.Client/Labels/UI/HandLabelerBoundUserInterface.cs b/Content.Client/Labels/UI/HandLabelerBoundUserInterface.cs index 6b65612341..b9b58f2322 100644 --- a/Content.Client/Labels/UI/HandLabelerBoundUserInterface.cs +++ b/Content.Client/Labels/UI/HandLabelerBoundUserInterface.cs @@ -26,6 +26,11 @@ namespace Content.Client.Labels.UI _window = this.CreateWindow(); + if (_entManager.TryGetComponent(Owner, out HandLabelerComponent? labeler)) + { + _window.SetMaxLabelLength(labeler!.MaxLabelChars); + } + _window.OnLabelChanged += OnLabelChanged; Reload(); } diff --git a/Content.Client/Labels/UI/HandLabelerWindow.xaml.cs b/Content.Client/Labels/UI/HandLabelerWindow.xaml.cs index 6482cdc1cc..7a0627b3e2 100644 --- a/Content.Client/Labels/UI/HandLabelerWindow.xaml.cs +++ b/Content.Client/Labels/UI/HandLabelerWindow.xaml.cs @@ -21,7 +21,7 @@ namespace Content.Client.Labels.UI { RobustXamlLoader.Load(this); - LabelLineEdit.OnTextEntered += e => + LabelLineEdit.OnTextChanged += e => { _label = e.Text; OnLabelChanged?.Invoke(_label); @@ -33,6 +33,10 @@ namespace Content.Client.Labels.UI _focused = false; LabelLineEdit.Text = _label; }; + + // Give the editor keybard focus, since that's the only + // thing the user will want to be doing with this UI + LabelLineEdit.GrabKeyboardFocus(); } public void SetCurrentLabel(string label) @@ -44,5 +48,10 @@ namespace Content.Client.Labels.UI if (!_focused) LabelLineEdit.Text = label; } + + public void SetMaxLabelLength(int maxLength) + { + LabelLineEdit.IsValid = s => s.Length <= maxLength; + } } }