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

Added keystrokes to the input #35

Closed
wants to merge 2 commits into from
Closed

Added keystrokes to the input #35

wants to merge 2 commits into from

Conversation

VictorKoenders
Copy link
Contributor

When trying to make a text input component, I found out there's no way to detect what keys were pressed this tick.

The current implementation is lazy, although we might want to make this allocated since the returned iterator borrows the given Context. On the other hand, it's fairly easy to call .collect::<Vec<_>>()

I didn't think a get_key_releases method would be useful, but I'll add it if you think otherwise.

@17cupsofcoffee
Copy link
Owner

This is excellent, had been meaning to get around to adding something like this :)

Couple of comments:

  • 🚲🏠: Could we call this method get_keys_pressed? I feel like that's a bit more consistent with the other methods, and I might add get_keys_down, get_keys_released, etc later on.
  • I think you might be able to simplify the implementation to ctx.input.current_key_state.difference(&ctx.input.previous_key_state). This also has the nice side effects or removing the cloning, and removing the need for the explicit lifetimes on the method.

@VictorKoenders
Copy link
Contributor Author

On second thought, the correct way to handle text is through the Event::TextInput.

Let me close this and try something with that.

@VictorKoenders
Copy link
Contributor Author

Let me know if you still want this PR, but I think the TextInput event supersedes this.

@17cupsofcoffee
Copy link
Owner

I can think of a couple of places where this would come in handy outside of text input - that said, I'll make the above changes myself rather than making you do them, if the text input stuff is what you're mainly interested in :)

@VictorKoenders VictorKoenders mentioned this pull request Dec 14, 2018
@VictorKoenders VictorKoenders deleted the keystrokes branch August 5, 2020 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants