Fix and simplify ScrollPanelWidget thumb rect calculation.

This commit is contained in:
Paul Chote
2020-03-25 20:51:45 +00:00
committed by abcdefg30
parent 09014ab6d5
commit b2f7f67756

View File

@@ -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)
{