Files
tbd-station-14/Content.Client/Labels/UI/HandLabelerWindow.xaml.cs
Absotively f1c95bfbb1 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
2025-10-23 15:15:42 +00:00

85 lines
2.4 KiB
C#

using Robust.Client.UserInterface.CustomControls;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.XAML;
namespace Content.Client.Labels.UI
{
[GenerateTypedNameReferences]
public sealed partial class HandLabelerWindow : DefaultWindow
{
public event Action<string>? OnLabelChanged;
/// <summary>
/// Is the user currently entering text into the control?
/// </summary>
private bool _focused;
// TODO LineEdit Make this a bool on the LineEdit control
private string _label = string.Empty;
private string _initialLabel = string.Empty;
public HandLabelerWindow()
{
RobustXamlLoader.Load(this);
LabelLineEdit.OnTextChanged += e =>
{
_label = e.Text;
OnLabelChanged?.Invoke(_label);
UpdateButtons();
};
LabelLineEdit.OnFocusEnter += _ => _focused = true;
LabelLineEdit.OnFocusExit += _ =>
{
_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();
}
public void SetCurrentLabel(string label)
{
if (label == _label)
return;
_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)
{
LabelLineEdit.IsValid = s => s.Length <= maxLength;
}
}
}