π Add mouse buttons to mouse event args #85
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
β¨ What's this?
This PR updates the
MouseEventArgs
to include the currently held down mouse buttons in the same way as we pass in the modifier keys.π Relationships
Provides a helpful step towards #5
π Why do we want this?
After looking into how to implement drag and drop, I decided to investigate how WPF does it, which basically lets controls themselves decide when a drag starts (this because very few controls actually need to support it). So what we want to be able to do is in the
OnMouseMoved
handler check whether the mouse button was pressed while moving the mouse, as this is a pretty good indication we're starting a drag.Problem is: right now we can't.
This PR makes the change to include this information in each of the
MouseEventArgs
objects so that this information becomes available.π How is it done?
The
MouseButtons
struct follows theModifierKeys
struct structure very closely, and works in a similar way. This is then passed into theMouseEventArgs
, which also acts as base class for all other mouse event args.π₯ Breaking changes
The constructors of the mouse event args are public, and they now require an extra parameter, so all previous calls are broken. I considered adding a constructor overload, but I feel it is weird that
MouseButtons
would be optional.π¬ Why not another way?
It may be considered weird that
MouseButtons
is present in even theMouseClickEventArgs
, but it opens up the option of responding to "left and right" click at the same time, and same for scrolling. If we wanted to limit theMouseButtons
to theOnMouseMoved
event, we would have to either introduce a newMouseMoveEventArgs
, which would break all existing overrides of that method (much bigger breaking change), or we would remove theMouseEventArgs
as base class of the other two, which would also have unintended side effects.