1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-04-29 07:39:06 +02:00

Don't unnecessarily set areas dirty when removing a root element from the ui

This commit is contained in:
Ell 2023-11-11 12:06:28 +01:00
parent 0293ea435e
commit 0fab7fe859
4 changed files with 9 additions and 8 deletions

View file

@ -35,6 +35,7 @@ Additions
Improvements
- Allow scrolling panels to contain other scrolling panels
- Allow dropdowns to have scrolling panels
- Don't unnecessarily set areas dirty when removing a root element from the ui
Fixes
- Fixed panels updating their relevant children too much when the scroll bar is hidden

View file

@ -588,10 +588,12 @@ namespace MLEM.Ui.Elements {
index = this.children.Count;
this.children.Insert(index, element);
element.Parent = this;
element.AndChildren(e => e.AddedToUi(this.System, this.Root));
element.AndChildren(e => {
e.SetAreaDirty();
e.AddedToUi(this.System, this.Root);
});
this.OnChildAdded?.Invoke(this, element);
this.SetSortedChildrenDirty();
element.SetAreaDirty();
return element;
}

View file

@ -232,7 +232,7 @@ namespace MLEM.Ui.Elements {
private void SetTextDirty() {
this.tokenizedText = null;
// only set our area dirty if our size changed as a result of this action
if (!this.AreaDirty && !this.CalcActualSize(this.ParentArea).Equals(this.DisplayArea.Size, Element.Epsilon))
if (!this.AreaDirty && (this.System == null || !this.CalcActualSize(this.ParentArea).Equals(this.DisplayArea.Size, Element.Epsilon)))
this.SetAreaDirty();
}

View file

@ -352,8 +352,8 @@ namespace MLEM.Ui {
var root = new RootElement(name, element, this);
this.rootElements.Add(root);
root.Element.AndChildren(e => {
e.AddedToUi(this, root);
e.SetAreaDirty();
e.AddedToUi(this, root);
});
this.OnRootAdded?.Invoke(root);
root.InvokeOnAddedToUi(this);
@ -371,10 +371,8 @@ namespace MLEM.Ui {
return;
this.rootElements.Remove(root);
this.Controls.SelectElement(root, null);
root.Element.AndChildren(e => {
e.RemovedFromUi();
e.SetAreaDirty();
});
// we don't need to set dirty here since re-adding to a ui will cause dirty state anyway
root.Element.AndChildren(e => e.RemovedFromUi());
this.OnRootRemoved?.Invoke(root);
root.InvokeOnRemovedFromUi(this);
}