2using System.Collections.Generic;
4using System.Reflection;
5using System.Diagnostics;
6using System.Runtime.CompilerServices;
10using Microsoft.Xna.Framework;
11using Microsoft.Xna.Framework.Input;
12using Microsoft.Xna.Framework.Graphics;
19 public partial class CUIComponent
21 #region Tree --------------------------------------------------------
23 public List<CUIComponent> Children {
get;
set; } =
new();
25 private CUIComponent? parent;
public CUIComponent? Parent
28 set => SetParent(value);
33 internal void SetParent(CUIComponent? value, [CallerMemberName]
string memberName =
"")
40 parent.Children.Remove(
this);
41 parent.OnChildRemoved?.Invoke(
this);
46 CUIDebug.Capture(
null,
this,
"SetParent", memberName,
"parent", $
"{parent}");
55 if (
AKA !=
null) parent.Remember(
this,
AKA);
56 parent.PassPropsToChild(
this);
58 parent.OnChildAdded?.Invoke(
this);
63 private bool treeChanged =
true;
internal bool TreeChanged
71 OnTreeChanged?.Invoke();
72 if (Parent !=
null) Parent.TreeChanged =
true;
82 public event Action<CUIComponent> OnChildAdded;
83 public event Action<CUIComponent> OnChildRemoved;
95 if (child ==
null)
return child;
99 if (name !=
null) Remember(child, name);
112 if (child ==
null)
return child;
115 Children.Insert(0, child);
116 if (name !=
null) Remember(child, name);
121 public virtual CUIComponent Insert(
CUIComponent child,
int index,
string name =
null, [CallerMemberName]
string memberName =
"")
123 if (child ==
null)
return child;
126 index = Math.Clamp(index, 0, Children.Count);
127 Children.Insert(index, child);
128 if (name !=
null) Remember(child, name);
134 public void RemoveSelf() => Parent?.RemoveChild(
this);
135 public CUIComponent RemoveChild(CUIComponent child, [CallerMemberName]
string memberName =
"")
137 if (child ==
null || !Children.Contains(child))
return child;
141 child.TreeChanged =
true;
142 child.OnPropChanged();
144 forsedSize =
new CUINullVector2();
145 OnAbsolutePropChanged();
147 Children.Remove(child);
148 OnChildRemoved?.Invoke(child);
153 CUIDebug.Capture(
null,
this,
"RemoveChild", memberName,
"child", $
"{child}");
160 public void RemoveAllChildren([CallerMemberName]
string memberName =
"")
162 foreach (CUIComponent c
in Children)
166 c.TreeChanged =
true;
170 OnChildRemoved?.Invoke(c);
175 CUIDebug.Capture(
null,
this,
"RemoveAllChildren", memberName,
"child", $
"{c}");
192 if (
ZIndex.HasValue && !child.IgnoreParentZIndex) child.ZIndex = ZIndex.Value + 1;
193 if (
IgnoreEvents && !child.IgnoreParentEventIgnorance) child.IgnoreEvents =
true;
194 if (!
Visible && !child.IgnoreParentVisibility) child.Visible =
false;
203 if (Parent ==
null)
return;
205 Parent.Children.Remove(
this);
206 Parent.Children.Add(
this);
Base class for all components.
void MoveToFront()
Moves component to front in Parent.Children which makes it render after other childs.
virtual CUIComponent Prepend(CUIComponent child, string name=null, [CallerMemberName] string memberName="")
Adds children to the begining of the list.
Dictionary< string, CUIComponent > NamedComponents
All memorized components.
virtual void PassPropsToChild(CUIComponent child)
Pass props like ZIndex, Visible to a new child.
CUIMainComponent MainComponent
Link to CUIMainComponent, passed to children.
virtual CUIComponent Append(CUIComponent child, string name=null, [CallerMemberName] string memberName="")
Adds children to the end of the list.
IEnumerable< CUIComponent > AddChildren
Allows you to add array of children.
string AKA
Parent can memorize it's children by their names, AKA.
int? ZIndex
Components are drawn in order of their ZIndex Normally it's derived from component position in the ...
bool Visible
Invisible components are not drawn, but still can be interacted with.
bool IgnoreEvents
Won't react to mouse events.
bool ShouldPassPropsToChildren
Some props (like visible) are autopassed to all new childs see PassPropsToChild.