Hand labeler UI improvements (#40318)
* 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
This commit is contained in:
@@ -33,6 +33,7 @@ namespace Content.Client.Labels.UI
|
|||||||
|
|
||||||
_window.OnLabelChanged += OnLabelChanged;
|
_window.OnLabelChanged += OnLabelChanged;
|
||||||
Reload();
|
Reload();
|
||||||
|
_window.SetInitialLabelState(); // Must be after Reload() has set the label text
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnLabelChanged(string newLabel)
|
private void OnLabelChanged(string newLabel)
|
||||||
|
|||||||
@@ -1,8 +1,14 @@
|
|||||||
<DefaultWindow xmlns="https://spacestation14.io"
|
<DefaultWindow xmlns="https://spacestation14.io"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
Title="{Loc 'hand-labeler-ui-header'}">
|
Title="{Loc 'hand-labeler-ui-header'}"
|
||||||
<BoxContainer Orientation="Vertical" SeparationOverride="4" MinWidth="150">
|
SetWidth="400"
|
||||||
|
MinWidth="150">
|
||||||
|
<BoxContainer Orientation="Vertical" SeparationOverride="4">
|
||||||
<Label Name="CurrentTextLabel" Text="{Loc 'hand-labeler-current-text-label'}" />
|
<Label Name="CurrentTextLabel" Text="{Loc 'hand-labeler-current-text-label'}" />
|
||||||
<LineEdit Name="LabelLineEdit" />
|
<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>
|
</BoxContainer>
|
||||||
</DefaultWindow>
|
</DefaultWindow>
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ namespace Content.Client.Labels.UI
|
|||||||
// TODO LineEdit Make this a bool on the LineEdit control
|
// TODO LineEdit Make this a bool on the LineEdit control
|
||||||
|
|
||||||
private string _label = string.Empty;
|
private string _label = string.Empty;
|
||||||
|
private string _initialLabel = string.Empty;
|
||||||
|
|
||||||
public HandLabelerWindow()
|
public HandLabelerWindow()
|
||||||
{
|
{
|
||||||
@@ -25,6 +26,7 @@ namespace Content.Client.Labels.UI
|
|||||||
{
|
{
|
||||||
_label = e.Text;
|
_label = e.Text;
|
||||||
OnLabelChanged?.Invoke(_label);
|
OnLabelChanged?.Invoke(_label);
|
||||||
|
UpdateButtons();
|
||||||
};
|
};
|
||||||
|
|
||||||
LabelLineEdit.OnFocusEnter += _ => _focused = true;
|
LabelLineEdit.OnFocusEnter += _ => _focused = true;
|
||||||
@@ -33,12 +35,14 @@ namespace Content.Client.Labels.UI
|
|||||||
_focused = false;
|
_focused = false;
|
||||||
LabelLineEdit.Text = _label;
|
LabelLineEdit.Text = _label;
|
||||||
};
|
};
|
||||||
|
ResetLabelButton.OnPressed += _ => LabelLineEdit.SetText(_initialLabel, true);
|
||||||
|
ClearLabelButton.OnPressed += _ => LabelLineEdit.SetText("", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Opened()
|
protected override void Opened()
|
||||||
{
|
{
|
||||||
base.Opened();
|
base.Opened();
|
||||||
|
|
||||||
// Give the editor keyboard focus, since that's the only
|
// Give the editor keyboard focus, since that's the only
|
||||||
// thing the user will want to be doing with this UI
|
// thing the user will want to be doing with this UI
|
||||||
LabelLineEdit.GrabKeyboardFocus();
|
LabelLineEdit.GrabKeyboardFocus();
|
||||||
@@ -51,7 +55,25 @@ namespace Content.Client.Labels.UI
|
|||||||
|
|
||||||
_label = label;
|
_label = label;
|
||||||
if (!_focused)
|
if (!_focused)
|
||||||
|
{
|
||||||
LabelLineEdit.Text = label;
|
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)
|
public void SetMaxLabelLength(int maxLength)
|
||||||
|
|||||||
@@ -3,6 +3,12 @@ hand-labeler-ui-header = Hand Labeler
|
|||||||
# The content of the label in the UI above the text entry input.
|
# The content of the label in the UI above the text entry input.
|
||||||
hand-labeler-current-text-label = Label:
|
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
|
# When the hand labeler applies a label successfully
|
||||||
hand-labeler-successfully-applied = Applied label successfully
|
hand-labeler-successfully-applied = Applied label successfully
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user