From 8dcf3d8e63657e2a1702b1557637f97119af2d53 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sat, 14 Dec 2019 14:10:38 +0100 Subject: [PATCH] made disabling scroll bar hiding easier for the panel --- MLEM.Ui/Elements/Panel.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/MLEM.Ui/Elements/Panel.cs b/MLEM.Ui/Elements/Panel.cs index 10300fa..8f56567 100644 --- a/MLEM.Ui/Elements/Panel.cs +++ b/MLEM.Ui/Elements/Panel.cs @@ -19,7 +19,7 @@ namespace MLEM.Ui.Elements { private readonly List relevantChildren = new List(); private bool relevantChildrenDirty; - public Panel(Anchor anchor, Vector2 size, Vector2 positionOffset, bool setHeightBasedOnChildren = false, bool scrollOverflow = false, Point? scrollerSize = null) : base(anchor, size) { + public Panel(Anchor anchor, Vector2 size, Vector2 positionOffset, bool setHeightBasedOnChildren = false, bool scrollOverflow = false, Point? scrollerSize = null, bool autoHideScrollbar = true) : base(anchor, size) { this.PositionOffset = positionOffset; this.SetHeightBasedOnChildren = setHeightBasedOnChildren; this.scrollOverflow = scrollOverflow; @@ -32,13 +32,14 @@ namespace MLEM.Ui.Elements { StepPerScroll = 10, OnValueChanged = (element, value) => this.ScrollChildren(), CanAutoAnchorsAttach = false, - AutoHideWhenEmpty = true, - IsHidden = true + AutoHideWhenEmpty = autoHideScrollbar, + IsHidden = autoHideScrollbar }; // modify the padding so that the scroll bar isn't over top of something else this.ScrollBar.PositionOffset -= new Vector2(scrollSize.X + 1, 0); - this.ScrollBar.OnAutoHide += e => this.ChildPadding += new Padding(0, scrollSize.X, 0, 0) * (e.IsHidden ? -1 : 1); + if (autoHideScrollbar) + this.ScrollBar.OnAutoHide += e => this.ChildPadding += new Padding(0, scrollSize.X, 0, 0) * (e.IsHidden ? -1 : 1); // handle automatic element selection, the scroller needs to scroll to the right location this.OnSelectedElementChanged += (element, otherElement) => {