1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-12-26 02:09:24 +01:00

fixed newly added Panel children not scrolling correctly since f6bc206

This commit is contained in:
Ell 2023-08-15 10:30:49 +02:00
parent a119db553f
commit 7720ab0ea5

View file

@ -55,6 +55,7 @@ namespace MLEM.Ui.Elements {
}
private readonly List<Element> relevantChildren = new List<Element>();
private readonly HashSet<Element> scrolledChildren = new HashSet<Element>();
private readonly bool scrollOverflow;
private RenderTarget2D renderTarget;
@ -336,11 +337,16 @@ namespace MLEM.Ui.Elements {
}
private void ScrollChildren() {
this.scrolledChildren.RemoveWhere(c => !c.GetParentTree().Contains(this));
if (!this.scrollOverflow)
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))
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 (this.scrolledChildren.Add(child))
child.ScrollOffset.Y -= this.lastScrollOffset;
child.ScrollOffset.Y += (this.lastScrollOffset - this.ScrollBar.CurrentValue);
}
this.lastScrollOffset = this.ScrollBar.CurrentValue;
this.relevantChildrenDirty = true;
}