columnAtOffset method

int columnAtOffset(
  1. double dx
)

The visible-column index at a horizontal offset in local coordinates, or -1 when outside the content.

The pinned bands are tested first and in screen space, because that is where they are: a pointer over a pinned column is nowhere near the content offset the same x would mean in the scrolling band.

Implementation

int columnAtOffset(double dx) {
  final layout = _columnLayout;
  if (layout.isEmpty) return -1;
  final logical = _textDirection == TextDirection.ltr ? dx : size.width - dx;
  if (logical < 0 || logical > size.width) return -1;

  if (logical < layout.leadingFrozenWidth) {
    return layout.columnAtOffset(logical);
  }
  final trailingEdge = size.width - layout.trailingFrozenWidth;
  if (layout.trailingFrozenStart < layout.length && logical >= trailingEdge) {
    final index = layout.columnAtOffset(
      layout.totalWidth - (size.width - logical),
    );
    return index >= layout.length ? layout.length - 1 : index;
  }
  return layout.scrollableColumnAtOffset(logical + _horizontalOffset);
}