From 3e7ddb8b1a60955795349d99e4aa145bf1e0a59f Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sun, 1 Sep 2019 19:53:52 +0200 Subject: [PATCH] add the ability for scroll bars to hide themselves when they're empty --- MLEM.Ui/Elements/Panel.cs | 3 ++- MLEM.Ui/Elements/ScrollBar.cs | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/MLEM.Ui/Elements/Panel.cs b/MLEM.Ui/Elements/Panel.cs index be9c330..4e9e832 100644 --- a/MLEM.Ui/Elements/Panel.cs +++ b/MLEM.Ui/Elements/Panel.cs @@ -27,7 +27,8 @@ namespace MLEM.Ui.Elements { this.ScrollBar = new ScrollBar(Anchor.TopRight, new Vector2(scrollSize.X, 1), scrollSize.Y, 0) { StepPerScroll = 10, OnValueChanged = (element, value) => this.ForceChildrenScroll(), - CanAutoAnchorsAttach = false + CanAutoAnchorsAttach = false, + AutoHideWhenEmpty = true }; this.AddChild(this.ScrollBar); diff --git a/MLEM.Ui/Elements/ScrollBar.cs b/MLEM.Ui/Elements/ScrollBar.cs index 2fe5347..ee9e94d 100644 --- a/MLEM.Ui/Elements/ScrollBar.cs +++ b/MLEM.Ui/Elements/ScrollBar.cs @@ -22,6 +22,8 @@ namespace MLEM.Ui.Elements { this.maxValue = Math.Max(0, value); // force current value to be clamped this.CurrentValue = this.currValue; + if (this.AutoHideWhenEmpty) + this.IsHidden = this.maxValue <= 0; } } private float currValue; @@ -41,6 +43,7 @@ namespace MLEM.Ui.Elements { private bool isMouseHeld; private bool isDragging; private bool isTouchHeld; + public bool AutoHideWhenEmpty; static ScrollBar() { InputHandler.EnableGestures(GestureType.HorizontalDrag, GestureType.VerticalDrag);