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: focus-scope; |
9 | |
10 | focus-scope := FocusScope {} |
11 | |
12 | FocusScope { |
13 | focus-changed-event => { |
14 | scope-focused = self.has-focus; |
15 | } |
16 | } |
17 | |
18 | property <bool> scope-focused; |
19 | } |
20 | |
21 | /* |
22 | ```rust |
23 | let instance = TestCase::new().unwrap(); |
24 | assert!(!instance.get_scope_focused()); |
25 | slint_testing::send_keyboard_string_sequence(&instance, "\t"); |
26 | assert!(instance.get_scope_focused()); |
27 | slint_testing::send_keyboard_string_sequence(&instance, "\t"); |
28 | assert!(!instance.get_scope_focused()); |
29 | ``` |
30 | |
31 | ```cpp |
32 | auto handle = TestCase::create(); |
33 | const TestCase &instance = *handle; |
34 | assert(!instance.get_scope_focused()); |
35 | slint_testing::send_keyboard_string_sequence(&instance, "\t"); |
36 | assert(instance.get_scope_focused()); |
37 | slint_testing::send_keyboard_string_sequence(&instance, "\t"); |
38 | assert(!instance.get_scope_focused()); |
39 | ``` |
40 | |
41 | ```js |
42 | var instance = new slint.TestCase(); |
43 | assert(!instance.scope_focused); |
44 | slintlib.private_api.send_keyboard_string_sequence(instance, "\t"); |
45 | assert(instance.scope_focused); |
46 | slintlib.private_api.send_keyboard_string_sequence(instance, "\t"); |
47 | assert(!instance.scope_focused); |
48 | ``` |
49 | */ |
50 | } |
51 | |
52 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
53 | use i_slint_backend_testing as slint_testing; |
54 | slint_testing::init(); |
55 | let instance = TestCase::new().unwrap(); |
56 | assert!(!instance.get_scope_focused()); |
57 | slint_testing::send_keyboard_string_sequence(&instance, sequence:" \t" ); |
58 | assert!(instance.get_scope_focused()); |
59 | slint_testing::send_keyboard_string_sequence(&instance, sequence:" \t" ); |
60 | assert!(!instance.get_scope_focused()); |
61 | Ok(()) |
62 | } |