diff --git a/CHANGELOG.md b/CHANGELOG.md index 897c67c..2b4635b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ Improvements - Allow style properties to set style values with a higher priority, which allows elements to style their default children - Allow changing the entire ui style for a single element - Skip unnecessary area updates for elements with dirty parents +- Calculate panel scroll bar height based on content height Fixes - Fixed VerticalSpace height parameter being an integer diff --git a/MLEM.Ui/Elements/Panel.cs b/MLEM.Ui/Elements/Panel.cs index b66fb77..8562373 100644 --- a/MLEM.Ui/Elements/Panel.cs +++ b/MLEM.Ui/Elements/Panel.cs @@ -39,7 +39,8 @@ namespace MLEM.Ui.Elements { /// public StyleProp StepPerScroll; /// - /// The size that the 's scroller should have, in pixels + /// The size that the 's scroller should have, in pixels. + /// The scroller size's height specified here is the minimum height, otherwise, it is automatically calculated based on panel content. /// public StyleProp ScrollerSize; @@ -225,7 +226,10 @@ namespace MLEM.Ui.Elements { 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.Area.Height) / this.Scale + this.ChildPadding.Value.Height; + this.ScrollBar.MaxValue = (childrenHeight - this.ChildPaddedArea.Height) / this.Scale; + // 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)); // update the render target var targetArea = (Rectangle) this.GetRenderTargetArea(); @@ -253,7 +257,6 @@ namespace MLEM.Ui.Elements { return; this.ScrollBar.StepPerScroll = this.StepPerScroll; this.ScrollBar.Size = new Vector2(this.ScrollerSize.Value.X, 1); - this.ScrollBar.ScrollerSize = this.ScrollerSize; this.ScrollBar.PositionOffset = new Vector2(-this.ScrollerSize.Value.X - 1, 0); }