Updated LabelLineEdit

Changed to use Source Generators.
This commit is contained in:
Mario Steele 2025-09-27 02:25:14 -05:00
parent b4f6258d5f
commit 3931f059db

View file

@ -1,23 +1,45 @@
using Godot;
using System;
[GlobalClass]
[GlobalClass, Tool]
public partial class LabelLineEdit : HBoxContainer
{
#region Exports
#endregion
[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; }
#region Nodes
private Label _labelNode;
private LineEdit _lineEdit;
#endregion
public LabelLineEdit()
{
_labelNode = new Label();
_lineEdit = new LineEdit();
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();
}