Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upMouse.isDown is not just the left button #43
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jonathanhefner
Feb 3, 2015
Contributor
Here are some reasonably not-horrible cross-browser solutions for detecting which mouse button: http://stackoverflow.com/questions/3944122/detect-left-mouse-button-press
One of the comments there mentions a newer event.buttons property which is sufficient by itself, and seems to be supported by current versions of Firefox and Webkit, and by IE 9+:
- https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent.buttons
- https://msdn.microsoft.com/en-us/library/ie/ff974878%28v=vs.85%29.aspx
What is Elm's policy on legacy browser support?
|
Here are some reasonably not-horrible cross-browser solutions for detecting which mouse button: http://stackoverflow.com/questions/3944122/detect-left-mouse-button-press One of the comments there mentions a newer
What is Elm's policy on legacy browser support? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jonathanhefner
Feb 3, 2015
Contributor
Also, I propose to rename Mouse.isDown to something like Mouse.left, with a corresponding Mouse.right.
Another alternative would be to define type MouseButton = None | Left | Right | Middle and have both Mouse.isDown and Mouse.clicks be Signal MouseButton. However, what should the behavior be if e.g. Left and Right are both down? (Send the most recent?)
Given either native solution, I think you can approximate the other in pure Elm, so perhaps the question is: which has least overhead?
|
Also, I propose to rename Another alternative would be to define Given either native solution, I think you can approximate the other in pure Elm, so perhaps the question is: which has least overhead? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
TheSeamau5
Feb 23, 2015
Contributor
+1 for having both Mouse.left and Mouse.right.
As for the general case, I think that having the union type of MouseButton is best left for a library. I think we should match the same behavior as Javascript where we have a signal called Mouse.button which outputs :
- -1: No button pressed
- 0 : Main button pressed, usually the left button
- 1 : Auxiliary button pressed, usually the wheel button or themiddle button (if present)
- 2 : Secondary button pressed, usually the right button
- 3 : Fourth button, typically the Browser Back button
- 4 : Fifth button, typically the Browser Forward button
(from MDN docs)
This is the same kind of logic behind the use of strings for attributes in elm-html as opposed to union types. It allows for the core library to follow the spec as much as possible and then someone can write a "elm-mouse-types" library or something.
Finally, as for legacy browsers, again, it would be up to a library. I would recommend Elm to just focus on the spec. In this case it is just a matter of jumbling some numbers around.
That said, I would recommend normalizing Mouse.left and Mouse.right due to how commonly they are used and doing so like jQuery.
|
+1 for having both As for the general case, I think that having the union type of
(from MDN docs) This is the same kind of logic behind the use of strings for attributes in elm-html as opposed to union types. It allows for the core library to follow the spec as much as possible and then someone can write a "elm-mouse-types" library or something. Finally, as for legacy browsers, again, it would be up to a library. I would recommend Elm to just focus on the spec. In this case it is just a matter of jumbling some numbers around. That said, I would recommend normalizing |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
kasbah
Feb 23, 2015
Contributor
In Helm we have something like:
data MouseButton
= LeftMouse
| MiddleMouse
| RightMouse
| X1Mouse
| X2Mouse
isDownButton :: MouseButton -> Signal BoolisDownButton used to be called isDown but I renamed it and introduced the following to bring it closer to Elm.
isDown :: Signal Bool
isDown = isDownButton LeftMouse|
In Helm we have something like: data MouseButton
= LeftMouse
| MiddleMouse
| RightMouse
| X1Mouse
| X2Mouse
isDownButton :: MouseButton -> Signal Bool
isDown :: Signal Bool
isDown = isDownButton LeftMouse |
evancz
referenced this issue
Jun 12, 2015
Closed
Right-click processed by Mouse "Presses" basic example #34
added a commit
to eeue56/core
that referenced
this issue
Aug 19, 2015
This was referenced Aug 19, 2015
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Not sure the solution, but this stuff lives in |
shaleh commentedDec 11, 2014
The comment in the source says
But in reality it is ANY mouse button. This leads to misbehaviour as described in issue elm/elm-lang.org#184. jQuery's docs say: