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: 500px; |
7 | height: 550px; |
8 | background: #ecedeb; |
9 | |
10 | property<[int]> xs: [1, 2, 3]; |
11 | |
12 | VerticalLayout { |
13 | padding: 0px; |
14 | spacing: 0px; |
15 | alignment: start; |
16 | |
17 | for x_[i] in xs: Rectangle { |
18 | background: i == 0 ? red : i == 1 ? green : blue; |
19 | height: 100px; |
20 | VerticalLayout { |
21 | padding: 1px; |
22 | TouchArea { |
23 | clicked => { last_clicked = x_; } |
24 | } |
25 | } |
26 | } |
27 | |
28 | for x_[i] in xs: Rectangle { |
29 | background: i == 0 ? red : i == 1 ? green : blue; |
30 | min-height: 50px; |
31 | HorizontalLayout { |
32 | padding: 1px; |
33 | TouchArea { |
34 | clicked => { last_clicked = 10 + x_; } |
35 | } |
36 | } |
37 | } |
38 | } |
39 | |
40 | property<int> last_clicked; |
41 | } |
42 | /* |
43 | ```cpp |
44 | auto handle = TestCase::create(); |
45 | const TestCase &instance = *handle; |
46 | |
47 | // aim at the padding |
48 | slint_testing::send_mouse_click(&instance, 5., 100.); |
49 | assert_eq(instance.get_last_clicked(), 0); |
50 | |
51 | slint_testing::send_mouse_click(&instance, 5., 455.); |
52 | assert_eq(instance.get_last_clicked(), 0); |
53 | slint_testing::send_mouse_click(&instance, 5., 305.); |
54 | assert_eq(instance.get_last_clicked(), 11); |
55 | slint_testing::send_mouse_click(&instance, 5., 295.); |
56 | assert_eq(instance.get_last_clicked(), 3); |
57 | slint_testing::send_mouse_click(&instance, 5., 95.); |
58 | assert_eq(instance.get_last_clicked(), 1); |
59 | ``` |
60 | |
61 | |
62 | ```rust |
63 | let instance = TestCase::new().unwrap(); |
64 | |
65 | // aim at the padding |
66 | slint_testing::send_mouse_click(&instance, 5., 100.); |
67 | assert_eq!(instance.get_last_clicked(), 0); |
68 | |
69 | |
70 | slint_testing::send_mouse_click(&instance, 5., 455.); |
71 | assert_eq!(instance.get_last_clicked(), 0); |
72 | slint_testing::send_mouse_click(&instance, 5., 305.); |
73 | assert_eq!(instance.get_last_clicked(), 11); |
74 | slint_testing::send_mouse_click(&instance, 5., 295.); |
75 | assert_eq!(instance.get_last_clicked(), 3); |
76 | slint_testing::send_mouse_click(&instance, 5., 95.); |
77 | assert_eq!(instance.get_last_clicked(), 1); |
78 | ``` |
79 | |
80 | ```js |
81 | var instance = new slint.TestCase(); |
82 | |
83 | // aim at the padding |
84 | slintlib.private_api.send_mouse_click(instance, 5., 100.); |
85 | assert.equal(instance.last_clicked, 0); |
86 | |
87 | |
88 | slintlib.private_api.send_mouse_click(instance, 5., 455.); |
89 | assert.equal(instance.last_clicked, 0); |
90 | slintlib.private_api.send_mouse_click(instance, 5., 305.); |
91 | assert.equal(instance.last_clicked, 11); |
92 | slintlib.private_api.send_mouse_click(instance, 5., 295.); |
93 | assert.equal(instance.last_clicked, 3); |
94 | slintlib.private_api.send_mouse_click(instance, 5., 95.); |
95 | assert.equal(instance.last_clicked, 1); |
96 | ``` |
97 | */ |
98 | } |
99 | |
100 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
101 | use i_slint_backend_testing as slint_testing; |
102 | slint_testing::init(); |
103 | let instance = TestCase::new().unwrap(); |
104 | |
105 | // aim at the padding |
106 | slint_testing::send_mouse_click(&instance, x:5., y:100.); |
107 | assert_eq!(instance.get_last_clicked(), 0); |
108 | |
109 | |
110 | slint_testing::send_mouse_click(&instance, x:5., y:455.); |
111 | assert_eq!(instance.get_last_clicked(), 0); |
112 | slint_testing::send_mouse_click(&instance, x:5., y:305.); |
113 | assert_eq!(instance.get_last_clicked(), 11); |
114 | slint_testing::send_mouse_click(&instance, x:5., y:295.); |
115 | assert_eq!(instance.get_last_clicked(), 3); |
116 | slint_testing::send_mouse_click(&instance, x:5., y:95.); |
117 | assert_eq!(instance.get_last_clicked(), 1); |
118 | Ok(()) |
119 | } |