调整了模板
This commit is contained in:
46
BITKit/Scripts/Builder/Form/Examples/ExampleFormResource.cs
Normal file
46
BITKit/Scripts/Builder/Form/Examples/ExampleFormResource.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using BITFactory;
|
||||
|
||||
namespace BITKit;
|
||||
[GlobalClass]
|
||||
public partial class ExampleFormResource : FormResource
|
||||
{
|
||||
public ExampleFormResource(){}
|
||||
public ExampleFormResource(string name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public struct FormField : IFormField
|
||||
{
|
||||
public int FieldCount => 2;
|
||||
public string[] FieldNames => new[] {"Filed 1", "Field 2"};
|
||||
public string[] FieldTypes=> new[] {"string", "int"};
|
||||
public string[] DefaultValues=> new[] {"null", "0"};
|
||||
}
|
||||
|
||||
[Export] private string name;
|
||||
|
||||
public override string Name
|
||||
{
|
||||
get => name;
|
||||
set => name = value;
|
||||
}
|
||||
|
||||
public override IFormField[] Fields
|
||||
{
|
||||
get
|
||||
{
|
||||
var list = new List<IFormField>();
|
||||
for (var i = 0; i < GD.RandRange(1, 6); i++)
|
||||
{
|
||||
list.Add(new FormField());
|
||||
}
|
||||
|
||||
return list.ToArray();
|
||||
}
|
||||
set => throw new NotImplementedException();
|
||||
}
|
||||
}
|
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