Table of Contents

Class ScrollbarHelper

Namespace
SharpConsoleUI.Helpers
Assembly
SharpConsoleUI.dll

Shared scrollbar geometry, drawing, and hit testing logic. Used by ListControl, TreeControl, and TableControl.

public static class ScrollbarHelper
Inheritance
ScrollbarHelper
Inherited Members

Methods

CalculateDragOffset(int, int, int, int, int, int)

Calculates a new scroll offset from a thumb drag operation.

public static int CalculateDragOffset(int dragDeltaY, int dragStartOffset, int contentAreaHeight, int thumbHeight, int totalItems, int visibleItems)

Parameters

dragDeltaY int

Pixels dragged from start position.

dragStartOffset int

Scroll offset when drag began.

contentAreaHeight int

Total scrollbar height.

thumbHeight int

Current thumb height.

totalItems int

Total number of items.

visibleItems int

Number of visible items.

Returns

int

New scroll offset, clamped to valid range.

DrawVerticalScrollbar(CharacterBuffer, int, int, int, int, int, int, Color, Color, Color)

Draws a vertical scrollbar into the character buffer.

public static void DrawVerticalScrollbar(CharacterBuffer buffer, int x, int startY, int height, int totalItems, int visibleItems, int scrollOffset, Color thumbColor, Color trackColor, Color bgColor)

Parameters

buffer CharacterBuffer
x int
startY int
height int
totalItems int
visibleItems int
scrollOffset int
thumbColor Color
trackColor Color
bgColor Color

GetVerticalGeometry(int, int, int, int)

Calculates vertical scrollbar geometry relative to the content area.

public static (int trackTop, int trackHeight, int thumbY, int thumbHeight) GetVerticalGeometry(int contentAreaHeight, int totalItems, int visibleItems, int scrollOffset)

Parameters

contentAreaHeight int

Total height available for the scrollbar in rows.

totalItems int

Total number of items/rows in the content.

visibleItems int

Number of items/rows visible in the viewport.

scrollOffset int

Current scroll offset (first visible item index).

Returns

(int trackTop, int trackHeight, int thumbY, int thumbHeight)

Geometry tuple: trackTop, trackHeight, thumbY, thumbHeight.

HitTest(int, int, int, int)

Determines which zone of the scrollbar was clicked.

public static ScrollbarHitZone HitTest(int relativeY, int trackHeight, int thumbY, int thumbHeight)

Parameters

relativeY int

Y position relative to the scrollbar top.

trackHeight int

Total scrollbar track height.

thumbY int

Thumb start position within the track.

thumbHeight int

Thumb height.

Returns

ScrollbarHitZone

The hit zone.