private static int CalculateHeightOfMiddlePartOfScrollBar(ICanHaveVerticalScrollBar parent, int bgHeight) { int midHeight; if (parent.VerticalItemCount <= parent.VerticalMaxVisibleItems) { midHeight = bgHeight - (BarEndsHeight * 2); } else { midHeight = ((parent.VerticalMaxVisibleItems * bgHeight) / parent.VerticalItemCount) - BarEndsHeight * 2; } if (midHeight >= bgHeight) { midHeight = bgHeight - (BarEndsHeight * 2); } else if (midHeight <= 0) { midHeight = 0; } return(midHeight); }
public VerticalScrollBar(IWindow window, ICanHaveVerticalScrollBar parent, Border border) : base(window, parent) { // scrollbars must be attached to a control Window = window; Parent = parent ?? throw new ArgumentNullException(nameof(parent)); _spriteSheet = Ui.SpriteSheet; _border = border; ZIndex = parent.ZIndex; Visible = true; _upArrow = new IconButtonUsingOverlay(window, this, Ui.ScrollBar.UpArrow, Ui.ScrollBar.ArrowNormalOverlay, Ui.ScrollBar.ArrowPressedOverlay, Rectangle.Empty); _upArrow.SetOnClick(ScrollUp); _downArrow = new IconButtonUsingOverlay(window, this, Ui.ScrollBar.DownArrow, Ui.ScrollBar.ArrowNormalOverlay, Ui.ScrollBar.ArrowPressedOverlay, Rectangle.Empty); _downArrow.SetOnClick(ScrollDown); _draggable = new Draggable(MouseButton.Left, 5); _mouseScrollable = new MouseScrollable(parent, ModifierKeys.None); _mouseScrollable.OnScroll = ScrollMouse; }