adjustScroll method

void adjustScroll(
  1. int viewportHeight
)

Adjusts the scroll offset based on the selected row and table height.

Implementation

void adjustScroll(int viewportHeight) {
  if (rows.isEmpty || viewportHeight <= 0) return;
  selectedRowIndex = selectedRowIndex.clamp(0, rows.length - 1);

  if (selectedRowIndex < scrollOffset) {
    scrollOffset = selectedRowIndex;
  } else if (selectedRowIndex >= scrollOffset + viewportHeight) {
    scrollOffset = selectedRowIndex - viewportHeight + 1;
  }
}