-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Feature: Extend EguiEvent::Key of it's text representation #7105
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
base: main
Are you sure you want to change the base?
Feature: Extend EguiEvent::Key of it's text representation #7105
Conversation
c4f25d2
to
dc46a8a
Compare
dc46a8a
to
66f5b26
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR. I need to understand this a bit better though, and a docstring would be a mighty fine way :)
Also: we should implement this on web too!
@emilk If you understand this better and approve it to be the way to go i will write a docstring and add the lost comment back :) |
I think this makes sense, but I still haven't understood a concrete use case for this. If you use What is the concrete problem you are trying to solve? |
I give you an example of what i currently do: I get following events:
|
Thanks for explaining this in more detail! It seems the core need is to be able to match a specific Or rather, maybe it doesn't go far enough 🤔 If we add |
Happy that I could clarify :) If we agree on this i can update this PR to do that. |
go for it! |
78f4fac
to
0673b6a
Compare
@emilk added docstring, deprecated Event::Text and changed all usages in the codebase to Event::Key. |
5f4d47e
to
a3844d6
Compare
a3844d6
to
832db73
Compare
832db73
to
92d27d4
Compare
crates/egui/src/data/input.rs
Outdated
/// Helpful if you relied on creating [`Event::Text`] before it's deprecation. | ||
pub fn from_text(text: String) -> Self { | ||
Self::Key { | ||
key: Key::from_name(&text.chars().nth(0).unwrap_or('a').to_string()).unwrap_or(Key::A), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this at all - this means any non-recognized text will be interpreted as a Key::A
press, which makes no sense
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair! I see following possibilities:
a) Fail if we can't get a Key from the text
b) create a Key::Unknown
c) Make Event::Key.key optional
d) you have a better idea :P
Which one you prefer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went ahead and implemented solution a) as I think it's fine to panic in case text
is empty or the first character is not representable as Key
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@emilk friendly ping (:
…t a valid [`Key`]
This pr adds the text representation of the key to the EguiEvent::Key struct.
This way we get the character that the keyboard layout actually represents and not only
the key combination. For example on EurKey layout, if i press AltRight+A, it's mapped to "ä".
Key { key: A, physical_key: Some(A), pressed: false, repeat: false, modifiers: Modifiers::NONE, text: Some("ä") }