Skip to content

Commit

Permalink
fix: scrollbar offset when moving by mouse
Browse files Browse the repository at this point in the history
  • Loading branch information
lumixraku committed Sep 24, 2024
1 parent 6338846 commit d56a7fb
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/engine-render/src/shape/scroll-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,13 +371,15 @@ export class ScrollBar extends BaseScrollBar {
state.stopPropagation();
}));
}

// pointer down then move on scrollbar
this._verticalPointerMoveSub = mainScene.onPointerMove$.subscribeEvent((evt: unknown, _state: EventState) => {
const e = evt as IPointerEvent | IMouseEvent;
if (!this._isVerticalMove) {
return;
}
this._viewport.scrollToBarPos({
y: e.offsetY,
y: e.offsetY - this._viewport.top,
});

this._lastY = e.offsetY;
Expand Down Expand Up @@ -439,6 +441,8 @@ export class ScrollBar extends BaseScrollBar {
this._hoverFunc(this.thumbHoverBackgroundColor!, this.horizonThumbRect!);
}));
}

// events for pointerdown at scrolltrack
if (this.horizonScrollTrack) {
this._eventSub.add(this.horizonScrollTrack.onPointerDown$.subscribeEvent((evt: unknown, state: EventState) => {
const e = evt as IPointerEvent | IMouseEvent;
Expand Down Expand Up @@ -466,13 +470,14 @@ export class ScrollBar extends BaseScrollBar {
}));
}

// pointer down then move on scrollbar
this._horizonPointerMoveSub = mainScene.onPointerMove$.subscribeEvent((evt: unknown, _state: EventState) => {
const e = evt as IPointerEvent | IMouseEvent;
if (!this._isHorizonMove) {
return;
}
this._viewport.scrollToBarPos({
x: e.offsetX,
x: e.offsetX - this._viewport.left,
});
this._lastX = e.offsetX;
mainScene.getEngine()?.setRemainCapture();
Expand Down

0 comments on commit d56a7fb

Please sign in to comment.