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