1 | #![allow (deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/children"# ] |
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: 100phx; |
7 | height: 100phx; |
8 | |
9 | property <int> touch_error; |
10 | property <int> touch1; |
11 | property <int> value; |
12 | |
13 | |
14 | HorizontalLayout { |
15 | spacing: 0; |
16 | padding: 0; |
17 | Rectangle { |
18 | background: orange; |
19 | z: 400; |
20 | TouchArea { |
21 | clicked => { touch_error+=78 } |
22 | } |
23 | } |
24 | |
25 | Rectangle { |
26 | background: green; |
27 | z: 3; |
28 | |
29 | TouchArea { |
30 | clicked => { touch_error+=1 } |
31 | } |
32 | |
33 | for i in [ |
34 | {color: #0f0, value: 8, }, |
35 | {color: #00f, value: 9, }, |
36 | {color: #f00, value: 10, }, |
37 | ] : Rectangle { |
38 | z: 78; |
39 | background: i.color; |
40 | TouchArea { |
41 | clicked => { |
42 | root.value = i.value; |
43 | } |
44 | } |
45 | } |
46 | |
47 | TouchArea { |
48 | clicked => { touch_error+=5 } |
49 | } |
50 | |
51 | TouchArea { |
52 | z: 4; |
53 | clicked => { touch_error+=8 } |
54 | } |
55 | |
56 | } |
57 | |
58 | Rectangle { |
59 | background: pink; |
60 | z: -43; |
61 | |
62 | TouchArea { |
63 | clicked => { touch_error+=1 } |
64 | } |
65 | |
66 | TouchArea { |
67 | clicked => { touch_error+=180 } |
68 | } |
69 | |
70 | TouchArea { |
71 | clicked => { |
72 | debug("HI" ); |
73 | touch1+=1 |
74 | } |
75 | } |
76 | |
77 | TouchArea { |
78 | z: -1; |
79 | clicked => { touch_error+=12 } |
80 | } |
81 | } |
82 | } |
83 | } |
84 | |
85 | /* |
86 | ```cpp |
87 | auto handle = TestCase::create(); |
88 | const TestCase &instance = *handle; |
89 | |
90 | slint_testing::send_mouse_click(&instance, 38, 5.); |
91 | assert_eq(instance.get_touch1(), 0); |
92 | assert_eq(instance.get_value(), 10); |
93 | assert_eq(instance.get_touch_error(), 0); |
94 | |
95 | slint_testing::send_mouse_click(&instance, 95, 5.); |
96 | assert_eq(instance.get_touch1(), 1); |
97 | assert_eq(instance.get_value(), 10); |
98 | assert_eq(instance.get_touch_error(), 0); |
99 | |
100 | ``` |
101 | |
102 | |
103 | ```rust |
104 | let instance = TestCase::new().unwrap(); |
105 | slint_testing::send_mouse_click(&instance, 38., 5.); |
106 | assert_eq!(instance.get_touch1(), 0); |
107 | assert_eq!(instance.get_value(), 10); |
108 | assert_eq!(instance.get_touch_error(), 0); |
109 | |
110 | slint_testing::send_mouse_click(&instance, 95., 5.); |
111 | assert_eq!(instance.get_touch1(), 1); |
112 | assert_eq!(instance.get_value(), 10); |
113 | assert_eq!(instance.get_touch_error(), 0); |
114 | ``` |
115 | |
116 | ```js |
117 | var instance = new slint.TestCase(); |
118 | |
119 | slintlib.private_api.send_mouse_click(instance, 38., 5.); |
120 | assert.equal(instance.touch1, 0); |
121 | assert.equal(instance.value, 10); |
122 | assert.equal(instance.touch_error, 0); |
123 | |
124 | slintlib.private_api.send_mouse_click(instance, 95., 5.); |
125 | assert.equal(instance.touch1, 1); |
126 | assert.equal(instance.value, 10); |
127 | assert.equal(instance.touch_error, 0); |
128 | ``` |
129 | */ |
130 | } |
131 | |
132 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
133 | use i_slint_backend_testing as slint_testing; |
134 | slint_testing::init(); |
135 | let instance = TestCase::new().unwrap(); |
136 | slint_testing::send_mouse_click(&instance, x:38., y:5.); |
137 | assert_eq!(instance.get_touch1(), 0); |
138 | assert_eq!(instance.get_value(), 10); |
139 | assert_eq!(instance.get_touch_error(), 0); |
140 | |
141 | slint_testing::send_mouse_click(&instance, x:95., y:5.); |
142 | assert_eq!(instance.get_touch1(), 1); |
143 | assert_eq!(instance.get_value(), 10); |
144 | assert_eq!(instance.get_touch_error(), 0); |
145 | Ok(()) |
146 | } |