1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-10-31 21:00:51 +01:00

Improved Panel performance when adding and removing a lot of children

This commit is contained in:
Ell 2023-11-11 12:40:11 +01:00
parent a233477b1e
commit 1fa563be46
2 changed files with 14 additions and 3 deletions

View file

@ -36,6 +36,7 @@ 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
- Improved Panel performance when adding and removing a lot of children
Fixes
- Fixed panels updating their relevant children too much when the scroll bar is hidden

View file

@ -355,16 +355,26 @@ namespace MLEM.Ui.Elements {
}
private void ScrollChildren() {
this.scrolledChildren.RemoveWhere(c => !c.GetParentTree().Contains(this));
if (!this.scrollOverflow)
if (!this.scrollOverflow) {
if (this.scrolledChildren.Count > 0)
this.scrolledChildren.Clear();
return;
}
// 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)) {
var currentChildren = new HashSet<Element>(this.GetChildren(c => c != this.ScrollBar, true, true));
// scroll all our children (and cache newly added ones)
foreach (var child in currentChildren) {
// if a child was newly added later, the last scroll offset was never applied
if (this.scrolledChildren.Add(child))
child.ScrollOffset.Y -= this.lastScrollOffset;
child.ScrollOffset.Y += (this.lastScrollOffset - this.ScrollBar.CurrentValue);
}
// remove cached scrolled children that aren't our children anymore
this.scrolledChildren.IntersectWith(currentChildren);
this.lastScrollOffset = this.ScrollBar.CurrentValue;
this.relevantChildrenDirty = true;
}