Skip to content

Commit

Permalink
Merge branch 'main' into 29-stack-overflow-crash-with-panel-scrolling…
Browse files Browse the repository at this point in the history
…-take-2
  • Loading branch information
Ellpeck committed Oct 29, 2024
2 parents 5ee4de6 + 41fb515 commit 63ff6f4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Additions
Fixes
- 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 AddedToUi and RemovedFromUi being called for freshly added or removed children whose parents are not in a ui system

### MLEM.Data
Improvements
Expand Down
10 changes: 6 additions & 4 deletions MLEM.Ui/Elements/Element.cs
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,8 @@ public virtual T AddChild<T>(T element, int index = -1) where T : Element {
index = this.children.Count;
this.children.Insert(index, element);
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.SetSortedChildrenDirty();
element.SetAreaDirty();
Expand All @@ -588,7 +589,8 @@ public virtual void RemoveChild(Element element) {
// upwards to us if the element is auto-positioned
element.SetAreaDirty();
element.Parent = null;
element.AndChildren(e => e.RemovedFromUi());
if (this.System != null)
element.AndChildren(e => e.RemovedFromUi());
this.OnChildRemoved?.Invoke(this, element);
this.SetSortedChildrenDirty();
}
Expand Down Expand Up @@ -1256,7 +1258,7 @@ protected Vector2 TransformInverseAll(Vector2 position) {

/// <summary>
/// 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>
/// <param name="system">The ui system to add to.</param>
/// <param name="root">The root element to add to.</param>
Expand All @@ -1269,7 +1271,7 @@ protected internal virtual void AddedToUi(UiSystem system, RootElement root) {

/// <summary>
/// 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>
protected internal virtual void RemovedFromUi() {
var root = this.Root;
Expand Down

0 comments on commit 63ff6f4

Please sign in to comment.