Class SelectionStateHelper
- Namespace
- SharpConsoleUI.Helpers
- Assembly
- SharpConsoleUI.dll
Helper class for managing selection state updates across controls. Eliminates code duplication and prevents double event firing bugs.
public static class SelectionStateHelper
- Inheritance
-
SelectionStateHelper
- Inherited Members
Methods
UpdateSelection(ref int, int, int, Action<int>?)
Updates selection index with proper guard clause to prevent duplicate events.
public static bool UpdateSelection(ref int currentIndex, int newIndex, int maxIndex, Action<int>? onChanged = null)
Parameters
currentIndexintReference to the current selected index field
newIndexintThe new index to select
maxIndexintMaximum valid index (exclusive upper bound)
onChangedAction<int>Optional callback invoked once if selection changed
Returns
- bool
True if selection changed, false otherwise
UpdateSelectionByOffset(ref int, int, int, Action<int>?)
Updates selection by relative offset (e.g., +1 for down, -1 for up).
public static bool UpdateSelectionByOffset(ref int currentIndex, int offset, int maxIndex, Action<int>? onChanged = null)
Parameters
currentIndexintReference to the current selected index field
offsetintOffset to apply (positive for down, negative for up)
maxIndexintMaximum valid index (exclusive upper bound)
onChangedAction<int>Optional callback invoked once if selection changed
Returns
- bool
True if selection changed, false otherwise
UpdateSelectionByPage(ref int, int, int, int, Action<int>?)
Updates selection by page offset (PageUp/PageDown).
public static bool UpdateSelectionByPage(ref int currentIndex, int pageSize, int direction, int maxIndex, Action<int>? onChanged = null)
Parameters
currentIndexintReference to the current selected index field
pageSizeintNumber of items per page
directionintDirection: 1 for PageDown, -1 for PageUp
maxIndexintMaximum valid index (exclusive upper bound)
onChangedAction<int>Optional callback invoked once if selection changed
Returns
- bool
True if selection changed, false otherwise
UpdateSelectionWithScroll(ref int, int, int, ref int, int, Action<int>?)
Updates selection and adjusts scroll offset to ensure item is visible. Combines selection update with viewport scrolling logic.
public static bool UpdateSelectionWithScroll(ref int currentIndex, int newIndex, int maxIndex, ref int scrollOffset, int visibleItems, Action<int>? onChanged = null)
Parameters
currentIndexintReference to the current selected index field
newIndexintThe new index to select
maxIndexintMaximum valid index (exclusive upper bound)
scrollOffsetintReference to the scroll offset field
visibleItemsintNumber of items visible in viewport
onChangedAction<int>Optional callback invoked once if selection changed
Returns
- bool
True if selection changed, false otherwise