-
-
Notifications
You must be signed in to change notification settings - Fork 261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change mouse button config to a function (e: Event) => ACTION
#459
base: dev
Are you sure you want to change the base?
Change mouse button config to a function (e: Event) => ACTION
#459
Conversation
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
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.shiftKey
and 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.html
to 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!