Skip to content
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

track interaction from all mouse buttons in UI #2324

Closed
wants to merge 3 commits into from

Conversation

mockersf
Copy link
Member

@mockersf mockersf commented Jun 9, 2021

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.

@github-actions github-actions bot added the S-Needs-Triage This issue needs to be labelled label Jun 9, 2021
@NathanSWard NathanSWard added C-Feature A new feature, making something new possible A-UI Graphical user interfaces, styles, layouts, and widgets and removed S-Needs-Triage This issue needs to be labelled labels Jun 9, 2021
@Weibye
Copy link
Contributor

Weibye commented Jun 9, 2021

What about mice with additional buttons like what is commonly seen with gaming-mice?

@mockersf
Copy link
Member Author

mockersf commented Jun 9, 2021

Thanks, forgot about those... They are now added

Copy link
Member

@alice-i-cecile alice-i-cecile left a 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 {
Copy link
Contributor

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,
}

Copy link
Member Author

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

Copy link
Contributor

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,
}

?

Copy link
Member Author

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh alright

Copy link
Contributor

@NathanSWard NathanSWard Jun 9, 2021

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)

crates/bevy_ui/src/focus.rs Outdated Show resolved Hide resolved
@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Jun 16, 2021
@billyb2
Copy link
Contributor

billyb2 commented Jun 28, 2021

Hey, just checking on the PR. Is there anything that needs to be fixed before it can be merged?

@alice-i-cecile
Copy link
Member

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 :)

@NathanSWard
Copy link
Contributor

I'm still a fan of reusing MouseButton even if it does cost a few most characters to type out.
However other than that, this PR should be good to go

@cart cart added the S-Pre-Relicense This PR was made before Bevy added the Apache license. Cannot be merged or used for other work label Jul 23, 2021
@mockersf mockersf removed the S-Pre-Relicense This PR was made before Bevy added the Apache license. Cannot be merged or used for other work label Jul 24, 2021
@cart
Copy link
Member

cart commented Aug 25, 2021

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).

@cart
Copy link
Member

cart commented Aug 25, 2021

Alternatively, maybe we should rely on event queues instead of component state.

@cart
Copy link
Member

cart commented Aug 25, 2021

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.

@mockersf mockersf closed this Feb 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-UI Graphical user interfaces, styles, layouts, and widgets C-Feature A new feature, making something new possible S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Right click button interactions
6 participants