From af1918d5454a9dd560a2bd353e2a119dabe75d4c Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 20 May 2020 00:48:53 +0200 Subject: [PATCH] added child addition and removal callbacks --- MLEM.Ui/Elements/Element.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/MLEM.Ui/Elements/Element.cs b/MLEM.Ui/Elements/Element.cs index 920c162..f2089d1 100644 --- a/MLEM.Ui/Elements/Element.cs +++ b/MLEM.Ui/Elements/Element.cs @@ -152,6 +152,8 @@ namespace MLEM.Ui.Elements { public OtherElementCallback OnSelectedElementChanged; public TabNextElementCallback GetTabNextElement; public GamepadNextElementCallback GetGamepadNextElement; + public OtherElementCallback OnChildAdded; + public OtherElementCallback OnChildRemoved; public StyleProp SelectionIndicator; public StyleProp ActionSound; @@ -179,8 +181,8 @@ namespace MLEM.Ui.Elements { element.AndChildren(e => { e.Root = this.Root; e.System = this.System; - if (this.Root != null) - this.Root.OnElementAdded(e); + this.Root?.OnElementAdded(e); + this.OnChildAdded?.Invoke(this, e); }); this.SetSortedChildrenDirty(); element.SetAreaDirty(); @@ -196,8 +198,8 @@ namespace MLEM.Ui.Elements { element.AndChildren(e => { e.Root = null; e.System = null; - if (this.Root != null) - this.Root.OnElementRemoved(e); + this.Root?.OnElementRemoved(e); + this.OnChildRemoved?.Invoke(this, e); }); this.SetSortedChildrenDirty(); }