diff --git a/CHANGELOG.md b/CHANGELOG.md index 0611ecf..d391afe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ Improvements Fixes - Fixed VerticalSpace height parameter being an integer - Fixed text not being pasted into a text field at all if it contains characters that don't match the input rule +- Fixed panels that don't auto-hide their scroll bars ignoring their width for child padding ### MLEM.Data Additions diff --git a/MLEM.Ui/Elements/Panel.cs b/MLEM.Ui/Elements/Panel.cs index 12fa24f..3db62b1 100644 --- a/MLEM.Ui/Elements/Panel.cs +++ b/MLEM.Ui/Elements/Panel.cs @@ -76,12 +76,6 @@ namespace MLEM.Ui.Elements { AutoHideWhenEmpty = autoHideScrollbar, IsHidden = autoHideScrollbar }; - if (autoHideScrollbar) { - this.ScrollBar.OnAutoHide += e => { - this.ChildPadding += new Padding(0, this.ScrollerSize.Value.X + this.ScrollBarOffset, 0, 0) * (e.IsHidden ? -1 : 1); - this.SetAreaDirty(); - }; - } // handle automatic element selection, the scroller needs to scroll to the right location this.OnSelectedElementChanged += (element, otherElement) => { @@ -235,7 +229,13 @@ namespace MLEM.Ui.Elements { // 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.Equals(scrollBarMax, Epsilon)) { + var wasZero = this.ScrollBar.MaxValue <= Epsilon; this.ScrollBar.MaxValue = scrollBarMax; + if (this.ScrollBar.MaxValue <= Epsilon != wasZero) { + // update child padding based on whether the scroll bar is visible + this.ChildPadding += new Padding(0, this.ScrollerSize.Value.X + this.ScrollBarOffset, 0, 0) * (this.ScrollBar.IsHidden ? -1 : 1); + this.SetAreaDirty(); + } this.relevantChildrenDirty = true; }