]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Hand labeler UI improvements (#40318)
authorAbsotively <jen@jenpollock.ca>
Thu, 23 Oct 2025 15:15:42 +0000 (09:15 -0600)
committerGitHub <noreply@github.com>
Thu, 23 Oct 2025 15:15:42 +0000 (15:15 +0000)
* Populate and select label line edit on window open

* Widen hand labeller UI

* Add reset and clear buttons to hand labeler UI

* Add window resizing fix from https://github.com/space-wizards/space-station-14/pull/40322

* xaml cleanup, button grouping

Content.Client/Labels/UI/HandLabelerBoundUserInterface.cs
Content.Client/Labels/UI/HandLabelerWindow.xaml
Content.Client/Labels/UI/HandLabelerWindow.xaml.cs
Resources/Locale/en-US/hand-labeler/hand-labeler.ftl

index b9b58f23220ace16e2327443aba229bdb435dab1..95d5cc7ab32c2eb3c6c2e429ecf478b736714235 100644 (file)
@@ -33,6 +33,7 @@ namespace Content.Client.Labels.UI
 
             _window.OnLabelChanged += OnLabelChanged;
             Reload();
+            _window.SetInitialLabelState(); // Must be after Reload() has set the label text
         }
 
         private void OnLabelChanged(string newLabel)
index 0bf03410c11a03ae029a23c5b9ac6780552a58c1..7bbadb843d6a757a4d5ebc35717b6bf163dddd05 100644 (file)
@@ -1,8 +1,14 @@
 <DefaultWindow xmlns="https://spacestation14.io"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-            Title="{Loc 'hand-labeler-ui-header'}">
-    <BoxContainer Orientation="Vertical" SeparationOverride="4" MinWidth="150">
+            Title="{Loc 'hand-labeler-ui-header'}"
+            SetWidth="400"
+            MinWidth="150">
+    <BoxContainer Orientation="Vertical" SeparationOverride="4">
         <Label Name="CurrentTextLabel" Text="{Loc 'hand-labeler-current-text-label'}" />
         <LineEdit Name="LabelLineEdit" />
+        <BoxContainer Orientation="Horizontal" Align="Center">
+            <Button Name="ResetLabelButton" Text="{Loc 'hand-labeler-ui-reset-label-text'}" StyleClasses="OpenRight" />
+            <Button Name="ClearLabelButton" Text="{Loc 'hand-labeler-ui-clear-label-text'}" StyleClasses="OpenLeft" />
+        </BoxContainer>
     </BoxContainer>
 </DefaultWindow>
index 528e227f552a7fc8e9e43000651985d686f230ad..32c9d980a4b06ae614adc04fe3961a4805ad8056 100644 (file)
@@ -16,6 +16,7 @@ namespace Content.Client.Labels.UI
         // TODO LineEdit Make this a bool on the LineEdit control
 
         private string _label = string.Empty;
+        private string _initialLabel = string.Empty;
 
         public HandLabelerWindow()
         {
@@ -25,6 +26,7 @@ namespace Content.Client.Labels.UI
             {
                 _label = e.Text;
                 OnLabelChanged?.Invoke(_label);
+                UpdateButtons();
             };
 
             LabelLineEdit.OnFocusEnter += _ => _focused = true;
@@ -33,12 +35,14 @@ namespace Content.Client.Labels.UI
                 _focused = false;
                 LabelLineEdit.Text = _label;
             };
+            ResetLabelButton.OnPressed += _ => LabelLineEdit.SetText(_initialLabel, true);
+            ClearLabelButton.OnPressed += _ => LabelLineEdit.SetText("", true);
         }
 
         protected override void Opened()
         {
             base.Opened();
-            
+
             // Give the editor keyboard focus, since that's the only
             // thing the user will want to be doing with this UI
             LabelLineEdit.GrabKeyboardFocus();
@@ -51,7 +55,25 @@ namespace Content.Client.Labels.UI
 
             _label = label;
             if (!_focused)
+            {
                 LabelLineEdit.Text = label;
+                UpdateButtons();
+            }
+        }
+
+        public void SetInitialLabelState()
+        {
+            LabelLineEdit.Text = _label;
+            LabelLineEdit.CursorPosition = _label.Length;
+            LabelLineEdit.SelectionStart = 0;
+            _initialLabel = _label;
+            UpdateButtons();
+        }
+
+        public void UpdateButtons()
+        {
+            ResetLabelButton.Disabled = (LabelLineEdit.Text == _initialLabel);
+            ClearLabelButton.Disabled = (LabelLineEdit.Text == "");
         }
 
         public void SetMaxLabelLength(int maxLength)
index f9861b0f6f626573592312daab1d26531aeaf459..73263ff60f2a1e189625bf8ff1d38f55f72278ba 100644 (file)
@@ -3,6 +3,12 @@ hand-labeler-ui-header = Hand Labeler
 # The content of the label in the UI above the text entry input.
 hand-labeler-current-text-label = Label:
 
+# The text on the button in the UI to reset the text entry input to the content it had when the UI was opened
+hand-labeler-ui-reset-label-text = Reset
+
+# The text on the button in the UI to clear the text entry input
+hand-labeler-ui-clear-label-text = Clear
+
 # When the hand labeler applies a label successfully
 hand-labeler-successfully-applied = Applied label successfully