1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-05-10 03:28:43 +02: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
- Added some extension methods for querying Anchor types
- Added Element.AutoSizeAddedAbsolute to allow for more granular control of auto-sizing
- Added Element.OnAddedToUi and Element.OnRemovedFromUi
Improvements
- 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>
public GamepadNextElementCallback GetGamepadNextElement;
/// <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>
public OtherElementCallback OnChildAdded;
/// <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>
public OtherElementCallback OnChildRemoved;
/// <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"/>.
/// This event is useful for unregistering global event handlers when this object should be destroyed.
/// </summary>
@ -497,6 +505,7 @@ namespace MLEM.Ui.Elements {
element.AndChildren(e => {
e.Root = this.Root;
e.System = this.System;
e.OnAddedToUi?.Invoke(e);
this.Root?.InvokeOnElementAdded(e);
this.OnChildAdded?.Invoke(this, e);
});
@ -520,6 +529,7 @@ namespace MLEM.Ui.Elements {
element.AndChildren(e => {
e.Root = null;
e.System = null;
e.OnRemovedFromUi?.Invoke(e);
this.Root?.InvokeOnElementRemoved(e);
this.OnChildRemoved?.Invoke(this, e);
});

View file

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