Change mouse button config to a function (e: Event) => ACTION#459
Change mouse button config to a function (e: Event) => ACTION#459jamesnakagawa wants to merge 1 commit intoyomotsu:devfrom
(e: Event) => ACTION#459Conversation
| this._isDragging && ( event.buttons & MOUSE_BUTTON.ALL ) > 0 ) { | ||
|
|
||
| this._state = this._state | this.mouseButtons.middle; | ||
|
|
||
| } | ||
|
|
||
| if ( this._isDragging && ( event.buttons & MOUSE_BUTTON.RIGHT ) === MOUSE_BUTTON.RIGHT ) { | ||
|
|
||
| this._state = this._state | this.mouseButtons.right; | ||
| this._state = this._state | this.mouseEventToAction( event ); |
There was a problem hiding this comment.
I was able to simplify this conditional because of this change.
( event.buttons & MOUSE_BUTTON.ALL ) > 0 looks a little weird, and technically it would exclude event.buttons === 8 || event.buttons === 16, which is not a common use case. I wanted the result of the function to match previous behaviour exactly.
| } else if ( ! this._lockedPointer && ( event.buttons & MOUSE_BUTTON.LEFT ) === MOUSE_BUTTON.LEFT || | ||
| ( event.buttons & MOUSE_BUTTON.MIDDLE ) === MOUSE_BUTTON.MIDDLE || | ||
| ( event.buttons & MOUSE_BUTTON.RIGHT ) === MOUSE_BUTTON.RIGHT ) { |
There was a problem hiding this comment.
I do not use MOUSE_BUTTON.ALL here because having ! this._lockedPointer && changes the logic.
(e: Event) => ACTION
|
@yomotsu Just wondering if you had a chance to see this? |
|
Sorry for the delay, I've been busy with house moving. This contains a lot change than I thought...and going to be a breaking change (no compatibility with older versions).
|
|
引っ越しおめでとう! Thank you for the response.
In that case, it could be done using closure:
Could this wait for the next major version of camera-controls? Otherwise, the alternative would be to extend Where a This would be much more verbose, which is why I think you didn't want this feature in the first place. |
|
@yomotsu Any thoughts on this? I'm happy to do another PR or make changes based on the direction you'd like to go. |
|
Sorry again for the delay.
Also, what do you think about the following: Renaming |
|
We could do it that way, yes. If |
|
looking for something like this as I would like to control user pressing ctrl+alt+shift keys and increasing/decreasing deltas appropriately. Is there any help here needed or a rethink to get something like this working? |
9f1d761 to
38c26ca
Compare
Regarding #458,
I propose a new structure for configuring mouse buttons. Instead of a configuration object, user can pass a configuration function which receives an
Event(either wheel event, click event, or contextmenu event) and which returns the intended action they want. With this, user can accessevent.shiftKeyand all other modifier key flags and reliably set them without overly verbose configuration.I have also updated the example at
examples/mouse-drag-with-modifier-keys.htmlto show how it could be used.Lastly, I wrote a custom setter for the previous configuration,
mouseButtons, so that this is not a breaking change.I'm not familiar with the coding conventions of this project, so please excuse if I didn't document something correctly. I look forward to hearing your feedback on my proposal!