-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
track interaction from all mouse buttons in UI #2324
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
Conversation
What about mice with additional buttons like what is commonly seen with gaming-mice? |
Thanks, forgot about those... They are now added |
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.
This is an excellent stop-gap and should be merged.
@@ -9,9 +9,18 @@ use bevy_transform::components::GlobalTransform; | |||
use bevy_window::Windows; | |||
use smallvec::SmallVec; | |||
|
|||
#[derive(Copy, Clone, Eq, PartialEq, Debug)] | |||
pub enum ClickedWith { |
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.
Instead of redefining the mouse buttons, can we just reuse the MouseButton
enum?
pub enum ClickedWith {
Mouse(MouseButton),
Touch,
}
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 didn't do that to avoid adding an extra layer to deconstruct when matching... I would prefer not to, but ok to change if people really feel it's better to reuse and add a layer
Currently it's
Interaction::Clicked(ClickedWith::MouseLeftButton)
With this it would be
Interaction::Clicked(ClickedWith::Mouse(MouseButton::Left))
Which starts to be painful when matching
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.
Why not just make it:
pub enum ClickedWith {
MouseButton,
Touch,
}
?
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.
That would only work if you want to react the same way to any mouse button click, Bevy shouldn't force that on users
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.
Oh alright
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 would prefer not to, but ok to change if people really feel it's better to reuse and add a layer
I'm personally a big fan of reusing stuff we already have.
It's fair that it is more code to write however, it comes at the benefit of reusing existing code which is a net gain. (Especially if MouseButton
were to change for some reason)
Also you could probably change ClickedWith
to just Clicked
to reduce a few characters :)
And you could also then do impl From<MouseButton> for Clicked
However at the end of the day, if most people don't want to reuse MouseButton
I'm fine with leaving it as is. (I just have a preference for re-usability)
Hey, just checking on the PR. Is there anything that needs to be fixed before it can be merged? |
I think we're good to; we're just in a bit of a PR backlog as Cart focuses on getting the rendering rework done. @mockersf has merge power as well now, but I don't think this qualifies as "completely uncontroversial", especially since it's his own PR :) |
I'm still a fan of reusing |
8d11f5c
to
ea13679
Compare
This doesn't behave quite how I would expect it to. If you "press left click", "press right click", then "release right click", it will be in the "hovered" state, despite left click still being clicked. We would need a "stack" to support this correctly (or poll current click state every frame). |
Alternatively, maybe we should rely on event queues instead of component state. |
But that would also be a pretty major change to a system that we plan on changing anyway. Not sure its worth developing new things here when we could be investing that energy in the "next" api. |
Objective
Track interaction from all mouse buttons
Fixes #2322
Solution
I added an enum to the clicked state that specify which mouse button clicked it.