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

Allow users to configure maximum size of chords #21

Closed
Tracked by #55
alice-i-cecile opened this issue Dec 27, 2021 · 3 comments
Closed
Tracked by #55

Allow users to configure maximum size of chords #21

alice-i-cecile opened this issue Dec 27, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@alice-i-cecile
Copy link
Contributor

No description provided.

@alice-i-cecile
Copy link
Contributor Author

Another const generic let's go.

@alice-i-cecile alice-i-cecile removed this from the 0.2 milestone Jan 28, 2022
@alice-i-cecile alice-i-cecile added the blocked Nothing to do yet label Jan 28, 2022
@alice-i-cecile alice-i-cecile removed the blocked Nothing to do yet label Jun 2, 2022
@TimJentzsch
Copy link
Collaborator

TimJentzsch commented Aug 22, 2022

What exactly do you envision here? Should the UserInput struct have the const generic which is then passed to the chord case instead of the 8?

Should the chord method stay as an iterator? What happens if the iterator has more items than are allowed?

Relevant code for future reference:

/// A combination of buttons, pressed simultaneously
///
/// Up to 8 (!!) buttons can be chorded together at once.
/// Chords are considered to belong to all of the [InputMode]s of their constituent buttons.
Chord(PetitSet<InputKind, 8>),

/// Creates a [`UserInput::Chord`] from an iterator of [`InputKind`]s
///
/// If `inputs` has a length of 1, a [`UserInput::Single`] variant will be returned instead.
pub fn chord(inputs: impl IntoIterator<Item = impl Into<InputKind>>) -> Self {
// We can't just check the length unless we add an ExactSizeIterator bound :(
let mut length: u8 = 0;
let mut set: PetitSet<InputKind, 8> = PetitSet::default();
for button in inputs {
length += 1;
set.insert(button.into());
}
match length {
1 => UserInput::Single(set.into_iter().next().unwrap()),
_ => UserInput::Chord(set),
}
}

@alice-i-cecile
Copy link
Contributor Author

Should the UserInput struct have the const generic which is then passed to the chord case instead of the 8?

This is the idea; but set a default value of 8 to avoid ergonomics regression.

Should the chord method stay as an iterator? What happens if the iterator has more items than are allowed?

This is the same situation as we have now. We should probably have a fallible version that returns a result for dynamic keybinding use cases.

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

No branches or pull requests

2 participants