1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-01 05:10:50 +01:00

Fixed AddedToUi and RemovedFromUi being called for freshly added or removed children whose parents are not in a ui system

This commit is contained in:
Ell 2024-10-29 20:28:44 +01:00
parent 50e864b94f
commit 41fb515f80
2 changed files with 7 additions and 4 deletions

View file

@ -31,6 +31,7 @@ Additions
Fixes Fixes
- Fixed tooltips not being bounded correctly for viewports that don't start at the origin - Fixed tooltips not being bounded correctly for viewports that don't start at the origin
- Fixed a stack overflow exception when a panel's children have just enough height to cause a scroll bar to appear - Fixed a stack overflow exception when a panel's children have just enough height to cause a scroll bar to appear
- Fixed AddedToUi and RemovedFromUi being called for freshly added or removed children whose parents are not in a ui system
### MLEM.Data ### MLEM.Data
Improvements Improvements

View file

@ -569,7 +569,8 @@ namespace MLEM.Ui.Elements {
index = this.children.Count; index = this.children.Count;
this.children.Insert(index, element); this.children.Insert(index, element);
element.Parent = this; element.Parent = this;
element.AndChildren(e => e.AddedToUi(this.System, this.Root)); if (this.System != null)
element.AndChildren(e => e.AddedToUi(this.System, this.Root));
this.OnChildAdded?.Invoke(this, element); this.OnChildAdded?.Invoke(this, element);
this.SetSortedChildrenDirty(); this.SetSortedChildrenDirty();
element.SetAreaDirty(); element.SetAreaDirty();
@ -588,7 +589,8 @@ namespace MLEM.Ui.Elements {
// upwards to us if the element is auto-positioned // upwards to us if the element is auto-positioned
element.SetAreaDirty(); element.SetAreaDirty();
element.Parent = null; element.Parent = null;
element.AndChildren(e => e.RemovedFromUi()); if (this.System != null)
element.AndChildren(e => e.RemovedFromUi());
this.OnChildRemoved?.Invoke(this, element); this.OnChildRemoved?.Invoke(this, element);
this.SetSortedChildrenDirty(); this.SetSortedChildrenDirty();
} }
@ -1256,7 +1258,7 @@ namespace MLEM.Ui.Elements {
/// <summary> /// <summary>
/// Called when this element is added to a <see cref="UiSystem"/> and, optionally, a given <see cref="RootElement"/>. /// Called when this element is added to a <see cref="UiSystem"/> and, optionally, a given <see cref="RootElement"/>.
/// This method is called in <see cref="AddChild{T}"/> and <see cref="UiSystem.Add"/>. /// This method is called in <see cref="AddChild{T}"/> for a parent whose <see cref="System"/> is set, as well as <see cref="UiSystem.Add"/>.
/// </summary> /// </summary>
/// <param name="system">The ui system to add to.</param> /// <param name="system">The ui system to add to.</param>
/// <param name="root">The root element to add to.</param> /// <param name="root">The root element to add to.</param>
@ -1269,7 +1271,7 @@ namespace MLEM.Ui.Elements {
/// <summary> /// <summary>
/// Called when this element is removed from a <see cref="UiSystem"/> and <see cref="RootElement"/>. /// Called when this element is removed from a <see cref="UiSystem"/> and <see cref="RootElement"/>.
/// This method is called in <see cref="RemoveChild"/> and <see cref="UiSystem.Remove"/>. /// This method is called in <see cref="RemoveChild"/> for a parent whose <see cref="System"/> is set, as well as <see cref="UiSystem.Remove"/>.
/// </summary> /// </summary>
protected internal virtual void RemovedFromUi() { protected internal virtual void RemovedFromUi() {
var root = this.Root; var root = this.Root;