public override void Recalculate() { // TODO: clean up this mess var upY = Parent.Bounds.Top + Parent.BorderSize; var downY = Parent.Bounds.Top + Parent.Height - Ui.ScrollBar.DownArrow.Height - BorderSize; var bgHeight = downY - upY - Ui.ScrollBar.UpArrow.Height; var x = _border switch { Border.Left => Parent.Bounds.Left + Parent.BorderSize + _horizontalOffset, Border.Right => Parent.Bounds.Left + Parent.Width - Ui.ScrollBar.UpArrow.Width - Parent.BorderSize + _horizontalOffset, _ => throw new ArgumentOutOfRangeException() }; var scrollPartHeight = Ui.ScrollBar.UpArrow.Height; var upArrowRect = new Rectangle(x, upY, Scroll.Width, scrollPartHeight); _upArrow.SetRect(upArrowRect); var downArrowRect = new Rectangle(x, downY, Scroll.Width, scrollPartHeight); _downArrow.SetRect(downArrowRect); var staticBgHeight = Ui.ScrollBar.VerticalBackground.Height; _backgroundRects = Parts.CreateVertical(bgHeight, staticBgHeight, x, upY + Ui.ScrollBar.UpArrow.Height, Scroll.Width); var parent = (ICanHaveVerticalScrollBar)Parent; var midHeight = CalculateHeightOfMiddlePartOfScrollBar(parent, bgHeight); var fullMidBarHeight = midHeight + BarEndsHeight * 2; var oneScrollHeight = parent.VerticalItemCount <= parent.VerticalMaxVisibleItems ? 0 : (float)(bgHeight - fullMidBarHeight) / parent.VerticalMaxScrollIndex; _draggable.SetMinimumDragDistance((int)oneScrollHeight); _dragMultiplier = (float)Math.Max(Math.Ceiling(1 / oneScrollHeight), 1); var barOffset = (int)Math.Ceiling(oneScrollHeight * parent.VerticalScrollIndex); var barStartY = barOffset + upY + Ui.ScrollBar.UpArrow.Height; _barUpRect = new Rectangle(x, barStartY, Scroll.Width, Ui.ScrollBar.VerticalForegroundStart.Height); var midPos = barStartY + Ui.ScrollBar.VerticalForegroundStart.Height; _barMiddleRects = Parts.CreateVertical(midHeight, Ui.ScrollBar.VerticalForegroundMiddle.Height, x, midPos, Scroll.Width); _barDownRect = new Rectangle(x, midPos + midHeight, Scroll.Width, Ui.ScrollBar.VerticalForegroundEnd.Height); _barHitBox = new Rectangle(x, barStartY, Scroll.Width, fullMidBarHeight); _bgHitBox = new Rectangle(x, upY + scrollPartHeight, Scroll.Width, bgHeight); _draggable.SetRect(_barHitBox); }