davidfig/pixi-viewport

Horizontal dragging by wheel while holding Shift key

blnvdanil opened this issue · 4 comments

Hi! I'm trying to implement horizontal scrolling by wheel. The final result should be if I scroll vertically (by wheel) while holding Shift key, there should be horizontal scrolling on the screen.

The implementation of the drag() plugin does not allow me to do that, because offset of the x axis depends on event.deltaX, but while scrolling vertically it is 0.

Is there any thoughts on how I can do this?

I came up with two solutions, the first one is to add a flag like swapAxes: boolean and implement new plugin, that will listen keydowns and keyups, and switch this flag. Second one is do the same, but inside the drag() plugin. The first solution is the quickest one, because there is the only one change for the drag() plugin.

@davidfig What you think about this?

I like the wheelReverseAxis in the drag plugin. That way in your app, you listen for the shift key (or whatever), and then swap the normal drag() plug with a drag({ wheelReverseAxis: true }) plugin. I'd then swap event.deltaX and event.deltaY if set to true. I probably wouldn't include the key handling in the drag plugin since it feels implementation specific.

I may be wrong, but don't you think, that the name wheelReverseAxis is not completely clear? I think that reverse axes is just reversing their direction, rather than swap x and y axes.

I agree. I think there's already a reverse option that does what you say. Swap or something more descriptive is better.