Browse Source

obsolete the clearchildren label

master
jkpete 2 months ago
parent
commit
f6469d6d1e
  1. 45
      addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGRowData.cs
  2. 6
      addons/EGFramework/Module/NodeExtension/EGNode.cs

45
addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGRowData.cs

@ -6,9 +6,10 @@ namespace EGFramework.UI
{ {
public interface IEGRowData public interface IEGRowData
{ {
public void InitRowData(Dictionary<string, object> data);
public void RefreshData(Dictionary<string, object> data);
} }
public partial class EGRowData : PanelContainer, IEGFramework public partial class EGRowData : PanelContainer, IEGFramework,IEGRowData
{ {
public Button ItemHover { get; set; } public Button ItemHover { get; set; }
@ -17,36 +18,60 @@ namespace EGFramework.UI
public HBoxContainer List { get; set; } public HBoxContainer List { get; set; }
protected Dictionary<string, object> Data { get; set; } protected Dictionary<string, object> Data { get; set; }
protected bool IsInit { set; get; } = false;
public virtual void InitRowData(Dictionary<string,object> data){ public virtual void InitRowData(Dictionary<string, object> data)
{
if (IsInit)
{
this.Data = data;
this.RefreshData(data);
return;
}
this.Data = data; this.Data = data;
BackGround = new ColorRect(); BackGround = new ColorRect();
BackGround.Name = "BackGround"; BackGround.Name = "BackGround";
BackGround.Color = new Color(0.5f,0.5f,1f); BackGround.Color = new Color(0f, 0f, 0f, 0f);
BackGround.SizeFlagsHorizontal = SizeFlags.ExpandFill; BackGround.SizeFlagsHorizontal = SizeFlags.ExpandFill;
BackGround.SizeFlagsVertical = SizeFlags.ExpandFill; BackGround.SizeFlagsVertical = SizeFlags.ExpandFill;
this.AddChild(BackGround); this.AddChild(BackGround);
List = new HBoxContainer(); List = new HBoxContainer();
List.Name = "TableRow_"+Resource.GenerateSceneUniqueId(); List.Name = "TableRow_" + Resource.GenerateSceneUniqueId();
List.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill; List.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
this.AddChild(List); this.AddChild(List);
Line = new ColorRect(); Line = new ColorRect();
Line.Name = "Line"; Line.Name = "Line";
Line.Color = new Color(0.5f,0.5f,0.5f); Line.Color = new Color(0f, 0f, 0f, 0f);
Line.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill; Line.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
Line.SizeFlagsVertical = Control.SizeFlags.ShrinkEnd; Line.SizeFlagsVertical = Control.SizeFlags.ShrinkEnd;
Line.CustomMinimumSize = new Vector2(0,1); Line.CustomMinimumSize = new Vector2(0, 1);
this.AddChild(Line); this.AddChild(Line);
foreach(KeyValuePair<string,object> kv in data){ foreach (KeyValuePair<string, object> kv in data)
this.List.AddChild(new Label(){ {
this.List.AddChild(new Label()
{
Name = kv.Key, Name = kv.Key,
Text = kv.Value.ToString(), Text = kv.Value.ToString(),
HorizontalAlignment = HorizontalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center,
SizeFlagsHorizontal = Control.SizeFlags.ExpandFill SizeFlagsHorizontal = Control.SizeFlags.ExpandFill
}); });
} }
this.AddThemeStyleboxOverride("panel",new StyleBoxEmpty()); this.AddThemeStyleboxOverride("panel", new StyleBoxEmpty());
} }
public virtual void RefreshData(Dictionary<string, object> data)
{
this.List.ClearChildren<Label>();
foreach (KeyValuePair<string, object> kv in data)
{
this.List.AddChild(new Label()
{
Name = kv.Key,
Text = kv.Value.ToString(),
HorizontalAlignment = HorizontalAlignment.Center,
SizeFlagsHorizontal = Control.SizeFlags.ExpandFill
});
}
}
} }
} }

6
addons/EGFramework/Module/NodeExtension/EGNode.cs

@ -34,12 +34,14 @@ namespace EGFramework{
} }
} }
} }
[Obsolete("This method can be replaced by ClearChildren<Label>")]
public static void ClearChildrenLabel(this Node itemContainer) public static void ClearChildrenLabel(this Node itemContainer)
{ {
foreach (Node child in itemContainer.GetChildren()) foreach (Node child in itemContainer.GetChildren())
{ {
if(child.GetType()==typeof(Label)){ if (child.GetType() == typeof(Label))
{
child.QueueFree(); child.QueueFree();
} }
} }

Loading…
Cancel
Save