Skip to content

@jimka/typescript-ui / component/container / VirtualScroller

Class: VirtualScroller

Defined in: src/typescript/lib/component/container/VirtualScroller.ts:34

Shared scroll machinery for transform-based virtual lists (e.g. table body, tree). Owns the rows-container element, two custom Scrollbar overlays (vertical + horizontal), and the wheel/touch handlers with 2-axis fling momentum.

The owner component:

  1. Constructs a VirtualScroller from its init() with the owner element and a callback that re-renders the visible window.
  2. Appends pool rows into getRowsContainer.
  3. Reads getScrollX / getScrollY to determine the visible window.
  4. Calls clampToContent at the start of renderWindow (so scroll positions are sane before being used).
  5. Calls layoutScrollbars at the end of renderWindow with the current content sizes; the scroller applies the final clamp and positions the scrollbars.

Constructors

new VirtualScroller()

ts
new VirtualScroller(
   owner: Component, 
   element: HTMLElement, 
   onScroll: VirtualScrollerOnScroll): VirtualScroller

Defined in: src/typescript/lib/component/container/VirtualScroller.ts:55

Constructs a VirtualScroller and attaches it to the owner element.

Parameters

owner

Component

The component being scrolled (used for getWidth/getHeight).

element

HTMLElement

The owner's root DOM element. Must already exist; call this from the owner's init() after super.init(element).

onScroll

VirtualScrollerOnScroll

Callback invoked when scroll position changes via user input.

Returns

VirtualScroller

Methods

clampToContent()

ts
clampToContent(contentWidth: number, contentHeight: number): void

Defined in: src/typescript/lib/component/container/VirtualScroller.ts:167

Loose clamp using full viewports (no cross-axis scrollbar reservation). Call at the start of renderWindow so scrollX/Y are within range before being used for window calculations — important when content has shrunk since the last frame. Does not fire onScroll.

Parameters

contentWidth

number

The total scrollable content width in pixels.

contentHeight

number

The total scrollable content height in pixels.

Returns

void


getRowsContainer()

ts
getRowsContainer(): HTMLElement

Defined in: src/typescript/lib/component/container/VirtualScroller.ts:90

Returns the rows-container element. Owners append pool rows here so they participate in the transform-based scroll.

Returns

HTMLElement

The rows-container DOM element.


getScrollX()

ts
getScrollX(): number

Defined in: src/typescript/lib/component/container/VirtualScroller.ts:108

Returns the current horizontal scroll position in pixels.

Returns

number

The current scrollX.


getScrollY()

ts
getScrollY(): number

Defined in: src/typescript/lib/component/container/VirtualScroller.ts:99

Returns the current vertical scroll position in pixels.

Returns

number

The current scrollY.


layoutScrollbars()

ts
layoutScrollbars(contentWidth: number, contentHeight: number): void

Defined in: src/typescript/lib/component/container/VirtualScroller.ts:198

Tight clamp using effective viewports (each axis subtracts the cross-axis scrollbar's track width when it is visible), then positions the scrollbars and pushes metrics. Call at end of renderWindow.

Parameters

contentWidth

number

The total scrollable content width in pixels.

contentHeight

number

The total scrollable content height in pixels.

Returns

void


setScrollX()

ts
setScrollX(x: number): this

Defined in: src/typescript/lib/component/container/VirtualScroller.ts:142

Sets the horizontal scroll position. Clamped against the last-known content width and viewport width. Triggers the owner's onScroll callback if the position changed.

Parameters

x

number

The new scroll position in pixels.

Returns

this


setScrollY()

ts
setScrollY(y: number): this

Defined in: src/typescript/lib/component/container/VirtualScroller.ts:119

Sets the vertical scroll position. Clamped against the last-known content height and viewport height. Triggers the owner's onScroll callback if the position changed.

Parameters

y

number

The new scroll position in pixels.

Returns

this