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 | import { LineEdit } from "std-widgets.slint" ; |
6 | |
7 | export component TestCase inherits Window { |
8 | |
9 | callback focus_the_line_edit; |
10 | focus_the_line_edit => { |
11 | le.focus(); |
12 | } |
13 | callback focus_the_focus_scope; |
14 | focus_the_focus_scope => { |
15 | fs.focus(); |
16 | } |
17 | |
18 | callback set_manual(bool); |
19 | set_manual(v) => { |
20 | TextInputInterface.text-input-focused = v; |
21 | } |
22 | |
23 | le := LineEdit { } |
24 | fs := FocusScope { } |
25 | |
26 | out property<bool> focused: TextInputInterface.text-input-focused; |
27 | |
28 | } |
29 | |
30 | /* |
31 | ```rust |
32 | let instance = TestCase::new().unwrap(); |
33 | assert!(!instance.get_focused()); |
34 | instance.invoke_focus_the_line_edit(); |
35 | assert!(instance.get_focused()); |
36 | instance.invoke_focus_the_focus_scope(); |
37 | assert!(!instance.get_focused()); |
38 | instance.invoke_focus_the_line_edit(); |
39 | assert!(instance.get_focused()); |
40 | instance.invoke_set_manual(false); |
41 | assert!(!instance.get_focused()); |
42 | instance.invoke_focus_the_focus_scope(); |
43 | assert!(!instance.get_focused()); |
44 | instance.invoke_focus_the_line_edit(); |
45 | assert!(instance.get_focused()); |
46 | ``` |
47 | |
48 | ```cpp |
49 | auto handle = TestCase::create(); |
50 | const TestCase &instance = *handle; |
51 | assert(!instance.get_focused()); |
52 | instance.invoke_focus_the_line_edit(); |
53 | assert(instance.get_focused()); |
54 | instance.invoke_focus_the_focus_scope(); |
55 | assert(!instance.get_focused()); |
56 | instance.invoke_focus_the_line_edit(); |
57 | assert(instance.get_focused()); |
58 | instance.invoke_set_manual(false); |
59 | assert(!instance.get_focused()); |
60 | instance.invoke_focus_the_focus_scope(); |
61 | assert(!instance.get_focused()); |
62 | instance.invoke_focus_the_line_edit(); |
63 | assert(instance.get_focused()); |
64 | ``` |
65 | |
66 | ```js |
67 | var instance = new slint.TestCase(); |
68 | assert(!instance.focused); |
69 | instance.focus_the_line_edit(); |
70 | assert(instance.focused); |
71 | instance.focus_the_focus_scope(); |
72 | assert(!instance.focused); |
73 | instance.focus_the_line_edit(); |
74 | assert(instance.focused); |
75 | instance.set_manual(false); |
76 | assert(!instance.focused); |
77 | instance.focus_the_focus_scope(); |
78 | assert(!instance.focused); |
79 | instance.focus_the_line_edit(); |
80 | assert(instance.focused); |
81 | ``` |
82 | */ |
83 | } |
84 | |
85 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
86 | use i_slint_backend_testing as slint_testing; |
87 | slint_testing::init(); |
88 | let instance = TestCase::new().unwrap(); |
89 | assert!(!instance.get_focused()); |
90 | instance.invoke_focus_the_line_edit(); |
91 | assert!(instance.get_focused()); |
92 | instance.invoke_focus_the_focus_scope(); |
93 | assert!(!instance.get_focused()); |
94 | instance.invoke_focus_the_line_edit(); |
95 | assert!(instance.get_focused()); |
96 | instance.invoke_set_manual(false); |
97 | assert!(!instance.get_focused()); |
98 | instance.invoke_focus_the_focus_scope(); |
99 | assert!(!instance.get_focused()); |
100 | instance.invoke_focus_the_line_edit(); |
101 | assert!(instance.get_focused()); |
102 | Ok(()) |
103 | } |