mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-02 22:54:36 +00:00
Rename KeyEvent::KeyPress::string to text
It's the textual representation of the key
This commit is contained in:
parent
916ad96ea5
commit
886dd425fc
6 changed files with 24 additions and 24 deletions
|
@ -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,
|
||||
},
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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 });
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue