45 lines
1.4 KiB
C#
45 lines
1.4 KiB
C#
using Godot;
|
|
using System;
|
|
|
|
[GlobalClass, Tool]
|
|
public partial class LabelLineEdit : HBoxContainer
|
|
{
|
|
[Export, Notify] public partial string Label { get; set; }
|
|
[Export, Notify] public partial string Text { get; set; }
|
|
[Export, Notify] public partial int Spacing { get; set; }
|
|
[Export, Notify] public partial bool Password { get; set; }
|
|
|
|
private Label _labelNode;
|
|
private LineEdit _lineEdit;
|
|
|
|
public LabelLineEdit()
|
|
{
|
|
Spacing = 4;
|
|
}
|
|
|
|
[GodotOverride]
|
|
private void OnReady()
|
|
{
|
|
_labelNode ??= new Label();
|
|
_lineEdit ??= new LineEdit();
|
|
_lineEdit.SizeFlagsHorizontal = SizeFlags.ExpandFill;
|
|
AddChild(_labelNode);
|
|
AddChild(_lineEdit);
|
|
_labelNode.Text = Label;
|
|
_lineEdit.Text = Text;
|
|
_lineEdit.Secret = Password;
|
|
LabelChanged += () => _labelNode.Text = Label;
|
|
TextChanged += () => _lineEdit.Text = Text;
|
|
PasswordChanged += () => _lineEdit.Secret = Password;
|
|
SpacingChanged += () => AddThemeConstantOverride("separation", Spacing);
|
|
_lineEdit.TextChanged += async value =>
|
|
{
|
|
var pos = _lineEdit.GetCaretColumn();
|
|
Text = value;
|
|
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
|
_lineEdit.SetCaretColumn(pos);
|
|
};
|
|
}
|
|
|
|
public override partial void _Ready();
|
|
}
|