From 886dd425fc8528efcee26254bb6912e8f141b46e Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Fri, 22 Jan 2021 10:33:15 +0100 Subject: [PATCH] Rename KeyEvent::KeyPress::string to text It's the textual representation of the key --- sixtyfps_runtime/corelib/input.rs | 4 ++-- sixtyfps_runtime/corelib/items.rs | 8 ++++---- sixtyfps_runtime/corelib/items/text.rs | 16 ++++++++-------- sixtyfps_runtime/corelib/tests.rs | 6 +++--- .../rendering_backends/gl/eventloop.rs | 8 ++++---- .../rendering_backends/qt/qt_window.rs | 6 +++--- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/sixtyfps_runtime/corelib/input.rs b/sixtyfps_runtime/corelib/input.rs index b9080c59d..6af319f50 100644 --- a/sixtyfps_runtime/corelib/input.rs +++ b/sixtyfps_runtime/corelib/input.rs @@ -245,14 +245,14 @@ pub enum KeyEvent { /// A key on a keyboard was pressed. KeyPressed { /// The unicode representation of the key pressed. - string: SharedString, + text: SharedString, /// The keyboard modifiers active at the time of the key press event. modifiers: KeyboardModifiers, }, /// A key on a keyboard was released. KeyReleased { /// The unicode representation of the key released. - string: SharedString, + text: SharedString, /// The keyboard modifiers active at the time of the key release event. modifiers: KeyboardModifiers, }, diff --git a/sixtyfps_runtime/corelib/items.rs b/sixtyfps_runtime/corelib/items.rs index ee67a417f..57ae09531 100644 --- a/sixtyfps_runtime/corelib/items.rs +++ b/sixtyfps_runtime/corelib/items.rs @@ -426,11 +426,11 @@ impl Item for FocusScope { fn key_event(self: Pin<&Self>, event: &KeyEvent, _window: &ComponentWindow) -> KeyEventResult { match event { - KeyEvent::KeyPressed { string, .. } => { - Self::FIELD_OFFSETS.key_pressed.apply_pin(self).emit(&(string.clone(),)); + KeyEvent::KeyPressed { text, .. } => { + Self::FIELD_OFFSETS.key_pressed.apply_pin(self).emit(&(text.clone(),)); } - KeyEvent::KeyReleased { string, .. } => { - Self::FIELD_OFFSETS.key_released.apply_pin(self).emit(&(string.clone(),)); + KeyEvent::KeyReleased { text, .. } => { + Self::FIELD_OFFSETS.key_released.apply_pin(self).emit(&(text.clone(),)); } }; KeyEventResult::EventAccepted diff --git a/sixtyfps_runtime/corelib/items/text.rs b/sixtyfps_runtime/corelib/items/text.rs index 6cb2f2f77..06d359cfd 100644 --- a/sixtyfps_runtime/corelib/items/text.rs +++ b/sixtyfps_runtime/corelib/items/text.rs @@ -270,8 +270,8 @@ impl Item for TextInput { } match event { - KeyEvent::KeyPressed { string, modifiers } => { - if let Some(keycode) = InternalKeyCode::try_decode_from_string(string) { + KeyEvent::KeyPressed { text, modifiers } => { + if let Some(keycode) = InternalKeyCode::try_decode_from_string(text) { if let Ok(text_cursor_movement) = TextCursorDirection::try_from(keycode.clone()) { TextInput::move_cursor( @@ -294,15 +294,15 @@ impl Item for TextInput { } KeyEventResult::EventIgnored } - KeyEvent::KeyReleased { string, modifiers } + KeyEvent::KeyReleased { text: event_text, modifiers } // Only insert/interpreter non-control character strings - if !string.is_empty() && string.as_str().chars().all(|ch| !ch.is_control()) => + if !event_text.is_empty() && event_text.as_str().chars().all(|ch| !ch.is_control()) => { if modifiers.test_exclusive(crate::input::COPY_PASTE_MODIFIER) { - if string == "c" { + if event_text == "c" { self.copy(); return KeyEventResult::EventAccepted; - } else if string == "v" { + } else if event_text == "v" { self.paste(); return KeyEventResult::EventAccepted; } @@ -313,10 +313,10 @@ impl Item for TextInput { // FIXME: respect grapheme boundaries let insert_pos = self.cursor_position() as usize; - text.insert_str(insert_pos, &string); + text.insert_str(insert_pos, &event_text); self.as_ref().text.set(text.into()); - let new_cursor_pos = (insert_pos + string.len()) as i32; + let new_cursor_pos = (insert_pos + event_text.len()) as i32; self.as_ref().cursor_position.set(new_cursor_pos); self.as_ref().anchor_position.set(new_cursor_pos); diff --git a/sixtyfps_runtime/corelib/tests.rs b/sixtyfps_runtime/corelib/tests.rs index fe1717d2e..d79bc1025 100644 --- a/sixtyfps_runtime/corelib/tests.rs +++ b/sixtyfps_runtime/corelib/tests.rs @@ -73,9 +73,9 @@ pub extern "C" fn send_keyboard_string_sequence( if ch.is_ascii_uppercase() { modifiers |= SHIFT_MODIFIER; } - let string: SharedString = ch.to_string().into(); + let text: SharedString = ch.to_string().into(); - window.process_key_input(&KeyEvent::KeyPressed { string: string.clone(), modifiers }); - window.process_key_input(&KeyEvent::KeyReleased { string, modifiers }); + window.process_key_input(&KeyEvent::KeyPressed { text: text.clone(), modifiers }); + window.process_key_input(&KeyEvent::KeyReleased { text, modifiers }); } } diff --git a/sixtyfps_runtime/rendering_backends/gl/eventloop.rs b/sixtyfps_runtime/rendering_backends/gl/eventloop.rs index 783b73dc2..85c141546 100644 --- a/sixtyfps_runtime/rendering_backends/gl/eventloop.rs +++ b/sixtyfps_runtime/rendering_backends/gl/eventloop.rs @@ -319,14 +319,14 @@ pub fn run() { } }) { - let string = key_code.encode_to_string(); + let text = key_code.encode_to_string(); let event = match input.state { winit::event::ElementState::Pressed => KeyEvent::KeyPressed { - string, + text, modifiers: window.current_keyboard_modifiers(), }, winit::event::ElementState::Released => KeyEvent::KeyReleased { - string, + text, modifiers: window.current_keyboard_modifiers(), }, }; @@ -357,7 +357,7 @@ pub fn run() { if !modifiers.control() && !modifiers.alt() && !modifiers.logo() { let key_event = KeyEvent::KeyReleased { - string: ch.to_string().into(), + text: ch.to_string().into(), modifiers, }; window diff --git a/sixtyfps_runtime/rendering_backends/qt/qt_window.rs b/sixtyfps_runtime/rendering_backends/qt/qt_window.rs index 9f3d715d5..f7e231846 100644 --- a/sixtyfps_runtime/rendering_backends/qt/qt_window.rs +++ b/sixtyfps_runtime/rendering_backends/qt/qt_window.rs @@ -661,7 +661,7 @@ impl QtWindow { modifiers |= sixtyfps_corelib::input::LOGO_MODIFIER } - let string = match key as key_generated::Qt_Key { + let text = match key as key_generated::Qt_Key { key_generated::Qt_Key_Key_Left => Some(InternalKeyCode::Left), key_generated::Qt_Key_Key_Right => Some(InternalKeyCode::Right), key_generated::Qt_Key_Key_Backspace => Some(InternalKeyCode::Back), @@ -674,9 +674,9 @@ impl QtWindow { .map_or_else(|| text.into(), |code| code.encode_to_string()); let event = if released { - KeyEvent::KeyReleased { string, modifiers } + KeyEvent::KeyReleased { text, modifiers } } else { - KeyEvent::KeyPressed { string, modifiers } + KeyEvent::KeyPressed { text, modifiers } }; self.self_weak.get().unwrap().upgrade().unwrap().process_key_input(&event);