Simplify KeyEvent

Fold CharacterInput into KeyPressed/KeyReleased and store the "key" as a string.

Also, instead of exposing the KeyCode we're encoding special characters
into the string.
This commit is contained in:
Simon Hausmann 2021-01-21 15:37:17 +01:00
parent db740831ee
commit 9ca87ab312
10 changed files with 223 additions and 463 deletions

View file

@ -426,15 +426,11 @@ impl Item for FocusScope {
fn key_event(self: Pin<&Self>, event: &KeyEvent, _window: &ComponentWindow) -> KeyEventResult {
match event {
KeyEvent::KeyPressed { .. } => {}
KeyEvent::KeyReleased { .. } => {}
KeyEvent::CharacterInput { unicode_scalar, .. } => {
if let Some(char) = std::char::from_u32(*unicode_scalar) {
let key = SharedString::from(char.to_string().as_str());
// FIXME: handle pressed and release in their event
Self::FIELD_OFFSETS.key_pressed.apply_pin(self).emit(&(key.clone(),));
Self::FIELD_OFFSETS.key_released.apply_pin(self).emit(&(key,));
}
KeyEvent::KeyPressed { string, .. } => {
Self::FIELD_OFFSETS.key_pressed.apply_pin(self).emit(&(string.clone(),));
}
KeyEvent::KeyReleased { string, .. } => {
Self::FIELD_OFFSETS.key_released.apply_pin(self).emit(&(string.clone(),));
}
};
KeyEventResult::EventAccepted