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 | export component TestCase inherits Window { |
6 | width: 100phx; |
7 | height: 100phx; |
8 | f1 := FocusScope { |
9 | key-pressed(event) => { |
10 | r1 += event.text; |
11 | return accept; |
12 | } |
13 | |
14 | f2 := FocusScope { |
15 | x: 50px; |
16 | y: 50px; |
17 | width: 50px; |
18 | height: 50px; |
19 | key-pressed(event) => { |
20 | r2 += event.text; |
21 | reject |
22 | } |
23 | } |
24 | } |
25 | |
26 | in property<bool> click-to-focus-on-outer <=> f1.enabled; |
27 | out property<string> r1; |
28 | out property<string> r2; |
29 | out property<bool> correct_focus: !f1.has_focus && f2.has_focus; |
30 | } |
31 | |
32 | /* |
33 | ```rust |
34 | let instance = TestCase::new().unwrap(); |
35 | slint_testing::send_mouse_click(&instance, 70., 70.); |
36 | assert!(instance.get_correct_focus()); |
37 | instance.set_click_to_focus_on_outer(false); |
38 | slint_testing::send_keyboard_string_sequence(&instance, "ok"); |
39 | assert_eq!(instance.get_r1(), "ok"); |
40 | assert_eq!(instance.get_r2(), "ok"); |
41 | ``` |
42 | |
43 | ```cpp |
44 | auto handle = TestCase::create(); |
45 | const TestCase &instance = *handle; |
46 | slint_testing::send_mouse_click(&instance, 70., 70.); |
47 | assert(instance.get_correct_focus()); |
48 | instance.set_click_to_focus_on_outer(false); |
49 | slint_testing::send_keyboard_string_sequence(&instance, "ok"); |
50 | assert_eq(instance.get_r1(), "ok"); |
51 | assert_eq(instance.get_r2(), "ok"); |
52 | ``` |
53 | |
54 | ```js |
55 | var instance = new slint.TestCase(); |
56 | slintlib.private_api.send_mouse_click(instance, 70., 70.); |
57 | assert(instance.correct_focus); |
58 | instance.click_to_focus_on_outer = false; |
59 | slintlib.private_api.send_keyboard_string_sequence(instance, "ok"); |
60 | assert.equal(instance.r1, "ok"); |
61 | assert.equal(instance.r2, "ok"); |
62 | ``` |
63 | */ |
64 | } |
65 | |
66 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
67 | use i_slint_backend_testing as slint_testing; |
68 | slint_testing::init(); |
69 | let instance = TestCase::new().unwrap(); |
70 | slint_testing::send_mouse_click(&instance, x:70., y:70.); |
71 | assert!(instance.get_correct_focus()); |
72 | instance.set_click_to_focus_on_outer(false); |
73 | slint_testing::send_keyboard_string_sequence(&instance, sequence:"ok" ); |
74 | assert_eq!(instance.get_r1(), "ok" ); |
75 | assert_eq!(instance.get_r2(), "ok" ); |
76 | Ok(()) |
77 | } |