Updated LabelLineEdit
Changed to use Source Generators.
This commit is contained in:
parent
b4f6258d5f
commit
3931f059db
1 changed files with 30 additions and 8 deletions
|
|
@ -1,23 +1,45 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
[GlobalClass]
|
||||
[GlobalClass, Tool]
|
||||
public partial class LabelLineEdit : HBoxContainer
|
||||
{
|
||||
#region Exports
|
||||
#endregion
|
||||
|
||||
#region Nodes
|
||||
[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;
|
||||
#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();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue