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