Table of Contents

Class ScrollingHelper

Namespace
SharpConsoleUI.Helpers
Assembly
SharpConsoleUI.dll

Helper class for managing viewport scrolling logic across scrollable controls. Consolidates duplicated scroll adjustment code from TreeControl, ListControl, and DropdownControl.

public static class ScrollingHelper
Inheritance
ScrollingHelper
Inherited Members

Methods

CenterIndexInViewport(int, ref int, int, int)

Centers the selected index in the viewport if possible. Useful for jump operations (PageUp/PageDown, search results).

public static void CenterIndexInViewport(int selectedIndex, ref int scrollOffset, int visibleItems, int totalItems)

Parameters

selectedIndex int

The index to center

scrollOffset int

Reference to the scroll offset field to update

visibleItems int

Number of items visible in the viewport

totalItems int

Total number of items in the list

EnsureIndexVisible(int, ref int, int, int)

Adjusts scroll offset to ensure the selected index is visible in the viewport. If the item is above the viewport, scrolls up. If below, scrolls down.

public static void EnsureIndexVisible(int selectedIndex, ref int scrollOffset, int visibleItems, int totalItems)

Parameters

selectedIndex int

The index that must be visible

scrollOffset int

Reference to the scroll offset field to update

visibleItems int

Number of items visible in the viewport

totalItems int

Total number of items in the list

GetMaxScrollOffset(int, int)

Calculates the maximum scroll offset for a given list.

public static int GetMaxScrollOffset(int totalItems, int visibleItems)

Parameters

totalItems int

Total number of items

visibleItems int

Number of visible items in viewport

Returns

int

Maximum valid scroll offset

IsIndexVisible(int, int, int)

Checks if an index is currently visible in the viewport.

public static bool IsIndexVisible(int index, int scrollOffset, int visibleItems)

Parameters

index int

The index to check

scrollOffset int

Current scroll offset

visibleItems int

Number of items visible in viewport

Returns

bool

True if the index is visible, false otherwise

ScrollByDelta(ref int, int, int, int)

Scrolls the viewport by a relative delta (e.g., mouse wheel, arrow keys).

public static void ScrollByDelta(ref int scrollOffset, int delta, int totalItems, int visibleItems)

Parameters

scrollOffset int

Reference to the scroll offset field to update

delta int

Amount to scroll (positive = down, negative = up)

totalItems int

Total number of items in the list

visibleItems int

Number of items visible in the viewport