| 1 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
| 2 | // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0 |
| 3 | |
| 4 | TestCase := Rectangle { |
| 5 | width: 400phx; |
| 6 | height: 400phx; |
| 7 | forward-focus: input2; |
| 8 | |
| 9 | input1 := TextInput { |
| 10 | width: parent.width; |
| 11 | height: 200phx; |
| 12 | Rectangle { |
| 13 | FocusScope { |
| 14 | width: 75%; |
| 15 | key-pressed(event) => { |
| 16 | if (event.text != Key.Shift && event.text != Key.Control) { |
| 17 | received += event.text; |
| 18 | } |
| 19 | accept |
| 20 | } |
| 21 | |
| 22 | if (false) : Rectangle { FocusScope {} } |
| 23 | |
| 24 | input2 := TextInput { |
| 25 | width: 75%; |
| 26 | height: 100%; |
| 27 | } |
| 28 | } |
| 29 | } |
| 30 | Rectangle { |
| 31 | width: 0%; |
| 32 | FocusScope { } |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | property<bool> input1_focused: input1.has_focus; |
| 37 | property<string> input1_text: input1.text; |
| 38 | property<bool> input2_focused: input2.has_focus; |
| 39 | property<string> input2_text: input2.text; |
| 40 | property<string> received; |
| 41 | } |
| 42 | |
| 43 | /* |
| 44 | let instance = TestCase::new().unwrap(); |
| 45 | |
| 46 | assert!(!instance.get_input1_focused()); |
| 47 | assert!(instance.get_input2_focused()); |
| 48 | |
| 49 | slint_testing::send_keyboard_string_sequence(&instance, "Hello"); |
| 50 | assert_eq!(instance.get_input2_text(), "Hello"); |
| 51 | assert_eq!(instance.get_input1_text(), ""); |
| 52 | assert_eq!(instance.get_received(), ""); |
| 53 | |
| 54 | slint_testing::send_keyboard_char(&instance, slint::private_unstable_api::re_exports::Key::Control.into(), true); |
| 55 | slint_testing::send_keyboard_string_sequence(&instance, "ß"); |
| 56 | assert_eq!(instance.get_input2_text(), "Hello"); |
| 57 | assert_eq!(instance.get_input1_text(), ""); |
| 58 | assert_eq!(instance.get_received(), "ß"); |
| 59 | ``` |
| 60 | |
| 61 | ```cpp |
| 62 | auto handle = TestCase::create(); |
| 63 | const TestCase &instance = *handle; |
| 64 | |
| 65 | assert(!instance.get_input1_focused()); |
| 66 | assert(instance.get_input2_focused()); |
| 67 | |
| 68 | slint_testing::send_keyboard_string_sequence(&instance, "Hello"); |
| 69 | assert_eq(instance.get_input2_text(), "Hello"); |
| 70 | assert_eq(instance.get_input1_text(), ""); |
| 71 | assert_eq(instance.get_received(), ""); |
| 72 | |
| 73 | // Control key |
| 74 | slint_testing::send_keyboard_char(&instance, slint::SharedString(u8"\U00000011"), true); |
| 75 | slint_testing::send_keyboard_string_sequence(&instance, "ß"); |
| 76 | assert_eq(instance.get_input2_text(), "Hello"); |
| 77 | assert_eq(instance.get_input1_text(), ""); |
| 78 | assert_eq(instance.get_received(), "ß"); |
| 79 | ``` |
| 80 | */ |
| 81 | |