1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-22 12:58:33 +01:00

Added Element.OnAddedToUi and Element.OnRemovedFromUi

This commit is contained in:
Ell 2022-09-13 14:27:49 +02:00
parent df2d102d8e
commit 55735b4c64
3 changed files with 15 additions and 2 deletions

View file

@ -29,6 +29,7 @@ Fixes
Additions Additions
- Added some extension methods for querying Anchor types - Added some extension methods for querying Anchor types
- Added Element.AutoSizeAddedAbsolute to allow for more granular control of auto-sizing - Added Element.AutoSizeAddedAbsolute to allow for more granular control of auto-sizing
- Added Element.OnAddedToUi and Element.OnRemovedFromUi
Improvements Improvements
- Allow elements to auto-adjust their size even when their children are aligned oddly - Allow elements to auto-adjust their size even when their children are aligned oddly

View file

@ -407,14 +407,22 @@ namespace MLEM.Ui.Elements {
/// </summary> /// </summary>
public GamepadNextElementCallback GetGamepadNextElement; public GamepadNextElementCallback GetGamepadNextElement;
/// <summary> /// <summary>
/// Event that is called when a child is added to this element using <see cref="AddChild{T}"/> /// Event that is called when a child or any level of grandchild is added to this element using <see cref="AddChild{T}"/>
/// </summary> /// </summary>
public OtherElementCallback OnChildAdded; public OtherElementCallback OnChildAdded;
/// <summary> /// <summary>
/// Event that is called when a child is removed from this element using <see cref="RemoveChild"/> /// Event that is called when a child or any level of grandchild is removed from this element using <see cref="RemoveChild"/>
/// </summary> /// </summary>
public OtherElementCallback OnChildRemoved; public OtherElementCallback OnChildRemoved;
/// <summary> /// <summary>
/// Event that is called when this element is added to a <see cref="UiSystem"/>, that is, when this element's <see cref="System"/> is set to a non-<see langword="null"/> value.
/// </summary>
public GenericCallback OnAddedToUi;
/// <summary>
/// Event that is called when this element is removed from a <see cref="UiSystem"/>, that is, when this element's <see cref="System"/> is set to <see langword="null"/>.
/// </summary>
public GenericCallback OnRemovedFromUi;
/// <summary>
/// Event that is called when this element's <see cref="Dispose"/> method is called, which also happens in <see cref="Finalize"/>. /// Event that is called when this element's <see cref="Dispose"/> method is called, which also happens in <see cref="Finalize"/>.
/// This event is useful for unregistering global event handlers when this object should be destroyed. /// This event is useful for unregistering global event handlers when this object should be destroyed.
/// </summary> /// </summary>
@ -497,6 +505,7 @@ namespace MLEM.Ui.Elements {
element.AndChildren(e => { element.AndChildren(e => {
e.Root = this.Root; e.Root = this.Root;
e.System = this.System; e.System = this.System;
e.OnAddedToUi?.Invoke(e);
this.Root?.InvokeOnElementAdded(e); this.Root?.InvokeOnElementAdded(e);
this.OnChildAdded?.Invoke(this, e); this.OnChildAdded?.Invoke(this, e);
}); });
@ -520,6 +529,7 @@ namespace MLEM.Ui.Elements {
element.AndChildren(e => { element.AndChildren(e => {
e.Root = null; e.Root = null;
e.System = null; e.System = null;
e.OnRemovedFromUi?.Invoke(e);
this.Root?.InvokeOnElementRemoved(e); this.Root?.InvokeOnElementRemoved(e);
this.OnChildRemoved?.Invoke(this, e); this.OnChildRemoved?.Invoke(this, e);
}); });

View file

@ -347,6 +347,7 @@ namespace MLEM.Ui {
root.Element.AndChildren(e => { root.Element.AndChildren(e => {
e.Root = root; e.Root = root;
e.System = this; e.System = this;
e.OnAddedToUi?.Invoke(e);
root.InvokeOnElementAdded(e); root.InvokeOnElementAdded(e);
e.SetAreaDirty(); e.SetAreaDirty();
}); });
@ -369,6 +370,7 @@ namespace MLEM.Ui {
root.Element.AndChildren(e => { root.Element.AndChildren(e => {
e.Root = null; e.Root = null;
e.System = null; e.System = null;
e.OnRemovedFromUi?.Invoke(e);
root.InvokeOnElementRemoved(e); root.InvokeOnElementRemoved(e);
e.SetAreaDirty(); e.SetAreaDirty();
}); });