调整了模板
This commit is contained in:
60
BITKit/Scripts/Builder/Form/Examples/ExampleFormWeaver.cs
Normal file
60
BITKit/Scripts/Builder/Form/Examples/ExampleFormWeaver.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using BITFactory;
|
||||
|
||||
namespace BITKit;
|
||||
[GlobalClass]
|
||||
public partial class ExampleFormWeaver : FormWeaverResource
|
||||
{
|
||||
private readonly List<List<string>> _values=new();
|
||||
public override void Weaver(Control container, IFormField formField)
|
||||
{
|
||||
var layout = new HBoxContainer();
|
||||
|
||||
var index = _values.Count;
|
||||
|
||||
var list = new List<string>();
|
||||
|
||||
_values.Add(list);
|
||||
|
||||
for (var i = 0; i < formField.FieldCount; i++)
|
||||
{
|
||||
var label = new Label();
|
||||
var lineEdit = new UXLineEdit();
|
||||
var myIndex = i;
|
||||
|
||||
list.Add(string.Empty);
|
||||
|
||||
lineEdit.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
|
||||
|
||||
var name = formField.FieldNames[i];
|
||||
var type = formField.FieldTypes[i];
|
||||
var DefaultValue = formField.DefaultValues[i];
|
||||
|
||||
label.Text = name;
|
||||
lineEdit.PlaceholderText = DefaultValue;
|
||||
|
||||
layout.AddChild(label);
|
||||
layout.AddChild(lineEdit);
|
||||
|
||||
lineEdit.TextChanged += s =>
|
||||
{
|
||||
list[myIndex] = s;
|
||||
};
|
||||
}
|
||||
container.AddChild(layout);
|
||||
}
|
||||
|
||||
public override string GetContent()
|
||||
{
|
||||
var value = JsonHelper.Get(_values);
|
||||
GD.Print(value);
|
||||
return value;
|
||||
}
|
||||
|
||||
public override void Clear()
|
||||
{
|
||||
_values.Clear();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user