1 | #![allow (deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/elements"# ] |
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 { |
6 | in-out property <int> touch1; |
7 | in-out property <int> touch2; |
8 | in-out property <int> touch3; |
9 | in-out property <int> touch_double1; |
10 | in-out property <int> touch_double2; |
11 | in-out property <int> touch_double3; |
12 | |
13 | in-out property <string> pointer-event-test; |
14 | |
15 | TouchArea { |
16 | x: 100phx; |
17 | y: 100phx; |
18 | width: 10phx; |
19 | height: 10phx; |
20 | clicked => { touch1+=1; } |
21 | double-clicked => { touch_double1+=1; } |
22 | mouse-cursor: move; |
23 | TouchArea { |
24 | y: 2phx; |
25 | height: 2phx; |
26 | x: 3phx; |
27 | width: 4phx; |
28 | clicked => { touch3+=1; } |
29 | double-clicked => { touch_double3+=1; } |
30 | mouse-cursor: default; |
31 | } |
32 | } |
33 | TouchArea { |
34 | x: 100phx; |
35 | y: 100phx; |
36 | width: 5phx; |
37 | height: 5phx; |
38 | mouse-cursor: pointer; |
39 | clicked => { |
40 | pointer-event-test += "click:" ; |
41 | touch2+=1; |
42 | } |
43 | double-clicked => { |
44 | pointer-event-test += "double_click:" ; |
45 | touch_double2+=1; |
46 | } |
47 | pointer-event(e) => { |
48 | if (e.kind == PointerEventKind.cancel) { |
49 | pointer-event-test += "cancel." ; |
50 | } else if (e.kind == PointerEventKind.up) { |
51 | pointer-event-test += "up." ; |
52 | } else if (e.kind == PointerEventKind.down) { |
53 | pointer-event-test += "down." ; |
54 | } else if (e.kind == PointerEventKind.move) { |
55 | pointer-event-test += "move." ; |
56 | } else { |
57 | pointer-event-test += "err." ; |
58 | } |
59 | if (e.button == PointerEventButton.right) { |
60 | pointer-event-test += "right" ; |
61 | } else if (e.button == PointerEventButton.left) { |
62 | pointer-event-test += "left" ; |
63 | } else if (e.button == PointerEventButton.middle) { |
64 | pointer-event-test += "middle" ; |
65 | } else if (e.button == PointerEventButton.other) { |
66 | pointer-event-test += "other" ; |
67 | } else { |
68 | pointer-event-test += "???" ; |
69 | } |
70 | if (e.modifiers.control) { |
71 | pointer-event-test += "(ctrl)" ; |
72 | } |
73 | if (e.modifiers.shift) { |
74 | pointer-event-test += "(shift)" ; |
75 | } |
76 | if (e.modifiers.meta) { |
77 | pointer-event-test += "(meta)" ; |
78 | } |
79 | if (e.modifiers.alt) { |
80 | pointer-event-test += "(alt)" ; |
81 | } |
82 | pointer-event-test += ":" ; |
83 | } |
84 | } |
85 | } |
86 | |
87 | /* |
88 | ```cpp |
89 | using slint::PointerEventButton; |
90 | |
91 | auto handle = TestCase::create(); |
92 | const TestCase &instance = *handle; |
93 | |
94 | auto double_click = [&](float x, float y) { |
95 | slint_testing::send_mouse_click(&instance, x, y); |
96 | slint_testing::mock_elapsed_time(50); |
97 | slint_testing::send_mouse_click(&instance, x, y); |
98 | }; |
99 | |
100 | // does not click on anything |
101 | slint_testing::send_mouse_click(&instance, 5., 5.); |
102 | assert_eq(instance.get_touch1(), 0); |
103 | assert_eq(instance.get_touch2(), 0); |
104 | assert_eq(instance.get_touch3(), 0); |
105 | assert_eq(instance.get_touch_double1(), 0); |
106 | assert_eq(instance.get_touch_double2(), 0); |
107 | assert_eq(instance.get_touch_double3(), 0); |
108 | |
109 | // click on second one |
110 | slint_testing::mock_elapsed_time(1000); |
111 | slint_testing::send_mouse_click(&instance, 101., 101.); |
112 | assert_eq(instance.get_touch1(), 0); |
113 | assert_eq(instance.get_touch2(), 1); |
114 | assert_eq(instance.get_touch3(), 0); |
115 | assert_eq(instance.get_touch_double1(), 0); |
116 | assert_eq(instance.get_touch_double2(), 0); |
117 | assert_eq(instance.get_touch_double3(), 0); |
118 | |
119 | // click on first one only |
120 | slint_testing::mock_elapsed_time(1000); |
121 | slint_testing::send_mouse_click(&instance, 108., 108.); |
122 | assert_eq(instance.get_touch1(), 1); |
123 | assert_eq(instance.get_touch2(), 1); |
124 | assert_eq(instance.get_touch3(), 0); |
125 | assert_eq(instance.get_touch_double1(), 0); |
126 | assert_eq(instance.get_touch_double2(), 0); |
127 | assert_eq(instance.get_touch_double3(), 0); |
128 | |
129 | // click on the third |
130 | slint_testing::mock_elapsed_time(1000); |
131 | slint_testing::send_mouse_click(&instance, 106., 103.); |
132 | assert_eq(instance.get_touch1(), 1); |
133 | assert_eq(instance.get_touch2(), 1); |
134 | assert_eq(instance.get_touch3(), 1); |
135 | assert_eq(instance.get_touch_double1(), 0); |
136 | assert_eq(instance.get_touch_double2(), 0); |
137 | assert_eq(instance.get_touch_double3(), 0); |
138 | assert_eq(instance.get_pointer_event_test(), "move.other:down.left:click:up.left:move.other:"); |
139 | |
140 | // does not double-click on anything |
141 | slint_testing::mock_elapsed_time(1000); |
142 | double_click(5., 5.); |
143 | assert_eq(instance.get_touch1(), 1); |
144 | assert_eq(instance.get_touch2(), 1); |
145 | assert_eq(instance.get_touch3(), 1); |
146 | assert_eq(instance.get_touch_double1(), 0); |
147 | assert_eq(instance.get_touch_double2(), 0); |
148 | assert_eq(instance.get_touch_double3(), 0); |
149 | |
150 | // double-click on second one |
151 | slint_testing::mock_elapsed_time(1000); |
152 | instance.set_pointer_event_test(""); |
153 | double_click(101., 101.); |
154 | assert_eq(instance.get_touch1(), 1); |
155 | assert_eq(instance.get_touch2(), 3); |
156 | assert_eq(instance.get_touch3(), 1); |
157 | assert_eq(instance.get_touch_double1(), 0); |
158 | assert_eq(instance.get_touch_double2(), 1); |
159 | assert_eq(instance.get_touch_double3(), 0); |
160 | assert_eq(instance.get_pointer_event_test(), "move.other:down.left:click:up.left:move.other:move.other:down.left:click:double_click:up.left:move.other:"); |
161 | |
162 | // double-click on first one only |
163 | slint_testing::mock_elapsed_time(1000); |
164 | double_click(108., 108.); |
165 | assert_eq(instance.get_touch1(), 3); |
166 | assert_eq(instance.get_touch2(), 3); |
167 | assert_eq(instance.get_touch3(), 1); |
168 | assert_eq(instance.get_touch_double1(), 1); |
169 | assert_eq(instance.get_touch_double2(), 1); |
170 | assert_eq(instance.get_touch_double3(), 0); |
171 | |
172 | // double-click on the third |
173 | slint_testing::mock_elapsed_time(1000); |
174 | double_click(106., 103.); |
175 | assert_eq(instance.get_touch1(), 3); |
176 | assert_eq(instance.get_touch2(), 3); |
177 | assert_eq(instance.get_touch3(), 3); |
178 | assert_eq(instance.get_touch_double1(), 1); |
179 | assert_eq(instance.get_touch_double2(), 1); |
180 | assert_eq(instance.get_touch_double3(), 1); |
181 | |
182 | // triple-click on second one |
183 | slint_testing::mock_elapsed_time(1000); |
184 | slint_testing::send_mouse_click(&instance, 106., 103.); |
185 | slint_testing::send_mouse_click(&instance, 106., 103.); |
186 | slint_testing::send_mouse_click(&instance, 106., 103.); |
187 | assert_eq(instance.get_touch1(), 3); |
188 | assert_eq(instance.get_touch2(), 3); |
189 | assert_eq(instance.get_touch3(), 6); |
190 | assert_eq(instance.get_touch_double1(), 1); |
191 | assert_eq(instance.get_touch_double2(), 1); |
192 | assert_eq(instance.get_touch_double3(), 2); |
193 | |
194 | // click quickly on two different mouse areas |
195 | slint_testing::mock_elapsed_time(1000); |
196 | instance.set_pointer_event_test(""); |
197 | slint_testing::mock_elapsed_time(1000); |
198 | slint_testing::send_mouse_click(&instance, 101., 106.); // first |
199 | slint_testing::mock_elapsed_time(20); |
200 | slint_testing::send_mouse_click(&instance, 101., 104.); // second |
201 | instance.window().dispatch_pointer_move_event(slint::LogicalPosition({ 1.0, 1.0 })); |
202 | assert_eq(instance.get_touch1(), 4); |
203 | assert_eq(instance.get_touch2(), 4); |
204 | assert_eq(instance.get_touch3(), 6); |
205 | assert_eq(instance.get_touch_double1(), 1); |
206 | assert_eq(instance.get_touch_double2(), 1); |
207 | assert_eq(instance.get_touch_double3(), 2); |
208 | assert_eq(instance.get_pointer_event_test(), "move.other:down.left:click:up.left:move.other:"); |
209 | |
210 | // click slowly on the same touch areas twice |
211 | slint_testing::mock_elapsed_time(1000); |
212 | instance.set_pointer_event_test(""); |
213 | slint_testing::mock_elapsed_time(1000); |
214 | slint_testing::send_mouse_click(&instance, 101., 101.); // second |
215 | slint_testing::mock_elapsed_time(1000); |
216 | slint_testing::send_mouse_click(&instance, 101., 101.); // second |
217 | instance.window().dispatch_pointer_move_event(slint::LogicalPosition({1.0, 1.0})); |
218 | assert_eq(instance.get_touch1(), 4); |
219 | assert_eq(instance.get_touch2(), 6); |
220 | assert_eq(instance.get_touch3(), 6); |
221 | assert_eq(instance.get_touch_double1(), 1); |
222 | assert_eq(instance.get_touch_double2(), 1); |
223 | assert_eq(instance.get_touch_double3(), 2); |
224 | |
225 | slint_testing::mock_elapsed_time(1000); |
226 | slint_testing::send_mouse_click(&instance, 109., 101.); // first |
227 | slint_testing::mock_elapsed_time(10); |
228 | slint_testing::send_mouse_click(&instance, 101., 109.); // first |
229 | assert_eq(instance.get_touch1(), 6); |
230 | assert_eq(instance.get_touch2(), 6); |
231 | assert_eq(instance.get_touch3(), 6); |
232 | assert_eq(instance.get_touch_double1(), 1); |
233 | assert_eq(instance.get_touch_double2(), 1); |
234 | assert_eq(instance.get_touch_double3(), 2); |
235 | |
236 | |
237 | slint_testing::mock_elapsed_time(1000); |
238 | assert_eq(instance.get_touch1(), 6); |
239 | assert_eq(instance.get_touch2(), 6); |
240 | assert_eq(instance.get_touch3(), 6); |
241 | assert_eq(instance.get_touch_double1(), 1); |
242 | assert_eq(instance.get_touch_double2(), 1); |
243 | assert_eq(instance.get_touch_double3(), 2); |
244 | ``` |
245 | |
246 | ```rust |
247 | use slint::{platform::WindowEvent, LogicalPosition}; |
248 | use slint::private_unstable_api::re_exports::MouseCursor; |
249 | |
250 | let instance = TestCase::new().unwrap(); |
251 | |
252 | let double_click = |x, y| { |
253 | slint_testing::send_mouse_click(&instance, x, y); |
254 | slint_testing::mock_elapsed_time(50); |
255 | slint_testing::send_mouse_click(&instance, x, y); |
256 | }; |
257 | |
258 | |
259 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default, |
260 | "Unexpected mousecursor at start"); |
261 | |
262 | // does not click on anything |
263 | slint_testing::send_mouse_click(&instance, 5., 5.); |
264 | slint_testing::mock_elapsed_time(1000); |
265 | assert_eq!(instance.get_touch1(), 0, "Mis-click registered at touch1"); |
266 | assert_eq!(instance.get_touch2(), 0, "Mis-click registered at touch2"); |
267 | assert_eq!(instance.get_touch3(), 0, "Mis-click registered at touch3"); |
268 | assert_eq!(instance.get_touch_double1(), 0, "Mis-click registered at touch1 as double-click"); |
269 | assert_eq!(instance.get_touch_double2(), 0, "Mis-click registered at touch2 as double-click"); |
270 | assert_eq!(instance.get_touch_double3(), 0, "Mis-click registered at touch3 as double-click"); |
271 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default, |
272 | "Mis-click changed mouse cursor"); |
273 | |
274 | // click on second one |
275 | instance.set_pointer_event_test("".into()); |
276 | slint_testing::mock_elapsed_time(1000); |
277 | slint_testing::send_mouse_click(&instance, 101., 101.); |
278 | assert_eq!(instance.get_touch1(), 0, "Click on 2 registered at touch1"); |
279 | assert_eq!(instance.get_touch2(), 1, "Click on 2 did not register at touch2"); |
280 | assert_eq!(instance.get_touch3(), 0, "Click on 2 registered at touch3"); |
281 | assert_eq!(instance.get_touch_double1(), 0, "Click on 2 registered at touch1 as double-click"); |
282 | assert_eq!(instance.get_touch_double2(), 0, "Click on 2 registered at touch2 as double-click"); |
283 | assert_eq!(instance.get_touch_double3(), 0, "Click on 2 registered at touch3 as double-click"); |
284 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Pointer, |
285 | "Click on 1 did not change mouse pointer"); |
286 | |
287 | // click on first one only |
288 | slint_testing::mock_elapsed_time(1000); |
289 | slint_testing::send_mouse_click(&instance, 108., 108.); |
290 | assert_eq!(instance.get_touch1(), 1, "Click on 1 did not register at touch1"); |
291 | assert_eq!(instance.get_touch2(), 1, "Click on 1 registered at touch2"); |
292 | assert_eq!(instance.get_touch3(), 0, "Click on 1 registered at touch3"); |
293 | assert_eq!(instance.get_touch_double1(), 0, "Click on 1 registered at touch1 as double-click"); |
294 | assert_eq!(instance.get_touch_double2(), 0, "Click on 1 registered at touch2 as double-click"); |
295 | assert_eq!(instance.get_touch_double3(), 0, "Click on 1 registered at touch3 as double-click"); |
296 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Move, |
297 | "Click on 2 did not change mouse pointer"); |
298 | |
299 | // click on the third |
300 | slint_testing::mock_elapsed_time(1000); |
301 | slint_testing::send_mouse_click(&instance, 106., 103.); |
302 | assert_eq!(instance.get_touch1(), 1, "Click on 3 registered at touch1"); |
303 | assert_eq!(instance.get_touch2(), 1, "Click on 3 registered at touch2"); |
304 | assert_eq!(instance.get_touch3(), 1, "Click on 3 did not register at touch3"); |
305 | assert_eq!(instance.get_touch_double1(), 0, "Click on 3 registered at touch1 as double-click"); |
306 | assert_eq!(instance.get_touch_double2(), 0, "Click on 3 registered at touch2 as double-click"); |
307 | assert_eq!(instance.get_touch_double3(), 0, "Click on 3 registered at touch3 as double-click"); |
308 | assert_eq!(instance.get_pointer_event_test().as_str(), "move.other:down.left:click:up.left:move.other:", |
309 | "Click on 3 produced an unexpected sequence of events"); |
310 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default, |
311 | "Click on 3 did not change mouse pointer"); |
312 | |
313 | // does not double-click on anything |
314 | slint_testing::mock_elapsed_time(1000); |
315 | double_click(5., 5.); |
316 | assert_eq!(instance.get_touch1(), 1, "Mis-double-click registered at touch1"); |
317 | assert_eq!(instance.get_touch2(), 1, "Mis-double-click registered at touch2"); |
318 | assert_eq!(instance.get_touch3(), 1, "Mis-double-click registered at touch3"); |
319 | assert_eq!(instance.get_touch_double1(), 0, "Mis-double-click registered at touch1 as double-click"); |
320 | assert_eq!(instance.get_touch_double2(), 0, "Mis-double-click registered at touch2 as double-click"); |
321 | assert_eq!(instance.get_touch_double3(), 0, "Mis-double-click registered at touch3 as double-click"); |
322 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default, |
323 | "Mis-double-click on 3 did not change mouse pointer"); |
324 | |
325 | // double-click on second one |
326 | slint_testing::mock_elapsed_time(1000); |
327 | instance.set_pointer_event_test("".into()); |
328 | double_click(101., 101.); |
329 | assert_eq!(instance.get_touch1(), 1, "Double-click on 2 registered at touch1"); |
330 | assert_eq!(instance.get_touch2(), 3, "Double-click on 2 did not registered at touch2"); |
331 | assert_eq!(instance.get_touch3(), 1, "Double-click on 2 registered at touch3"); |
332 | assert_eq!(instance.get_touch_double1(), 0, "Double-click on 2 registered at touch1 as double-click"); |
333 | assert_eq!(instance.get_touch_double2(), 1, "Double-click on 2 did not register at touch1 as double-click"); |
334 | assert_eq!(instance.get_touch_double3(), 0, "Double-click on 2 registered at touch1 as double-click"); |
335 | assert_eq!(instance.get_pointer_event_test().as_str(), "move.other:down.left:click:up.left:move.other:move.other:down.left:click:double_click:up.left:move.other:", |
336 | "Double-click on 2 produced an unexpected sequence of events"); |
337 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Pointer, |
338 | "Double-click on 2 did not change mouse pointer"); |
339 | |
340 | // double-click on first one only |
341 | slint_testing::mock_elapsed_time(1000); |
342 | double_click(108., 108.); |
343 | assert_eq!(instance.get_touch1(), 3, "Double-click on 1 did not registered at touch1"); |
344 | assert_eq!(instance.get_touch2(), 3, "Double-click on 1 registered at touch2"); |
345 | assert_eq!(instance.get_touch3(), 1, "Double-click on 1 registered at touch3"); |
346 | assert_eq!(instance.get_touch_double1(), 1, "Double-click on 1 did not register at touch1 as double-click"); |
347 | assert_eq!(instance.get_touch_double2(), 1, "Double-click on 1 registered at touch2 as double-click"); |
348 | assert_eq!(instance.get_touch_double3(), 0, "Double-click on 1 registered at touch3 as double-click"); |
349 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Move, |
350 | "Double-click on 1 did not change mouse pointer"); |
351 | |
352 | // double-click on the third |
353 | slint_testing::mock_elapsed_time(1000); |
354 | double_click(106., 103.); |
355 | assert_eq!(instance.get_touch1(), 3, "Double-click on 3 registered at touch1"); |
356 | assert_eq!(instance.get_touch2(), 3, "Double-click on 3 registered at touch2"); |
357 | assert_eq!(instance.get_touch3(), 3, "Double-click on 3 did not registered at touch3"); |
358 | assert_eq!(instance.get_touch_double1(), 1, "Double-click on 3 registered at touch1 as double-click"); |
359 | assert_eq!(instance.get_touch_double2(), 1, "Double-click on 3 registered at touch2 as double-click"); |
360 | assert_eq!(instance.get_touch_double3(), 1, "Double-click on 3 did not register at touch3 as double-click"); |
361 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default, |
362 | "Double-click on 3 did not change mouse pointer"); |
363 | |
364 | // triple-click on the third (treated as a double click, followed by a single click) |
365 | slint_testing::mock_elapsed_time(1000); |
366 | slint_testing::send_mouse_click(&instance, 106.0, 103.0); |
367 | assert_eq!(instance.get_touch1(), 3, "Triple-click (1st click) on 3 registered at touch1"); |
368 | assert_eq!(instance.get_touch2(), 3, "Triple-click (1st click) on 3 registered at touch2"); |
369 | assert_eq!(instance.get_touch3(), 4, "Triple-click (1st click) on 3 did not register at touch3"); |
370 | slint_testing::send_mouse_click(&instance, 106.0, 103.0); |
371 | assert_eq!(instance.get_touch1(), 3, "Triple-click (2st click) on 3 registered at touch1"); |
372 | assert_eq!(instance.get_touch2(), 3, "Triple-click (2st click) on 3 registered at touch2"); |
373 | assert_eq!(instance.get_touch3(), 5, "Triple-click (2st click) on 3 did not register at touch3"); |
374 | slint_testing::send_mouse_click(&instance, 106.0, 103.0); |
375 | assert_eq!(instance.get_touch1(), 3, "Triple-click on 3 registered at touch1"); |
376 | assert_eq!(instance.get_touch2(), 3, "Triple-click on 3 registered at touch1"); |
377 | assert_eq!(instance.get_touch3(), 6, "Triple-click on 3 registered at touch1"); |
378 | assert_eq!(instance.get_touch_double1(), 1, "Triple-click on 3 registered at touch1"); |
379 | assert_eq!(instance.get_touch_double2(), 1, "Triple-click on 3 registered at touch2"); |
380 | assert_eq!(instance.get_touch_double3(), 2, "Triple-click on 3 did not register at touch3 as double-click"); |
381 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default, |
382 | "Triple-click on 3 did not change mouse pointer"); |
383 | |
384 | // click really quickly on two different mouse areas |
385 | slint_testing::mock_elapsed_time(1000); |
386 | instance.set_pointer_event_test("".into()); |
387 | slint_testing::mock_elapsed_time(1000); |
388 | slint_testing::send_mouse_click(&instance, 101., 106.); // first |
389 | slint_testing::mock_elapsed_time(20); |
390 | slint_testing::send_mouse_click(&instance, 101., 104.); // second |
391 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(1.0, 1.0) }); |
392 | assert_eq!(instance.get_touch1(), 4, "click on different touch areas did not register on touch1"); |
393 | assert_eq!(instance.get_touch2(), 4, "click on different touch areas did not register on touch2"); |
394 | assert_eq!(instance.get_touch3(), 6, "click on different touch areas registered at touch3"); |
395 | assert_eq!(instance.get_touch_double1(), 1, "click on different touch areas registered on touch1 as double-click"); |
396 | assert_eq!(instance.get_touch_double2(), 1, "click on different touch areas registered on touch2 as double-click"); |
397 | assert_eq!(instance.get_touch_double3(), 2, "click on different touch areas registered on touch3 as double-click"); |
398 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default, |
399 | "click on different touch areas changed mouse pointer"); |
400 | assert_eq!(instance.get_pointer_event_test().as_str(), "move.other:down.left:click:up.left:move.other:", |
401 | "click on different touch areas produced an unexpected sequence of events"); |
402 | |
403 | // click slowly on the same touch areas twice |
404 | slint_testing::mock_elapsed_time(1000); |
405 | instance.set_pointer_event_test("".into()); |
406 | slint_testing::send_mouse_click(&instance, 101., 101.); // second |
407 | slint_testing::mock_elapsed_time(1000); |
408 | slint_testing::send_mouse_click(&instance, 101., 101.); // second |
409 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(1.0, 1.0) }); |
410 | |
411 | assert_eq!(instance.get_touch1(), 4, "Slow double click did not register on touch1"); |
412 | assert_eq!(instance.get_touch2(), 6, "Slow double click did not register on touch2"); |
413 | assert_eq!(instance.get_touch3(), 6, "Slow double click did not register on touch3"); |
414 | assert_eq!(instance.get_touch_double1(), 1, "Slow double click registered on touch1 as double-click"); |
415 | assert_eq!(instance.get_touch_double2(), 1, "Slow double click registered on touch2 as double-click"); |
416 | assert_eq!(instance.get_touch_double3(), 2, "Slow double click registered on touch3 as double-click"); |
417 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default, |
418 | "click on different touch areas changed mouse pointer"); |
419 | assert_eq!(instance.get_pointer_event_test().as_str(), "move.other:down.left:click:up.left:move.other:move.other:down.left:click:up.left:move.other:", |
420 | "click on different touch areas produced an unexpected sequence of events"); |
421 | |
422 | |
423 | // Click on the same mouse area but using a distance which is more than the threshold |
424 | slint_testing::mock_elapsed_time(1000); |
425 | slint_testing::send_mouse_click(&instance, 109., 101.); // first |
426 | slint_testing::mock_elapsed_time(10); |
427 | slint_testing::send_mouse_click(&instance, 101., 109.); // first |
428 | assert_eq!(instance.get_touch1(), 6, "long distance click 1"); |
429 | assert_eq!(instance.get_touch2(), 6, "long distance click 2"); |
430 | assert_eq!(instance.get_touch3(), 6, "long distance click 3"); |
431 | assert_eq!(instance.get_touch_double1(), 1, "long distance click as double click 1"); |
432 | assert_eq!(instance.get_touch_double2(), 1, "long distance click as double click 2"); |
433 | assert_eq!(instance.get_touch_double3(), 2, "long distance click as double click 3"); |
434 | |
435 | |
436 | slint_testing::mock_elapsed_time(1000); |
437 | assert_eq!(instance.get_touch1(), 6, "Cool down changed touch1"); |
438 | assert_eq!(instance.get_touch2(), 6, "Cool down changed touch2"); |
439 | assert_eq!(instance.get_touch3(), 6, "Cool down changed touch3"); |
440 | assert_eq!(instance.get_touch_double1(), 1, "Cool down changed touch-double1"); |
441 | assert_eq!(instance.get_touch_double2(), 1, "Cool down changed touch-double2"); |
442 | assert_eq!(instance.get_touch_double3(), 2, "Cool down changed touch-double3"); |
443 | ``` |
444 | |
445 | ```js |
446 | var instance = new slint.TestCase(); |
447 | |
448 | function double_click(x, y) { |
449 | slintlib.private_api.send_mouse_click(instance, x, y); |
450 | slintlib.private_api.mock_elapsed_time(50); |
451 | slintlib.private_api.send_mouse_click(instance, x, y); |
452 | } |
453 | |
454 | // // // Disable the test as the time handling is currently broken in JS tests! |
455 | |
456 | // // does not click on anything |
457 | // slintlib.private_api.send_mouse_click(instance, 5., 5.); |
458 | // assert.equal(instance.touch1, 0); |
459 | // assert.equal(instance.touch2, 0); |
460 | // assert.equal(instance.touch3, 0); |
461 | // assert.equal(instance.touch_double1, 0); |
462 | // assert.equal(instance.touch_double2, 0); |
463 | // assert.equal(instance.touch_double3, 0); |
464 | |
465 | // // click on second one |
466 | // slintlib.private_api.mock_elapsed_time(1000); |
467 | // slintlib.private_api.send_mouse_click(instance, 101., 101.); |
468 | // assert.equal(instance.touch1, 0); |
469 | // assert.equal(instance.touch2, 1); |
470 | // assert.equal(instance.touch3, 0); |
471 | // assert.equal(instance.touch_double1, 0); |
472 | // assert.equal(instance.touch_double2, 0); |
473 | // assert.equal(instance.touch_double3, 0); |
474 | |
475 | // // click on first one only |
476 | // slintlib.private_api.mock_elapsed_time(2000); |
477 | // slintlib.private_api.send_mouse_click(instance, 108., 108.); |
478 | // assert.equal(instance.touch1, 1); |
479 | // assert.equal(instance.touch2, 1); |
480 | // assert.equal(instance.touch3, 0); |
481 | // assert.equal(instance.touch_double1, 0); |
482 | // assert.equal(instance.touch_double2, 0); |
483 | // assert.equal(instance.touch_double3, 0); |
484 | |
485 | // // click on the third |
486 | // slintlib.private_api.mock_elapsed_time(1000); |
487 | // slintlib.private_api.send_mouse_click(instance, 106., 103.); |
488 | // assert.equal(instance.touch1, 1); |
489 | // assert.equal(instance.touch2, 1); |
490 | // assert.equal(instance.touch3, 1); |
491 | // assert.equal(instance.touch_double1, 0); |
492 | // assert.equal(instance.touch_double2, 0); |
493 | // assert.equal(instance.touch_double3, 0); |
494 | |
495 | // assert.equal(instance.pointer_event_test, "move.other:down.left:click:up.left:move.other:"); |
496 | |
497 | // // does not double-click on anything |
498 | // slintlib.private_api.mock_elapsed_time(1000); |
499 | // double_click(5., 5.); |
500 | // assert.equal(instance.touch1, 1); |
501 | // assert.equal(instance.touch2, 1); |
502 | // assert.equal(instance.touch3, 1); |
503 | // assert.equal(instance.touch_double1, 0); |
504 | // assert.equal(instance.touch_double2, 0); |
505 | // assert.equal(instance.touch_double3, 0); |
506 | |
507 | // // double-click on second one |
508 | // slintlib.private_api.mock_elapsed_time(1000); |
509 | // instance.pointer_event_test = ""; |
510 | // double_click(101., 101.); |
511 | // assert.equal(instance.touch1, 1); |
512 | // assert.equal(instance.touch2, 3); |
513 | // assert.equal(instance.touch3, 1); |
514 | // assert.equal(instance.touch_double1, 0); |
515 | // assert.equal(instance.touch_double2, 1); |
516 | // assert.equal(instance.touch_double3, 0); |
517 | // assert.equal(instance.pointer_event_test, "move.other:down.left:click:up.left:move.other:move.other:down.left:click:double_click:up.left:move.other:"); |
518 | |
519 | // // double-click on first one only |
520 | // slintlib.private_api.mock_elapsed_time(1000); |
521 | // double_click(108., 108.); |
522 | // assert.equal(instance.touch1, 3); |
523 | // assert.equal(instance.touch2, 3); |
524 | // assert.equal(instance.touch3, 1); |
525 | // assert.equal(instance.touch_double1, 1); |
526 | // assert.equal(instance.touch_double2, 1); |
527 | // assert.equal(instance.touch_double3, 0); |
528 | |
529 | // // double-click on third one only |
530 | // slintlib.private_api.mock_elapsed_time(1000); |
531 | // double_click(106., 103.); |
532 | // assert.equal(instance.touch1, 3); |
533 | // assert.equal(instance.touch2, 3); |
534 | // assert.equal(instance.touch3, 3); |
535 | // assert.equal(instance.touch_double1, 1); |
536 | // assert.equal(instance.touch_double2, 1); |
537 | // assert.equal(instance.touch_double3, 1); |
538 | |
539 | // // triple-click on the third |
540 | // slintlib.private_api.mock_elapsed_time(1000); |
541 | // slintlib.private_api.send_mouse_click(instance, 106., 103.); |
542 | // assert.equal(instance.touch3, 4); |
543 | // assert.equal(instance.touch_double3, 1); |
544 | // slintlib.private_api.send_mouse_click(instance, 106., 103.); |
545 | // assert.equal(instance.touch3, 5); |
546 | // assert.equal(instance.touch_double3, 2); |
547 | // slintlib.private_api.send_mouse_click(instance, 106., 103.); |
548 | // assert.equal(instance.touch1, 3); |
549 | // assert.equal(instance.touch2, 3); |
550 | // assert.equal(instance.touch3, 6); |
551 | // assert.equal(instance.touch_double1, 1); |
552 | // assert.equal(instance.touch_double2, 1); |
553 | // assert.equal(instance.touch_double3, 2); |
554 | |
555 | // // click really quickly on two different mouse areas |
556 | // slintlib.private_api.mock_elapsed_time(1000); |
557 | // instance.pointer_event_test = ""; |
558 | // slintlib.private_api.send_mouse_click(instance, 108., 108.); |
559 | // slintlib.private_api.mock_elapsed_time(20); |
560 | // slintlib.private_api.send_mouse_click(instance, 101., 101.); |
561 | // assert.equal(instance.touch1, 4); |
562 | // assert.equal(instance.touch2, 4); |
563 | // assert.equal(instance.touch3, 6); |
564 | // assert.equal(instance.touch_double1, 1); |
565 | // assert.equal(instance.touch_double2, 1); |
566 | // assert.equal(instance.touch_double3, 2); |
567 | // assert.equal(instance.pointer_event_test, "move.other:down.left:click:up.left:move.other:"); |
568 | |
569 | // // click slowly on the same touch areas twice |
570 | // slintlib.private_api.mock_elapsed_time(1000); |
571 | // instance.pointer_event_test = ""; |
572 | // slintlib.private_api.send_mouse_click(instance, 101., 101.); |
573 | // slintlib.private_api.mock_elapsed_time(1000); |
574 | // slintlib.private_api.send_mouse_click(instance, 101., 101.); |
575 | // assert.equal(instance.touch1, 4); |
576 | // assert.equal(instance.touch2, 6); |
577 | // assert.equal(instance.touch3, 6); |
578 | // assert.equal(instance.touch_double1, 1); |
579 | // assert.equal(instance.touch_double2, 1); |
580 | // assert.equal(instance.touch_double3, 2); |
581 | // assert.equal(instance.pointer_event_test, "move.other:down.left:click:up.left:move.other:move.other:down.left:click:up.left:move.other:"); |
582 | |
583 | // slintlib.private_api.mock_elapsed_time(1000); |
584 | // assert.equal(instance.touch1, 4); |
585 | // assert.equal(instance.touch2, 6); |
586 | // assert.equal(instance.touch3, 6); |
587 | // assert.equal(instance.touch_double1, 1); |
588 | // assert.equal(instance.touch_double2, 1); |
589 | // assert.equal(instance.touch_double3, 2); |
590 | ``` |
591 | */ |
592 | } |
593 | |
594 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
595 | use i_slint_backend_testing as slint_testing; |
596 | slint_testing::init(); |
597 | use slint::{platform::WindowEvent, LogicalPosition}; |
598 | use slint::private_unstable_api::re_exports::MouseCursor; |
599 | |
600 | let instance = TestCase::new().unwrap(); |
601 | |
602 | let double_click = |x, y| { |
603 | slint_testing::send_mouse_click(&instance, x, y); |
604 | slint_testing::mock_elapsed_time(50); |
605 | slint_testing::send_mouse_click(&instance, x, y); |
606 | }; |
607 | |
608 | |
609 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default, |
610 | "Unexpected mousecursor at start" ); |
611 | |
612 | // does not click on anything |
613 | slint_testing::send_mouse_click(&instance, 5., 5.); |
614 | slint_testing::mock_elapsed_time(1000); |
615 | assert_eq!(instance.get_touch1(), 0, "Mis-click registered at touch1" ); |
616 | assert_eq!(instance.get_touch2(), 0, "Mis-click registered at touch2" ); |
617 | assert_eq!(instance.get_touch3(), 0, "Mis-click registered at touch3" ); |
618 | assert_eq!(instance.get_touch_double1(), 0, "Mis-click registered at touch1 as double-click" ); |
619 | assert_eq!(instance.get_touch_double2(), 0, "Mis-click registered at touch2 as double-click" ); |
620 | assert_eq!(instance.get_touch_double3(), 0, "Mis-click registered at touch3 as double-click" ); |
621 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default, |
622 | "Mis-click changed mouse cursor" ); |
623 | |
624 | // click on second one |
625 | instance.set_pointer_event_test("" .into()); |
626 | slint_testing::mock_elapsed_time(1000); |
627 | slint_testing::send_mouse_click(&instance, 101., 101.); |
628 | assert_eq!(instance.get_touch1(), 0, "Click on 2 registered at touch1" ); |
629 | assert_eq!(instance.get_touch2(), 1, "Click on 2 did not register at touch2" ); |
630 | assert_eq!(instance.get_touch3(), 0, "Click on 2 registered at touch3" ); |
631 | assert_eq!(instance.get_touch_double1(), 0, "Click on 2 registered at touch1 as double-click" ); |
632 | assert_eq!(instance.get_touch_double2(), 0, "Click on 2 registered at touch2 as double-click" ); |
633 | assert_eq!(instance.get_touch_double3(), 0, "Click on 2 registered at touch3 as double-click" ); |
634 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Pointer, |
635 | "Click on 1 did not change mouse pointer" ); |
636 | |
637 | // click on first one only |
638 | slint_testing::mock_elapsed_time(1000); |
639 | slint_testing::send_mouse_click(&instance, 108., 108.); |
640 | assert_eq!(instance.get_touch1(), 1, "Click on 1 did not register at touch1" ); |
641 | assert_eq!(instance.get_touch2(), 1, "Click on 1 registered at touch2" ); |
642 | assert_eq!(instance.get_touch3(), 0, "Click on 1 registered at touch3" ); |
643 | assert_eq!(instance.get_touch_double1(), 0, "Click on 1 registered at touch1 as double-click" ); |
644 | assert_eq!(instance.get_touch_double2(), 0, "Click on 1 registered at touch2 as double-click" ); |
645 | assert_eq!(instance.get_touch_double3(), 0, "Click on 1 registered at touch3 as double-click" ); |
646 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Move, |
647 | "Click on 2 did not change mouse pointer" ); |
648 | |
649 | // click on the third |
650 | slint_testing::mock_elapsed_time(1000); |
651 | slint_testing::send_mouse_click(&instance, 106., 103.); |
652 | assert_eq!(instance.get_touch1(), 1, "Click on 3 registered at touch1" ); |
653 | assert_eq!(instance.get_touch2(), 1, "Click on 3 registered at touch2" ); |
654 | assert_eq!(instance.get_touch3(), 1, "Click on 3 did not register at touch3" ); |
655 | assert_eq!(instance.get_touch_double1(), 0, "Click on 3 registered at touch1 as double-click" ); |
656 | assert_eq!(instance.get_touch_double2(), 0, "Click on 3 registered at touch2 as double-click" ); |
657 | assert_eq!(instance.get_touch_double3(), 0, "Click on 3 registered at touch3 as double-click" ); |
658 | assert_eq!(instance.get_pointer_event_test().as_str(), "move.other:down.left:click:up.left:move.other:" , |
659 | "Click on 3 produced an unexpected sequence of events" ); |
660 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default, |
661 | "Click on 3 did not change mouse pointer" ); |
662 | |
663 | // does not double-click on anything |
664 | slint_testing::mock_elapsed_time(1000); |
665 | double_click(5., 5.); |
666 | assert_eq!(instance.get_touch1(), 1, "Mis-double-click registered at touch1" ); |
667 | assert_eq!(instance.get_touch2(), 1, "Mis-double-click registered at touch2" ); |
668 | assert_eq!(instance.get_touch3(), 1, "Mis-double-click registered at touch3" ); |
669 | assert_eq!(instance.get_touch_double1(), 0, "Mis-double-click registered at touch1 as double-click" ); |
670 | assert_eq!(instance.get_touch_double2(), 0, "Mis-double-click registered at touch2 as double-click" ); |
671 | assert_eq!(instance.get_touch_double3(), 0, "Mis-double-click registered at touch3 as double-click" ); |
672 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default, |
673 | "Mis-double-click on 3 did not change mouse pointer" ); |
674 | |
675 | // double-click on second one |
676 | slint_testing::mock_elapsed_time(1000); |
677 | instance.set_pointer_event_test("" .into()); |
678 | double_click(101., 101.); |
679 | assert_eq!(instance.get_touch1(), 1, "Double-click on 2 registered at touch1" ); |
680 | assert_eq!(instance.get_touch2(), 3, "Double-click on 2 did not registered at touch2" ); |
681 | assert_eq!(instance.get_touch3(), 1, "Double-click on 2 registered at touch3" ); |
682 | assert_eq!(instance.get_touch_double1(), 0, "Double-click on 2 registered at touch1 as double-click" ); |
683 | assert_eq!(instance.get_touch_double2(), 1, "Double-click on 2 did not register at touch1 as double-click" ); |
684 | assert_eq!(instance.get_touch_double3(), 0, "Double-click on 2 registered at touch1 as double-click" ); |
685 | assert_eq!(instance.get_pointer_event_test().as_str(), "move.other:down.left:click:up.left:move.other:move.other:down.left:click:double_click:up.left:move.other:" , |
686 | "Double-click on 2 produced an unexpected sequence of events" ); |
687 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Pointer, |
688 | "Double-click on 2 did not change mouse pointer" ); |
689 | |
690 | // double-click on first one only |
691 | slint_testing::mock_elapsed_time(1000); |
692 | double_click(108., 108.); |
693 | assert_eq!(instance.get_touch1(), 3, "Double-click on 1 did not registered at touch1" ); |
694 | assert_eq!(instance.get_touch2(), 3, "Double-click on 1 registered at touch2" ); |
695 | assert_eq!(instance.get_touch3(), 1, "Double-click on 1 registered at touch3" ); |
696 | assert_eq!(instance.get_touch_double1(), 1, "Double-click on 1 did not register at touch1 as double-click" ); |
697 | assert_eq!(instance.get_touch_double2(), 1, "Double-click on 1 registered at touch2 as double-click" ); |
698 | assert_eq!(instance.get_touch_double3(), 0, "Double-click on 1 registered at touch3 as double-click" ); |
699 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Move, |
700 | "Double-click on 1 did not change mouse pointer" ); |
701 | |
702 | // double-click on the third |
703 | slint_testing::mock_elapsed_time(1000); |
704 | double_click(106., 103.); |
705 | assert_eq!(instance.get_touch1(), 3, "Double-click on 3 registered at touch1" ); |
706 | assert_eq!(instance.get_touch2(), 3, "Double-click on 3 registered at touch2" ); |
707 | assert_eq!(instance.get_touch3(), 3, "Double-click on 3 did not registered at touch3" ); |
708 | assert_eq!(instance.get_touch_double1(), 1, "Double-click on 3 registered at touch1 as double-click" ); |
709 | assert_eq!(instance.get_touch_double2(), 1, "Double-click on 3 registered at touch2 as double-click" ); |
710 | assert_eq!(instance.get_touch_double3(), 1, "Double-click on 3 did not register at touch3 as double-click" ); |
711 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default, |
712 | "Double-click on 3 did not change mouse pointer" ); |
713 | |
714 | // triple-click on the third (treated as a double click, followed by a single click) |
715 | slint_testing::mock_elapsed_time(1000); |
716 | slint_testing::send_mouse_click(&instance, 106.0, 103.0); |
717 | assert_eq!(instance.get_touch1(), 3, "Triple-click (1st click) on 3 registered at touch1" ); |
718 | assert_eq!(instance.get_touch2(), 3, "Triple-click (1st click) on 3 registered at touch2" ); |
719 | assert_eq!(instance.get_touch3(), 4, "Triple-click (1st click) on 3 did not register at touch3" ); |
720 | slint_testing::send_mouse_click(&instance, 106.0, 103.0); |
721 | assert_eq!(instance.get_touch1(), 3, "Triple-click (2st click) on 3 registered at touch1" ); |
722 | assert_eq!(instance.get_touch2(), 3, "Triple-click (2st click) on 3 registered at touch2" ); |
723 | assert_eq!(instance.get_touch3(), 5, "Triple-click (2st click) on 3 did not register at touch3" ); |
724 | slint_testing::send_mouse_click(&instance, 106.0, 103.0); |
725 | assert_eq!(instance.get_touch1(), 3, "Triple-click on 3 registered at touch1" ); |
726 | assert_eq!(instance.get_touch2(), 3, "Triple-click on 3 registered at touch1" ); |
727 | assert_eq!(instance.get_touch3(), 6, "Triple-click on 3 registered at touch1" ); |
728 | assert_eq!(instance.get_touch_double1(), 1, "Triple-click on 3 registered at touch1" ); |
729 | assert_eq!(instance.get_touch_double2(), 1, "Triple-click on 3 registered at touch2" ); |
730 | assert_eq!(instance.get_touch_double3(), 2, "Triple-click on 3 did not register at touch3 as double-click" ); |
731 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default, |
732 | "Triple-click on 3 did not change mouse pointer" ); |
733 | |
734 | // click really quickly on two different mouse areas |
735 | slint_testing::mock_elapsed_time(1000); |
736 | instance.set_pointer_event_test("" .into()); |
737 | slint_testing::mock_elapsed_time(1000); |
738 | slint_testing::send_mouse_click(&instance, 101., 106.); // first |
739 | slint_testing::mock_elapsed_time(20); |
740 | slint_testing::send_mouse_click(&instance, 101., 104.); // second |
741 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(1.0, 1.0) }); |
742 | assert_eq!(instance.get_touch1(), 4, "click on different touch areas did not register on touch1" ); |
743 | assert_eq!(instance.get_touch2(), 4, "click on different touch areas did not register on touch2" ); |
744 | assert_eq!(instance.get_touch3(), 6, "click on different touch areas registered at touch3" ); |
745 | assert_eq!(instance.get_touch_double1(), 1, "click on different touch areas registered on touch1 as double-click" ); |
746 | assert_eq!(instance.get_touch_double2(), 1, "click on different touch areas registered on touch2 as double-click" ); |
747 | assert_eq!(instance.get_touch_double3(), 2, "click on different touch areas registered on touch3 as double-click" ); |
748 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default, |
749 | "click on different touch areas changed mouse pointer" ); |
750 | assert_eq!(instance.get_pointer_event_test().as_str(), "move.other:down.left:click:up.left:move.other:" , |
751 | "click on different touch areas produced an unexpected sequence of events" ); |
752 | |
753 | // click slowly on the same touch areas twice |
754 | slint_testing::mock_elapsed_time(1000); |
755 | instance.set_pointer_event_test("" .into()); |
756 | slint_testing::send_mouse_click(&instance, 101., 101.); // second |
757 | slint_testing::mock_elapsed_time(1000); |
758 | slint_testing::send_mouse_click(&instance, 101., 101.); // second |
759 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(1.0, 1.0) }); |
760 | |
761 | assert_eq!(instance.get_touch1(), 4, "Slow double click did not register on touch1" ); |
762 | assert_eq!(instance.get_touch2(), 6, "Slow double click did not register on touch2" ); |
763 | assert_eq!(instance.get_touch3(), 6, "Slow double click did not register on touch3" ); |
764 | assert_eq!(instance.get_touch_double1(), 1, "Slow double click registered on touch1 as double-click" ); |
765 | assert_eq!(instance.get_touch_double2(), 1, "Slow double click registered on touch2 as double-click" ); |
766 | assert_eq!(instance.get_touch_double3(), 2, "Slow double click registered on touch3 as double-click" ); |
767 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default, |
768 | "click on different touch areas changed mouse pointer" ); |
769 | assert_eq!(instance.get_pointer_event_test().as_str(), "move.other:down.left:click:up.left:move.other:move.other:down.left:click:up.left:move.other:" , |
770 | "click on different touch areas produced an unexpected sequence of events" ); |
771 | |
772 | |
773 | // Click on the same mouse area but using a distance which is more than the threshold |
774 | slint_testing::mock_elapsed_time(1000); |
775 | slint_testing::send_mouse_click(&instance, 109., 101.); // first |
776 | slint_testing::mock_elapsed_time(10); |
777 | slint_testing::send_mouse_click(&instance, 101., 109.); // first |
778 | assert_eq!(instance.get_touch1(), 6, "long distance click 1" ); |
779 | assert_eq!(instance.get_touch2(), 6, "long distance click 2" ); |
780 | assert_eq!(instance.get_touch3(), 6, "long distance click 3" ); |
781 | assert_eq!(instance.get_touch_double1(), 1, "long distance click as double click 1" ); |
782 | assert_eq!(instance.get_touch_double2(), 1, "long distance click as double click 2" ); |
783 | assert_eq!(instance.get_touch_double3(), 2, "long distance click as double click 3" ); |
784 | |
785 | |
786 | slint_testing::mock_elapsed_time(1000); |
787 | assert_eq!(instance.get_touch1(), 6, "Cool down changed touch1" ); |
788 | assert_eq!(instance.get_touch2(), 6, "Cool down changed touch2" ); |
789 | assert_eq!(instance.get_touch3(), 6, "Cool down changed touch3" ); |
790 | assert_eq!(instance.get_touch_double1(), 1, "Cool down changed touch-double1" ); |
791 | assert_eq!(instance.get_touch_double2(), 1, "Cool down changed touch-double2" ); |
792 | assert_eq!(instance.get_touch_double3(), 2, "Cool down changed touch-double3" ); |
793 | Ok(()) |
794 | } |