From 09208e27567e75999b89422f36569eae8a5779ee Mon Sep 17 00:00:00 2001 From: bbazukun123 Date: Wed, 22 May 2024 17:10:21 +0700 Subject: [PATCH] Feat: Expose trackpad's axis values and add a `scrollToPosition` method (#161) Co-authored-by: Baz Utsahajit Co-authored-by: Zyie <24736175+Zyie@users.noreply.github.com> --- src/ScrollBox.ts | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/ScrollBox.ts b/src/ScrollBox.ts index 4bc95aa..a121280 100644 --- a/src/ScrollBox.ts +++ b/src/ScrollBox.ts @@ -7,6 +7,7 @@ import { Graphics, isMobile, Point, + PointData, Ticker, } from 'pixi.js'; import { Signal } from 'typed-signals'; @@ -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) + { + 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 { @@ -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;