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 | |
5 | import { ListView } from "std-widgets.slint" ; |
6 | |
7 | export 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 |
37 | let instance = TestCase::new().unwrap(); |
38 | |
39 | slint_testing::send_mouse_click(&instance, 50., 5.); |
40 | assert_eq!(instance.get_clicked(), 0); |
41 | |
42 | slint_testing::send_mouse_click(&instance, 50., 25.); |
43 | assert_eq!(instance.get_clicked(), 1); |
44 | instance.set_clicked(0); |
45 | |
46 | slint_testing::send_mouse_click(&instance, 50., 85.); |
47 | assert_eq!(instance.get_clicked(), 4); |
48 | |
49 | instance.set_clicked(0); |
50 | |
51 | let another_model = std::rc::Rc::new(slint::VecModel::<i32>::from( |
52 | vec![10,11,12,13,14,15,16,17,18,19])); |
53 | |
54 | instance.set_mod(slint::ModelRc::from(another_model.clone())); |
55 | |
56 | slint_testing::send_mouse_click(&instance, 50., 5.); |
57 | assert_eq!(instance.get_clicked(), 10); |
58 | |
59 | instance.set_clicked(0); |
60 | |
61 | slint_testing::send_mouse_click(&instance, 50., 45.); |
62 | assert_eq!(instance.get_clicked(), 12); |
63 | instance.set_clicked(0); |
64 | |
65 | slint_testing::send_mouse_click(&instance, 50., 85.); |
66 | assert_eq!(instance.get_clicked(), 14); |
67 | |
68 | ``` |
69 | |
70 | ```cpp |
71 | auto handle = TestCase::create(); |
72 | const TestCase &instance = *handle; |
73 | |
74 | slint_testing::send_mouse_click(&instance, 50., 5.); |
75 | assert_eq(instance.get_clicked(), 0); |
76 | |
77 | slint_testing::send_mouse_click(&instance, 50., 25.); |
78 | assert_eq(instance.get_clicked(), 1); |
79 | instance.set_clicked(0); |
80 | |
81 | slint_testing::send_mouse_click(&instance, 50., 85.); |
82 | assert_eq(instance.get_clicked(), 4); |
83 | |
84 | instance.set_clicked(0); |
85 | |
86 | auto another_model = std::make_shared<slint::VectorModel<int>>(std::vector{10, 11, 12, 13, 14, 15, 16 }); |
87 | instance.set_mod(another_model); |
88 | |
89 | slint_testing::send_mouse_click(&instance, 50., 5.); |
90 | assert_eq(instance.get_clicked(), 10); |
91 | |
92 | instance.set_clicked(0); |
93 | |
94 | slint_testing::send_mouse_click(&instance, 50., 45.); |
95 | assert_eq(instance.get_clicked(), 12); |
96 | instance.set_clicked(0); |
97 | |
98 | slint_testing::send_mouse_click(&instance, 50., 85.); |
99 | assert_eq(instance.get_clicked(), 14); |
100 | |
101 | |
102 | ``` |
103 | |
104 | |
105 | */ |
106 | |