-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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!
@@ -436,6 +436,8 @@ pub enum Event { | |||
|
|||
/// The state of the modifier keys at the time of the event. | |||
modifiers: Modifiers, | |||
|
|||
text: Option<String>, |
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.
Needs a docstring!
How does this compare to Event::Text
?
When should this be used instead of Event::Text
?
When should Event::Text
be used instead of this?
When is it None
?
When is it Some("")
?
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.
How does this compare to Event::Text?
It's the same, but combined. Currently if eframe detects a "text representation" (aka a key combination also represents a character defined by the keyboard layout) eframe emits two events. Once Event::Key for the key combination, once Event::Text with the text representation of it. But this detachment makes it impossible to do custom text input handling. Because one cannot know if a key combination results in a certain "text representation" or not.
When should Event::Text be used instead of this?
If one is only interested in text, but not exactly sure as i don't use this event type
When is it None?
If the key combination doesn't represent a text (more likely a character)
When is it Some("")
Hopefully never :D
{ | ||
// Make sure there is text, and that it is not control characters | ||
// (e.g. delete is sent as "\u{f728}" on macOS). | ||
if !text.is_empty() && text.chars().all(is_printable_char) { | ||
// On some platforms we get here when the user presses Cmd-C (copy), ctrl-W, etc. | ||
// We need to ignore these characters that are side-effects of commands. |
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.
Some of these comment got lost
@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 |
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("ä") }