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 | |
9 | callback focus_rectangle(); |
10 | focus_rectangle => { rectangle.focus(); } |
11 | |
12 | rectangle := Rectangle { |
13 | width: parent.width; |
14 | height: 200phx; |
15 | forward-focus: input; |
16 | } |
17 | |
18 | input := TextInput { |
19 | y: 200phx; |
20 | width: parent.width; |
21 | height: 200phx; |
22 | } |
23 | |
24 | property<bool> input_focused: input.has_focus; |
25 | } |
26 | |
27 | /* |
28 | ```rust |
29 | let instance = TestCase::new().unwrap(); |
30 | assert!(!instance.get_input_focused()); |
31 | |
32 | instance.invoke_focus_rectangle(); |
33 | assert!(instance.get_input_focused()); |
34 | ``` |
35 | |
36 | ```cpp |
37 | auto handle = TestCase::create(); |
38 | const TestCase &instance = *handle; |
39 | assert(!instance.get_input_focused()); |
40 | |
41 | instance.invoke_focus_rectangle(); |
42 | assert(instance.get_input_focused()); |
43 | ``` |
44 | |
45 | ```js |
46 | var instance = new slint.TestCase(); |
47 | assert(!instance.input_focused); |
48 | |
49 | instance.focus_rectangle(); |
50 | assert(instance.input_focused); |
51 | ``` |
52 | */ |
53 | } |
54 | |
55 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
56 | use i_slint_backend_testing as slint_testing; |
57 | slint_testing::init(); |
58 | let instance = TestCase::new().unwrap(); |
59 | assert!(!instance.get_input_focused()); |
60 | |
61 | instance.invoke_focus_rectangle(); |
62 | assert!(instance.get_input_focused()); |
63 | Ok(()) |
64 | } |