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

feat: leafwing action for grab #55

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

luan
Copy link

@luan luan commented Feb 8, 2024

Allow using leafwing-input-manager for action binding. See examples/leafwing.rs.

@johanhelsing
Copy link
Owner

Thanks for the PR!

Adding input logic like combos to this crate feels slightly like scope creep. Maybe it could be doable by having an optional dependency on leafwing-input-manager instead? And allow arbitrary actions. Or have some other more flexible way of triggering moves? Perhaps events?

I'm not saying it's a definitive no, just hoping we could avoid having this sort of general purpose input logic here, since it's difficult to get right and cover every use case.

For instance, I believe the PR as it currently is interprets

  1. Mouse down
  2. Modifier down

As a valid key combo, which is probably not what the user would expect.

@luan
Copy link
Author

luan commented Feb 8, 2024

Thanks for the PR!

Adding input logic like combos to this crate feels slightly like scope creep. Maybe it could be doable by having an optional dependency on leafwing-input-manager instead? And allow arbitrary actions. Or have some other more flexible way of triggering moves? Perhaps events?

I'm not saying it's a definitive no, just hoping we could avoid having this sort of general purpose input logic here, since it's difficult to get right and cover every use case.

For instance, I believe the PR as it currently is interprets

  1. Mouse down
  2. Modifier down

As a valid key combo, which is probably not what the user would expect.

Thanks for that feedback! Adding leafwing_input_manager as an optional dependency behind a feature sounds great! I was on the fence about adding another dependency so I slapped this together but just the edge case you described is enough to convince me this is going to be too much logic for this crate.

I'll update the PR with the optional leafwing actions shortly

@luan luan changed the title feat: allow key+mouse modifiers in grab_buttons feat: leafwing action for grab Feb 8, 2024
@luan
Copy link
Author

luan commented Feb 8, 2024

I've added a Action::Grab -- we could do the same for zoom I think but I didn't want to go overboard until you got a chance to give me some more feedback here.

@luan
Copy link
Author

luan commented Feb 8, 2024

FWIW the example I committed using leafwing's chords also has that weird ordering behavior you described, but now the issue is no longer on this crate, which I think is a positive change.

Copy link
Owner

@johanhelsing johanhelsing left a comment

Choose a reason for hiding this comment

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

Looks great!

I think we should probably settle on one default value for grab_buttons, but otherwise this is fine.

src/lib.rs Outdated
grab_buttons: vec![MouseButton::Left, MouseButton::Right, MouseButton::Middle],
#[cfg(feature = "leafwing-input-manager")]
grab_buttons: vec![],
Copy link
Owner

Choose a reason for hiding this comment

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

Hmm... I'm not sure how I feel about changing the defaults based on a feature flag... could lead to subtle surprising behavior/bugs if you have multiple crates that depend on pancam?

Copy link
Author

Choose a reason for hiding this comment

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

I didn't want to have the default be using standard input if one requested leafwing. I made a big change around this now (will detail it in the main thread).

src/lib.rs Outdated
/// This is only available when the `leafwing-input-manager` feature is enabled
#[derive(Actionlike, PartialEq, Eq, Hash, Clone, Copy, Debug, Reflect)]
#[cfg(feature = "leafwing-input-manager")]
pub enum Action {
Copy link
Owner

Choose a reason for hiding this comment

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

Action feels maybe a bit too broad and it will probably have to be aliased when used to make intention clear? Maybe prefixing it PanCamAction is better?

(Honest question) :)

Copy link
Author

Choose a reason for hiding this comment

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

Yeah I think I agree. Initially I assumed Action was "fine" because we're inside the bevy_pancam module, but it's pretty common to use import the type directly (or sometimes even via ::*) which would surely dirty up the namespace.

@johanhelsing
Copy link
Owner

johanhelsing commented Feb 11, 2024

FWIW the example I committed using leafwing's chords also has that weird ordering behavior you described, but now the issue is no longer on this crate, which I think is a positive change.

Yeah, it's quite a subtle thing. If I understand correctly, this is the issue to follow Leafwing-Studios/leafwing-input-manager#49

@luan
Copy link
Author

luan commented Feb 12, 2024

@johanhelsing I pushed a refactor around defaults that consists of a breaking change. The reason for it is I needed to move grab_buttons out of the PanCam component so that we could carry that over to a component that is added via a bundle optionally, this makes it possible to keep leafwing related defaults and regular inputs separate.

Like I said, it does make it breaking, because existing code won't work without some minor corrections (see what I did on the examples).

@johanhelsing
Copy link
Owner

Hey sorry for the late response, but i think i prefer it in a single component. I generally follow the approach of making the common use case dead simple, while making more advanced use cases possible.

I think it's acceptable if leafwing users have to set buttons: vec![]

@johanhelsing
Copy link
Owner

I mean have the features be truly additive. Do you think it's possible? Maybe I'm asking too much, but just thought a not entirely thought through response is better than no response

@luan
Copy link
Author

luan commented Feb 18, 2024

I can certainly do that, but I think it makes for a messier API. The idea that choosing leafwing uses leafwing to setup the default made more sense to me. Unfortunately, it did make it so I had to create a bundle type initializer instead of using the original.

I'll sit down to work on game stuff later tonight, until then if you have any thoughts let me know. If I don't hear back I'll just do what you asked and revert back to the buttons vector default.

@johanhelsing
Copy link
Owner

Thanks, perhaps you're right. I can have another look Thursday or Friday alternatively

@luan luan force-pushed the luan/modifier-keys branch from e07cbd9 to f3229fb Compare February 19, 2024 09:01
@johanhelsing johanhelsing added the enhancement New feature or request label Feb 22, 2024
@luan luan force-pushed the luan/modifier-keys branch from f3229fb to 81439a8 Compare February 23, 2024 06:01
@luan
Copy link
Author

luan commented Feb 23, 2024

I've update it against main although I didn't change it back to default to using the regular input modes. Given your last message I'm not 100% which way you'd prefer to go, but happy to come back to this and get it done either way, just give me a ping.

@luan luan requested a review from johanhelsing March 9, 2024 02:08
@luan luan force-pushed the luan/modifier-keys branch from 82c17bb to f1e9155 Compare April 14, 2024 05:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants