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
selectedIndexintThe index to center
scrollOffsetintReference to the scroll offset field to update
visibleItemsintNumber of items visible in the viewport
totalItemsintTotal 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
selectedIndexintThe index that must be visible
scrollOffsetintReference to the scroll offset field to update
visibleItemsintNumber of items visible in the viewport
totalItemsintTotal 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
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
indexintThe index to check
scrollOffsetintCurrent scroll offset
visibleItemsintNumber 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)