From b2f7f6775641b7120eba9fe44923fe62798bd5f4 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Wed, 25 Mar 2020 20:51:45 +0000 Subject: [PATCH] Fix and simplify ScrollPanelWidget thumb rect calculation. --- OpenRA.Mods.Common/Widgets/ScrollPanelWidget.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/OpenRA.Mods.Common/Widgets/ScrollPanelWidget.cs b/OpenRA.Mods.Common/Widgets/ScrollPanelWidget.cs index 7bb070b9fe..ea461afc1e 100644 --- a/OpenRA.Mods.Common/Widgets/ScrollPanelWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ScrollPanelWidget.cs @@ -146,13 +146,16 @@ namespace OpenRA.Mods.Common.Widgets UpdateSmoothScrolling(); var rb = RenderBounds; - var scrollbarHeight = rb.Height - 2 * ScrollbarWidth; - var thumbHeight = ContentHeight == 0 ? 0 : Math.Max(MinimumThumbSize, (int)(scrollbarHeight * Math.Min(rb.Height * 1f / ContentHeight, 1f))); - var thumbOrigin = rb.Y + ScrollbarWidth + (int)((scrollbarHeight - thumbHeight) * (-1f * currentListOffset / (ContentHeight - rb.Height))); - if (thumbHeight == scrollbarHeight) - thumbHeight = 0; + // Scroll thumb is only visible if the content does not fit within the panel bounds + var thumbHeight = 0; + var thumbOrigin = rb.Y + ScrollbarWidth; + if (ContentHeight > rb.Height) + { + thumbHeight = Math.Max(MinimumThumbSize, scrollbarHeight * rb.Height / ContentHeight); + thumbOrigin += (int)((scrollbarHeight - thumbHeight) * currentListOffset / (rb.Height - ContentHeight)); + } switch (ScrollBar) {