Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Content.Client/Labels/UI/HandLabelerBoundUserInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ protected override void Open()

_window.OnLabelChanged += OnLabelChanged;
Reload();
_window.SetInitialLabelState(); // Must be after Reload() has set the label text
}

private void OnLabelChanged(string newLabel)
Expand Down
10 changes: 8 additions & 2 deletions Content.Client/Labels/UI/HandLabelerWindow.xaml
Original file line number Diff line number Diff line change
@@ -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" HorizontalExpand="True">
<Label Name="CurrentTextLabel" Text="{Loc 'hand-labeler-current-text-label'}" />
<LineEdit Name="LabelLineEdit" />
<BoxContainer Orientation="Horizontal" HorizontalExpand="True" Align="Center">
<Button Name="ResetLabelButton" Text="{Loc 'hand-labeler-ui-reset-label-text'}"/>
<Button Name="ClearLabelButton" Text="{Loc 'hand-labeler-ui-clear-label-text'}"/>
</BoxContainer>
</BoxContainer>
</DefaultWindow>
24 changes: 23 additions & 1 deletion Content.Client/Labels/UI/HandLabelerWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public sealed partial class HandLabelerWindow : DefaultWindow
// TODO LineEdit Make this a bool on the LineEdit control

private string _label = string.Empty;
private string _initialLabel = string.Empty;

public HandLabelerWindow()
{
Expand All @@ -25,6 +26,7 @@ public HandLabelerWindow()
{
_label = e.Text;
OnLabelChanged?.Invoke(_label);
UpdateButtons();
};

LabelLineEdit.OnFocusEnter += _ => _focused = true;
Expand All @@ -33,12 +35,14 @@ public HandLabelerWindow()
_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();
Expand All @@ -51,7 +55,25 @@ public void SetCurrentLabel(string label)

_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)
Expand Down
6 changes: 6 additions & 0 deletions Resources/Locale/en-US/hand-labeler/hand-labeler.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading