@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:
- Constructs a VirtualScroller from its
init()with the owner element and a callback that re-renders the visible window. - Appends pool rows into getRowsContainer.
- Reads getScrollX / getScrollY to determine the visible window.
- Calls clampToContent at the start of
renderWindow(so scroll positions are sane before being used). - Calls layoutScrollbars at the end of
renderWindowwith the current content sizes; the scroller applies the final clamp and positions the scrollbars.
Constructors
new VirtualScroller()
new VirtualScroller(
owner: Component,
element: HTMLElement,
onScroll: VirtualScrollerOnScroll): VirtualScrollerDefined in: src/typescript/lib/component/container/VirtualScroller.ts:55
Constructs a VirtualScroller and attaches it to the owner element.
Parameters
owner
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
Callback invoked when scroll position changes via user input.
Returns
Methods
clampToContent()
clampToContent(contentWidth: number, contentHeight: number): voidDefined 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()
getRowsContainer(): HTMLElementDefined 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()
getScrollX(): numberDefined in: src/typescript/lib/component/container/VirtualScroller.ts:108
Returns the current horizontal scroll position in pixels.
Returns
number
The current scrollX.
getScrollY()
getScrollY(): numberDefined in: src/typescript/lib/component/container/VirtualScroller.ts:99
Returns the current vertical scroll position in pixels.
Returns
number
The current scrollY.
layoutScrollbars()
layoutScrollbars(contentWidth: number, contentHeight: number): voidDefined 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()
setScrollX(x: number): thisDefined 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()
setScrollY(y: number): thisDefined 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