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

further panel performance improvements

This commit is contained in:
Ell 2023-11-11 13:02:18 +01:00
parent 5fcee515e2
commit 56a4833a49
4 changed files with 17 additions and 15 deletions

View file

@ -35,7 +35,6 @@ Additions
Improvements Improvements
- Allow scrolling panels to contain other scrolling panels - Allow scrolling panels to contain other scrolling panels
- Allow dropdowns to have scrolling panels - Allow dropdowns to have scrolling panels
- Don't unnecessarily set areas dirty when removing a root element from the ui
- Improved Panel performance when adding and removing a lot of children - Improved Panel performance when adding and removing a lot of children
Fixes Fixes

View file

@ -591,6 +591,7 @@ namespace MLEM.Ui.Elements {
element.AndChildren(e => e.AddedToUi(this.System, this.Root)); 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();
return element; return element;
} }
@ -1341,7 +1342,6 @@ namespace MLEM.Ui.Elements {
protected internal virtual void AddedToUi(UiSystem system, RootElement root) { protected internal virtual void AddedToUi(UiSystem system, RootElement root) {
this.Root = root; this.Root = root;
this.System = system; this.System = system;
this.SetAreaDirty();
this.OnAddedToUi?.Invoke(this); this.OnAddedToUi?.Invoke(this);
root?.InvokeOnElementAdded(this); root?.InvokeOnElementAdded(this);
} }

View file

@ -245,13 +245,12 @@ namespace MLEM.Ui.Elements {
/// <inheritdoc /> /// <inheritdoc />
protected override void OnChildAreaDirty(Element child, bool grandchild) { protected override void OnChildAreaDirty(Element child, bool grandchild) {
base.OnChildAreaDirty(child, grandchild); base.OnChildAreaDirty(child, grandchild);
// we only need to scroll when a grandchild changes, since all of our children are forced if (grandchild && !this.AreaDirty) {
// to be auto-anchored and so will automatically propagate their changes up to us // we only need to scroll when a grandchild changes, since all of our children are forced
if (grandchild) { // to be auto-anchored and so will automatically propagate their changes up to us
this.ScrollChildren(); this.ScrollChildren();
// we also need to re-setup here in case the child is involved in a special GetTotalCoveredArea // we also need to re-setup here in case the child is involved in a special GetTotalCoveredArea
if (!this.AreaDirty) this.ScrollSetup();
this.ScrollSetup();
} }
} }
@ -358,17 +357,16 @@ namespace MLEM.Ui.Elements {
if (!this.scrollOverflow) if (!this.scrollOverflow)
return; return;
// we ignore false grandchildren so that the children of the scroll bar stay in place var currentChildren = new HashSet<Element>();
var currentChildren = new HashSet<Element>(this.GetChildren(c => c != this.ScrollBar, true, true));
// scroll all our children (and cache newly added ones) // scroll all our children (and cache newly added ones)
foreach (var child in currentChildren) { // we ignore false grandchildren so that the children of the scroll bar stay in place
foreach (var child in this.GetChildren(c => c != this.ScrollBar, true, true)) {
// if a child was newly added later, the last scroll offset was never applied // if a child was newly added later, the last scroll offset was never applied
if (this.scrolledChildren.Add(child)) if (this.scrolledChildren.Add(child))
child.ScrollOffset.Y -= this.lastScrollOffset; child.ScrollOffset.Y -= this.lastScrollOffset;
child.ScrollOffset.Y += (this.lastScrollOffset - this.ScrollBar.CurrentValue); child.ScrollOffset.Y += (this.lastScrollOffset - this.ScrollBar.CurrentValue);
currentChildren.Add(child);
} }
// remove cached scrolled children that aren't our children anymore // remove cached scrolled children that aren't our children anymore
this.scrolledChildren.IntersectWith(currentChildren); this.scrolledChildren.IntersectWith(currentChildren);

View file

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