1#![allow(deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/issues"#]
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
6import { ListView } from "std-widgets.slint";
7
8export component TestCase {
9 height: 100px;
10 width: 100px;
11 in-out property <int> clicked;
12 in-out property viewport-y <=> lv.viewport-y;
13 in-out property <[int]> mod: [0,1,2,3,4,5,6,7,8,9];
14
15
16
17 lv := ListView {
18 for i in mod: Rectangle {
19 height: 20px;
20 property <int> internal_state: 1;
21 TouchArea {
22 clicked => {
23 root.clicked += internal_state * i;
24 internal_state += 10000;
25 }
26 }
27 }
28 }
29
30 Text { text: clicked; }
31
32}
33
34/*
35
36
37```rust
38let instance = TestCase::new().unwrap();
39
40slint_testing::send_mouse_click(&instance, 50., 5.);
41assert_eq!(instance.get_clicked(), 0);
42
43slint_testing::send_mouse_click(&instance, 50., 25.);
44assert_eq!(instance.get_clicked(), 1);
45instance.set_clicked(0);
46
47slint_testing::send_mouse_click(&instance, 50., 85.);
48assert_eq!(instance.get_clicked(), 4);
49
50instance.set_clicked(0);
51
52let another_model = std::rc::Rc::new(slint::VecModel::<i32>::from(
53 vec![10,11,12,13,14,15,16,17,18,19]));
54
55instance.set_mod(slint::ModelRc::from(another_model.clone()));
56
57slint_testing::send_mouse_click(&instance, 50., 5.);
58assert_eq!(instance.get_clicked(), 10);
59
60instance.set_clicked(0);
61
62slint_testing::send_mouse_click(&instance, 50., 45.);
63assert_eq!(instance.get_clicked(), 12);
64instance.set_clicked(0);
65
66slint_testing::send_mouse_click(&instance, 50., 85.);
67assert_eq!(instance.get_clicked(), 14);
68
69```
70
71```cpp
72auto handle = TestCase::create();
73const TestCase &instance = *handle;
74
75slint_testing::send_mouse_click(&instance, 50., 5.);
76assert_eq(instance.get_clicked(), 0);
77
78slint_testing::send_mouse_click(&instance, 50., 25.);
79assert_eq(instance.get_clicked(), 1);
80instance.set_clicked(0);
81
82slint_testing::send_mouse_click(&instance, 50., 85.);
83assert_eq(instance.get_clicked(), 4);
84
85instance.set_clicked(0);
86
87auto another_model = std::make_shared<slint::VectorModel<int>>(std::vector{10, 11, 12, 13, 14, 15, 16 });
88instance.set_mod(another_model);
89
90slint_testing::send_mouse_click(&instance, 50., 5.);
91assert_eq(instance.get_clicked(), 10);
92
93instance.set_clicked(0);
94
95slint_testing::send_mouse_click(&instance, 50., 45.);
96assert_eq(instance.get_clicked(), 12);
97instance.set_clicked(0);
98
99slint_testing::send_mouse_click(&instance, 50., 85.);
100assert_eq(instance.get_clicked(), 14);
101
102
103```
104
105
106*/
107}
108
109#[test] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
110 use i_slint_backend_testing as slint_testing;
111 slint_testing::init();
112 let instance = TestCase::new().unwrap();
113
114 slint_testing::send_mouse_click(&instance, 50., 5.);
115 assert_eq!(instance.get_clicked(), 0);
116
117 slint_testing::send_mouse_click(&instance, 50., 25.);
118 assert_eq!(instance.get_clicked(), 1);
119 instance.set_clicked(0);
120
121 slint_testing::send_mouse_click(&instance, 50., 85.);
122 assert_eq!(instance.get_clicked(), 4);
123
124 instance.set_clicked(0);
125
126 let another_model = std::rc::Rc::new(slint::VecModel::<i32>::from(
127 vec![10,11,12,13,14,15,16,17,18,19]));
128
129 instance.set_mod(slint::ModelRc::from(another_model.clone()));
130
131 slint_testing::send_mouse_click(&instance, 50., 5.);
132 assert_eq!(instance.get_clicked(), 10);
133
134 instance.set_clicked(0);
135
136 slint_testing::send_mouse_click(&instance, 50., 45.);
137 assert_eq!(instance.get_clicked(), 12);
138 instance.set_clicked(0);
139
140 slint_testing::send_mouse_click(&instance, 50., 85.);
141 assert_eq!(instance.get_clicked(), 14);
142
143 Ok(())
144}