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
5TestCase := 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/*
45let instance = TestCase::new().unwrap();
46
47assert!(!instance.get_input1_focused());
48assert!(instance.get_input2_focused());
49
50slint_testing::send_keyboard_string_sequence(&instance, "Hello");
51assert_eq!(instance.get_input2_text(), "Hello");
52assert_eq!(instance.get_input1_text(), "");
53assert_eq!(instance.get_received(), "");
54
55slint_testing::send_keyboard_char(&instance, slint::private_unstable_api::re_exports::Key::Control.into(), true);
56slint_testing::send_keyboard_string_sequence(&instance, "ß");
57assert_eq!(instance.get_input2_text(), "Hello");
58assert_eq!(instance.get_input1_text(), "");
59assert_eq!(instance.get_received(), "ß");
60```
61
62```cpp
63auto handle = TestCase::create();
64const TestCase &instance = *handle;
65
66assert(!instance.get_input1_focused());
67assert(instance.get_input2_focused());
68
69slint_testing::send_keyboard_string_sequence(&instance, "Hello");
70assert_eq(instance.get_input2_text(), "Hello");
71assert_eq(instance.get_input1_text(), "");
72assert_eq(instance.get_received(), "");
73
74// Control key
75slint_testing::send_keyboard_char(&instance, slint::SharedString(u8"\U00000011"), true);
76slint_testing::send_keyboard_string_sequence(&instance, "ß");
77assert_eq(instance.get_input2_text(), "Hello");
78assert_eq(instance.get_input1_text(), "");
79assert_eq(instance.get_received(), "ß");
80```
81*/
82}
83