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

Split UserInput into multiple traits #535

Closed
alice-i-cecile opened this issue Jun 10, 2024 · 5 comments · Fixed by #548
Closed

Split UserInput into multiple traits #535

alice-i-cecile opened this issue Jun 10, 2024 · 5 comments · Fixed by #548
Labels
code-quality Make the code faster or prettier controversial Requires a heightened standard of review usability Reduce user friction
Milestone

Comments

@alice-i-cecile
Copy link
Contributor

alice-i-cecile commented Jun 10, 2024

I had previously considered splitting it into different input kinds: Button, Axis, DualAxis, etc.; and there are corresponding data types for each. Then, modify the ActionState API, something like this:

if let ButtonState(state) = action_state.get(ButtonAction) {
   let pressed = state.pressed;
   let pressure = state.pressure; // Gamepad buttons are ranging from 0 to 1, and others are 0 or 1
}
if let AxisValue(value: f32) = action_state.get(AxisAction) {
}

Originally posted by @Shute052 in #490 (comment)

@alice-i-cecile alice-i-cecile added code-quality Make the code faster or prettier usability Reduce user friction controversial Requires a heightened standard of review labels Jun 10, 2024
@alice-i-cecile alice-i-cecile added this to the Trait-driven design milestone Jun 10, 2024
@alice-i-cecile
Copy link
Contributor Author

The basic design I'm going to go with is a core UserInput trait with the bare minimum of functionality.

Then, three other traits that imply UserInput: ButtonlikeInput, SingleAxisInput, DualAxisInput.

@Shute052
Copy link
Collaborator

I was thinking of having an InputData enum for buttons, single-axis inputs, and dual-axis ones.
However, there's an issue with Chord in that context. It can consist of multiple single-axis inputs and multiple dual-axis inputs (but only considers the first dual-axis data).

@alice-i-cecile
Copy link
Contributor Author

Yeah, I think that we need to restrict chords to only contain buttonlike inputs, and then make sure there's general-purpose ways to turn axislikes into buttonlikes.

I'll tackle this and ping you for review :)

@Shute052
Copy link
Collaborator

Shute052 commented Jun 10, 2024

I think that we need to restrict chords to only contain buttonlike inputs

But in some cases, Chord with single-/dual-axis inputs can be really useful. For instance, in my project, I've implemented mouse drag using a Chord.

Perhaps we could consider making a Chord consist of either only buttons, only buttons with single-axis inputs, or only buttons with dual-axis inputs?

@alice-i-cecile
Copy link
Contributor Author

Hmm 🤔 Okay, I'll leave it for now and chew on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code-quality Make the code faster or prettier controversial Requires a heightened standard of review usability Reduce user friction
Projects
None yet
2 participants