1// Copyright © SixtyFPS GmbH <info@slint.dev>
2// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
3
4TestCase := Window {
5 width: 500px;
6 height: 550px;
7 background: #ecedeb;
8
9 property<[int]> xs: [1, 2, 3];
10
11 VerticalLayout {
12 padding: 0px;
13 spacing: 0px;
14 alignment: start;
15
16 for x_[i] in xs: Rectangle {
17 background: i == 0 ? red : i == 1 ? green : blue;
18 height: 100px;
19 TouchArea {
20 clicked => { last_clicked = x_; }
21 }
22 }
23
24 for x_[i] in xs: Rectangle {
25 background: i == 0 ? red : i == 1 ? green : blue;
26 min-height: 50px;
27 TouchArea {
28 clicked => { last_clicked = 10 + x_; }
29 }
30 }
31 }
32
33 property<int> last_clicked;
34}
35/*
36```cpp
37auto handle = TestCase::create();
38const TestCase &instance = *handle;
39
40slint_testing::send_mouse_click(&instance, 5., 455.);
41assert_eq(instance.get_last_clicked(), 0);
42slint_testing::send_mouse_click(&instance, 5., 305.);
43assert_eq(instance.get_last_clicked(), 11);
44slint_testing::send_mouse_click(&instance, 5., 295.);
45assert_eq(instance.get_last_clicked(), 3);
46slint_testing::send_mouse_click(&instance, 5., 95.);
47assert_eq(instance.get_last_clicked(), 1);
48```
49
50
51```rust
52let instance = TestCase::new().unwrap();
53
54slint_testing::send_mouse_click(&instance, 5., 455.);
55assert_eq!(instance.get_last_clicked(), 0);
56slint_testing::send_mouse_click(&instance, 5., 305.);
57assert_eq!(instance.get_last_clicked(), 11);
58slint_testing::send_mouse_click(&instance, 5., 295.);
59assert_eq!(instance.get_last_clicked(), 3);
60slint_testing::send_mouse_click(&instance, 5., 95.);
61assert_eq!(instance.get_last_clicked(), 1);
62```
63
64```js
65var instance = new slint.TestCase();
66slintlib.private_api.send_mouse_click(instance, 5., 455.);
67assert.equal(instance.last_clicked, 0);
68slintlib.private_api.send_mouse_click(instance, 5., 305.);
69assert.equal(instance.last_clicked, 11);
70slintlib.private_api.send_mouse_click(instance, 5., 295.);
71assert.equal(instance.last_clicked, 3);
72slintlib.private_api.send_mouse_click(instance, 5., 95.);
73assert.equal(instance.last_clicked, 1);
74```
75*/
76