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 | SubElement := Rectangle { |
6 | property text <=> input.text; |
7 | property <bool> has-focus: input.has-focus; |
8 | forward_focus: input; |
9 | input := TextInput { |
10 | width: 100%; |
11 | height: 100%; |
12 | } |
13 | } |
14 | |
15 | TestCase := Rectangle { |
16 | width: 400phx; |
17 | height: 400phx; |
18 | |
19 | callback focus_input1(); |
20 | focus_input1 => { input1.focus(); } |
21 | |
22 | callback focus_input2(); |
23 | focus_input2 => { input2.focus(); } |
24 | |
25 | Rectangle { |
26 | input1 := TextInput { |
27 | width: parent.width; |
28 | height: 200phx; |
29 | } |
30 | } |
31 | |
32 | input2 := SubElement { |
33 | y: 200phx; |
34 | width: parent.width; |
35 | height: 200phx; |
36 | } |
37 | |
38 | if (false) : SubElement { } |
39 | |
40 | property<bool> input1_focused: input1.has_focus; |
41 | property<string> input1_text: input1.text; |
42 | property<bool> input2_focused: input2.has_focus; |
43 | property<string> input2_text: input2.text; |
44 | } |
45 | |
46 | /* |
47 | ```rust |
48 | let instance = TestCase::new().unwrap(); |
49 | assert!(!instance.get_input1_focused()); |
50 | assert!(!instance.get_input2_focused()); |
51 | |
52 | instance.invoke_focus_input1(); |
53 | assert!(instance.get_input1_focused()); |
54 | assert!(!instance.get_input2_focused()); |
55 | |
56 | instance.invoke_focus_input2(); |
57 | assert!(!instance.get_input1_focused()); |
58 | assert!(instance.get_input2_focused()); |
59 | ``` |
60 | |
61 | ```cpp |
62 | auto handle = TestCase::create(); |
63 | const TestCase &instance = *handle; |
64 | assert(!instance.get_input1_focused()); |
65 | assert(!instance.get_input2_focused()); |
66 | |
67 | instance.invoke_focus_input1(); |
68 | assert(instance.get_input1_focused()); |
69 | assert(!instance.get_input2_focused()); |
70 | |
71 | instance.invoke_focus_input2(); |
72 | assert(!instance.get_input1_focused()); |
73 | assert(instance.get_input2_focused()); |
74 | ``` |
75 | |
76 | ```js |
77 | var instance = new slint.TestCase(); |
78 | assert(!instance.input1_focused); |
79 | assert(!instance.input2_focused); |
80 | |
81 | instance.focus_input1(); |
82 | assert(instance.input1_focused); |
83 | assert(!instance.input2_focused); |
84 | |
85 | instance.focus_input2(); |
86 | assert(!instance.input1_focused); |
87 | assert(instance.input2_focused); |
88 | ``` |
89 | */ |
90 | } |
91 | |
92 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
93 | use i_slint_backend_testing as slint_testing; |
94 | slint_testing::init(); |
95 | let instance = TestCase::new().unwrap(); |
96 | assert!(!instance.get_input1_focused()); |
97 | assert!(!instance.get_input2_focused()); |
98 | |
99 | instance.invoke_focus_input1(); |
100 | assert!(instance.get_input1_focused()); |
101 | assert!(!instance.get_input2_focused()); |
102 | |
103 | instance.invoke_focus_input2(); |
104 | assert!(!instance.get_input1_focused()); |
105 | assert!(instance.get_input2_focused()); |
106 | Ok(()) |
107 | } |