1// Copyright © SixtyFPS GmbH <info@slint.dev>
2// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial
3
4
5import { ListView } from "std-widgets.slint";
6
7export component TestCase {
8 height: 100px;
9 width: 100px;
10 in-out property <int> clicked;
11 in-out property viewport-y <=> lv.viewport-y;
12 in-out property <[int]> mod: [0,1,2,3,4,5,6,7,8,9];
13
14
15
16 lv := ListView {
17 for i in mod: Rectangle {
18 height: 20px;
19 property <int> internal_state: 1;
20 TouchArea {
21 clicked => {
22 root.clicked += internal_state * i;
23 internal_state += 10000;
24 }
25 }
26 }
27 }
28
29 Text { text: clicked; }
30
31}
32
33/*
34
35
36```rust
37let instance = TestCase::new().unwrap();
38
39slint_testing::send_mouse_click(&instance, 50., 5.);
40assert_eq!(instance.get_clicked(), 0);
41
42slint_testing::send_mouse_click(&instance, 50., 25.);
43assert_eq!(instance.get_clicked(), 1);
44instance.set_clicked(0);
45
46slint_testing::send_mouse_click(&instance, 50., 85.);
47assert_eq!(instance.get_clicked(), 4);
48
49instance.set_clicked(0);
50
51let another_model = std::rc::Rc::new(slint::VecModel::<i32>::from(
52 vec![10,11,12,13,14,15,16,17,18,19]));
53
54instance.set_mod(slint::ModelRc::from(another_model.clone()));
55
56slint_testing::send_mouse_click(&instance, 50., 5.);
57assert_eq!(instance.get_clicked(), 10);
58
59instance.set_clicked(0);
60
61slint_testing::send_mouse_click(&instance, 50., 45.);
62assert_eq!(instance.get_clicked(), 12);
63instance.set_clicked(0);
64
65slint_testing::send_mouse_click(&instance, 50., 85.);
66assert_eq!(instance.get_clicked(), 14);
67
68```
69
70```cpp
71auto handle = TestCase::create();
72const TestCase &instance = *handle;
73
74slint_testing::send_mouse_click(&instance, 50., 5.);
75assert_eq(instance.get_clicked(), 0);
76
77slint_testing::send_mouse_click(&instance, 50., 25.);
78assert_eq(instance.get_clicked(), 1);
79instance.set_clicked(0);
80
81slint_testing::send_mouse_click(&instance, 50., 85.);
82assert_eq(instance.get_clicked(), 4);
83
84instance.set_clicked(0);
85
86auto another_model = std::make_shared<slint::VectorModel<int>>(std::vector{10, 11, 12, 13, 14, 15, 16 });
87instance.set_mod(another_model);
88
89slint_testing::send_mouse_click(&instance, 50., 5.);
90assert_eq(instance.get_clicked(), 10);
91
92instance.set_clicked(0);
93
94slint_testing::send_mouse_click(&instance, 50., 45.);
95assert_eq(instance.get_clicked(), 12);
96instance.set_clicked(0);
97
98slint_testing::send_mouse_click(&instance, 50., 85.);
99assert_eq(instance.get_clicked(), 14);
100
101
102```
103
104
105*/
106