Skip to content

Commit

Permalink
Feat: Expose trackpad's axis values and add a scrollToPosition meth…
Browse files Browse the repository at this point in the history
…od (#161)

Co-authored-by: Baz Utsahajit <[email protected]>
Co-authored-by: Zyie <[email protected]>
  • Loading branch information
3 people authored May 22, 2024
1 parent 5a62d17 commit 09208e2
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/ScrollBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Graphics,
isMobile,
Point,
PointData,
Ticker,
} from 'pixi.js';
import { Signal } from 'typed-signals';
Expand Down Expand Up @@ -714,6 +715,21 @@ export class ScrollBox extends Container
this.stopRenderHiddenItems();
}

/**
* Scrolls to the given position.
* @param position - x and y position object.
* @param position.x - x position.
* @param position.y - y position.
*/
scrollToPosition({ x, y }: Partial<PointData>)
{
if (x === undefined && y === undefined) return;
this.renderAllItems();
if (x !== undefined) this.scrollX = -x;
if (y !== undefined) this.scrollY = -y;
this.stopRenderHiddenItems();
}

/** Gets component height. */
override get height(): number
{
Expand Down Expand Up @@ -742,6 +758,30 @@ export class ScrollBox extends Container
this.scrollTop();
}

/** Gets the current raw scroll position on the x-axis (Negated Value). */
get scrollX(): number
{
return this._trackpad.xAxis.value;
}

/** Sets the current raw scroll position on the x-axis (Negated Value). */
set scrollX(value: number)
{
this._trackpad.xAxis.value = value;
}

/** Gets the current raw scroll position on the y-axis (Negated Value). */
get scrollY(): number
{
return this._trackpad.yAxis.value;
}

/** Sets the current raw scroll position on the y-axis (Negated Value). */
set scrollY(value: number)
{
this._trackpad.yAxis.value = value;
}

protected update()
{
if (!this.list) return;
Expand Down

0 comments on commit 09208e2

Please sign in to comment.