diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d505d6..93824c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ Fixes - Fixed paragraphs sometimes not updating their position properly when hidden because they're empty - Fixed panels sometimes not drawing children that came into view when their positions changed unexpectedly - Fixed UiMarkdownParser not parsing formatting in headings and blockquotes +- Fixed Element.OnChildAdded and Element.OnChildRemoved being called for grandchildren when a child is added ### MLEM.Data Improvements diff --git a/MLEM.Ui/Elements/Element.cs b/MLEM.Ui/Elements/Element.cs index 4e168f0..e0d7e54 100644 --- a/MLEM.Ui/Elements/Element.cs +++ b/MLEM.Ui/Elements/Element.cs @@ -407,11 +407,13 @@ namespace MLEM.Ui.Elements { /// public GamepadNextElementCallback GetGamepadNextElement; /// - /// Event that is called when a child or any level of grandchild is added to this element using + /// Event that is called when a child is added to this element using + /// Note that, while this event is only called for immediate children of this element, is called for all children and grandchildren. /// public OtherElementCallback OnChildAdded; /// - /// Event that is called when a child or any level of grandchild is removed from this element using + /// Event that is called when a child is removed from this element using . + /// Note that, while this event is only called for immediate children of this element, is called for all children and grandchildren. /// public OtherElementCallback OnChildRemoved; /// @@ -507,8 +509,8 @@ namespace MLEM.Ui.Elements { e.System = this.System; e.OnAddedToUi?.Invoke(e); this.Root?.InvokeOnElementAdded(e); - this.OnChildAdded?.Invoke(this, e); }); + this.OnChildAdded?.Invoke(this, element); this.SetSortedChildrenDirty(); element.SetAreaDirty(); return element; @@ -531,8 +533,8 @@ namespace MLEM.Ui.Elements { e.System = null; e.OnRemovedFromUi?.Invoke(e); this.Root?.InvokeOnElementRemoved(e); - this.OnChildRemoved?.Invoke(this, e); }); + this.OnChildRemoved?.Invoke(this, element); this.SetSortedChildrenDirty(); } diff --git a/MLEM.Ui/UiSystem.cs b/MLEM.Ui/UiSystem.cs index b9d78e7..1e4587b 100644 --- a/MLEM.Ui/UiSystem.cs +++ b/MLEM.Ui/UiSystem.cs @@ -572,7 +572,7 @@ namespace MLEM.Ui { /// public event Element.GenericCallback OnElementAdded; /// - /// Event that is invoked when a is removed rom this root element of any of its children. + /// Event that is invoked when a is removed rom this root element or any of its children. /// public event Element.GenericCallback OnElementRemoved; ///