From 6d554faaac32b5e39d7879c402a58ac0ffb2f6f9 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Mon, 8 Nov 2021 02:06:50 +0100 Subject: [PATCH] mark panel children dirty when the scroll bar's max value (the height of the children) changes --- MLEM.Ui/Elements/Panel.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/MLEM.Ui/Elements/Panel.cs b/MLEM.Ui/Elements/Panel.cs index 8562373..7ff137e 100644 --- a/MLEM.Ui/Elements/Panel.cs +++ b/MLEM.Ui/Elements/Panel.cs @@ -221,12 +221,19 @@ namespace MLEM.Ui.Elements { // if there is only one child, then we have just the scroll bar if (this.Children.Count == 1) return; + // the "real" first child is the scroll bar, which we want to ignore var firstChild = this.Children.First(c => c != this.ScrollBar); var lowestChild = this.GetLowestChild(c => c != this.ScrollBar && !c.IsHidden); - // the max value of the scrollbar is the amount of non-scaled pixels taken up by overflowing components var childrenHeight = lowestChild.Area.Bottom - firstChild.Area.Top; - this.ScrollBar.MaxValue = (childrenHeight - this.ChildPaddedArea.Height) / this.Scale; + + // the max value of the scrollbar is the amount of non-scaled pixels taken up by overflowing components + var scrollBarMax = (childrenHeight - this.ChildPaddedArea.Height) / this.Scale; + if (this.ScrollBar.MaxValue != scrollBarMax) { + this.ScrollBar.MaxValue = scrollBarMax; + this.relevantChildrenDirty = true; + } + // the scroller height has the same relation to the scroll bar height as the visible area has to the total height of the panel's content var scrollerHeight = this.ChildPaddedArea.Height / childrenHeight / this.Scale * this.ScrollBar.Area.Height; this.ScrollBar.ScrollerSize = new Vector2(this.ScrollerSize.Value.X, Math.Max(this.ScrollerSize.Value.Y, scrollerHeight));