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
dragDeltaYintPixels dragged from start position.
dragStartOffsetintScroll offset when drag began.
contentAreaHeightintTotal scrollbar height.
thumbHeightintCurrent thumb height.
totalItemsintTotal number of items.
visibleItemsintNumber 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
bufferCharacterBufferxintstartYintheightinttotalItemsintvisibleItemsintscrollOffsetintthumbColorColortrackColorColorbgColorColor
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
contentAreaHeightintTotal height available for the scrollbar in rows.
totalItemsintTotal number of items/rows in the content.
visibleItemsintNumber of items/rows visible in the viewport.
scrollOffsetintCurrent 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
relativeYintY position relative to the scrollbar top.
trackHeightintTotal scrollbar track height.
thumbYintThumb start position within the track.
thumbHeightintThumb height.
Returns
- ScrollbarHitZone
The hit zone.