From 7720ab0ea51a7fdc4e3ff71e721a9010fac3664a Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Tue, 15 Aug 2023 10:30:49 +0200 Subject: [PATCH] fixed newly added Panel children not scrolling correctly since f6bc206 --- MLEM.Ui/Elements/Panel.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/MLEM.Ui/Elements/Panel.cs b/MLEM.Ui/Elements/Panel.cs index ef1236d..a3771e3 100644 --- a/MLEM.Ui/Elements/Panel.cs +++ b/MLEM.Ui/Elements/Panel.cs @@ -55,6 +55,7 @@ namespace MLEM.Ui.Elements { } private readonly List relevantChildren = new List(); + private readonly HashSet scrolledChildren = new HashSet(); 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; }