pixi-viewport icon indicating copy to clipboard operation
pixi-viewport copied to clipboard

Drag vs wheel plugin in paused state

Open irothschild opened this issue 5 years ago • 3 comments

If both drag and wheel plugins are used, the drag plugin doesn't handle the wheel events. That makes sense. But the check is:

            const wheel = this.parent.plugins.get('wheel')
            if (!wheel)

https://github.com/davidfig/pixi-viewport/blob/master/src/plugins/drag.js#L269

I think it would be better if it also checks whether the wheel plugin is not paused. (There are also a bunch of similar checks for a plugin (ex. pinch) where it checks existence but not paused state.)

My use case is I want the wheel to scroll (ie. only drag plugin active) but while holding down the shift key, the wheel plugin resumes and does zooming.

Seems like a one line change but maybe I'm missing the full implications?

irothschild avatar May 26 '20 11:05 irothschild

If you log the plugin you can see its properties.

`const wheel = viewport.plugins.get('wheel');
       
 console.log('WHEEl', wheel);`

You will see the wheel object like so:

`Wheel {parent: Viewport, paused: false, options: {…}}

options: {percent: 0.1, smooth: false, interrupt: true, reverse: false, center: null, …}

parent: Viewport {_events: Events, _eventsCount: 7, tempDisplayObjectParent: null, transform: Transform, alpha: 1, …}
paused: false //<-------- Here is your paused boolean**
__proto__: Plugin`

So you can access it if(!wheel.paused)

jjwallace avatar Sep 15 '20 20:09 jjwallace

Yes, I can access it but the code in drag is simply checking if the plugin is enabled and not whether it's paused.

irothschild avatar Sep 15 '20 21:09 irothschild

Yes, that would be better. Hmm...I probably should add a viewport.plugins.isActive(string) and check both the existence of the plugin and whether it's paused.

Ok, all fixed in v4.14.0. I added an ignorePaused option to viewport.plugin.get and used that through the code to ensure that paused plugins are not used to alter behavior. Good catch.

davidfig avatar Sep 16 '20 22:09 davidfig