1 | #![allow (deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/layout"# ] |
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 := Window { |
6 | width: 300phx; |
7 | height: 300phx; |
8 | |
9 | property<[int]> xs: [1, 2, 3]; |
10 | property<[int]> ys: [10, 20, 30]; |
11 | |
12 | VerticalLayout { |
13 | padding: 0px; |
14 | spacing: 0px; |
15 | for x_[i] in xs: HorizontalLayout { |
16 | padding: 0px; |
17 | spacing: 0px; |
18 | for y_[j] in ys: Rectangle { |
19 | TouchArea { |
20 | clicked => { |
21 | last_clicked = x_ + y_; |
22 | } |
23 | } |
24 | Text { text: (x_ + y_); } |
25 | } |
26 | } |
27 | } |
28 | |
29 | property<int> last_clicked; |
30 | } |
31 | /* |
32 | ```cpp |
33 | auto handle = TestCase::create(); |
34 | const TestCase &instance = *handle; |
35 | |
36 | slint_testing::send_mouse_click(&instance, 5., 95.); |
37 | assert_eq(instance.get_last_clicked(), 11); |
38 | slint_testing::send_mouse_click(&instance, 105., 205.); |
39 | assert_eq(instance.get_last_clicked(), 23); |
40 | slint_testing::send_mouse_click(&instance, 95., 195.); |
41 | assert_eq(instance.get_last_clicked(), 12); |
42 | slint_testing::send_mouse_click(&instance, 295., 56.); |
43 | assert_eq(instance.get_last_clicked(), 31); |
44 | ``` |
45 | |
46 | |
47 | ```rust |
48 | let instance = TestCase::new().unwrap(); |
49 | |
50 | slint_testing::send_mouse_click(&instance, 5., 95.); |
51 | assert_eq!(instance.get_last_clicked(), 11); |
52 | slint_testing::send_mouse_click(&instance, 105., 205.); |
53 | assert_eq!(instance.get_last_clicked(), 23); |
54 | slint_testing::send_mouse_click(&instance, 95., 195.); |
55 | assert_eq!(instance.get_last_clicked(), 12); |
56 | slint_testing::send_mouse_click(&instance, 295., 56.); |
57 | assert_eq!(instance.get_last_clicked(), 31); |
58 | |
59 | ``` |
60 | |
61 | ```js |
62 | var instance = new slint.TestCase(); |
63 | |
64 | slintlib.private_api.send_mouse_click(instance, 5., 95.); |
65 | assert.equal(instance.last_clicked, 11); |
66 | slintlib.private_api.send_mouse_click(instance, 105., 205.); |
67 | assert.equal(instance.last_clicked, 23); |
68 | slintlib.private_api.send_mouse_click(instance, 95., 195.); |
69 | assert.equal(instance.last_clicked, 12); |
70 | slintlib.private_api.send_mouse_click(instance, 295., 56.); |
71 | assert.equal(instance.last_clicked, 31); |
72 | ``` |
73 | */ |
74 | } |
75 | |
76 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
77 | use i_slint_backend_testing as slint_testing; |
78 | slint_testing::init(); |
79 | let instance = TestCase::new().unwrap(); |
80 | |
81 | slint_testing::send_mouse_click(&instance, x:5., y:95.); |
82 | assert_eq!(instance.get_last_clicked(), 11); |
83 | slint_testing::send_mouse_click(&instance, x:105., y:205.); |
84 | assert_eq!(instance.get_last_clicked(), 23); |
85 | slint_testing::send_mouse_click(&instance, x:95., y:195.); |
86 | assert_eq!(instance.get_last_clicked(), 12); |
87 | slint_testing::send_mouse_click(&instance, x:295., y:56.); |
88 | assert_eq!(instance.get_last_clicked(), 31); |
89 | |
90 | Ok(()) |
91 | } |