1 | #![allow (deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/elements"# ] |
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 | TestCase := Window { |
6 | width: 500px; |
7 | height: 500px; |
8 | no-frame: false; |
9 | |
10 | outer := Flickable { |
11 | x: 10px; |
12 | y: 10px; |
13 | width: parent.width - 20px; |
14 | height: parent.height - 20px; |
15 | viewport_width: width; |
16 | viewport_height: 980px; |
17 | |
18 | inner := Flickable { |
19 | viewport_width: 1500px; |
20 | Rectangle { |
21 | background: @radial-gradient(circle, yellow, blue, red, green); |
22 | } |
23 | } |
24 | } |
25 | |
26 | property<length> outer_y: - outer.viewport-y; |
27 | property<length> inner_x: - inner.viewport-x; |
28 | |
29 | property <bool> test: outer.viewport-x == 0 && inner.viewport-y == 0; |
30 | |
31 | } |
32 | |
33 | /* |
34 | |
35 | ```rust |
36 | use slint::{platform::WindowEvent, platform::PointerEventButton, LogicalPosition}; |
37 | let instance = TestCase::new().unwrap(); |
38 | |
39 | // First, try to scroll up |
40 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(150.0, 200.0) }); |
41 | slint_testing::mock_elapsed_time(16); |
42 | instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(150.0, 200.0), button: PointerEventButton::Left }); |
43 | slint_testing::mock_elapsed_time(16); |
44 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(150.0, 205.0) }); |
45 | slint_testing::mock_elapsed_time(16); |
46 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(150.0, 290.0) }); |
47 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(150.0, 300.0) }); |
48 | // shouldn't move because we are already up |
49 | assert_eq!(instance.get_inner_x(), 0.); |
50 | assert_eq!(instance.get_outer_y(), 0.); |
51 | |
52 | // now, scroll down |
53 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(150.0, 202.0) }); |
54 | assert_eq!(instance.get_inner_x(), 0.); |
55 | assert_eq!(instance.get_outer_y(), 0.); |
56 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(150.0, 200.0) }); |
57 | assert_eq!(instance.get_inner_x(), 0.); |
58 | assert_eq!(instance.get_outer_y(), 0.); |
59 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(150.0, 198.0) }); |
60 | assert_eq!(instance.get_inner_x(), 0.); |
61 | assert_eq!(instance.get_outer_y(), 2.); |
62 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(150.0, 170.0) }); |
63 | assert_eq!(instance.get_inner_x(), 0.); |
64 | assert_eq!(instance.get_outer_y(), 30.); |
65 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(150.0, 150.0) }); |
66 | assert_eq!(instance.get_inner_x(), 0.); |
67 | assert_eq!(instance.get_outer_y(), 50.); |
68 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0, 150.0) }); |
69 | assert_eq!(instance.get_inner_x(), 0.); |
70 | assert_eq!(instance.get_outer_y(), 50.); |
71 | slint_testing::mock_elapsed_time(100); |
72 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0, -2000.0) }); |
73 | assert_eq!(instance.get_inner_x(), 0.); |
74 | // all the way down |
75 | assert_eq!(instance.get_outer_y(), 500.); |
76 | slint_testing::mock_elapsed_time(100); |
77 | instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(250.0, -2000.0), button: PointerEventButton::Left }); |
78 | slint_testing::mock_elapsed_time(1000); |
79 | assert_eq!(instance.get_inner_x(), 0.); |
80 | assert_eq!(instance.get_outer_y(), 500.); |
81 | |
82 | // Now, try to go to the right |
83 | instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(100.0, 100.0), button: PointerEventButton::Left }); |
84 | slint_testing::mock_elapsed_time(16); |
85 | assert_eq!(instance.get_inner_x(), 0.); |
86 | assert_eq!(instance.get_outer_y(), 500.); |
87 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(90.0, 100.0) }); |
88 | slint_testing::mock_elapsed_time(120); // we need to wait enough because of the delay in the outer one |
89 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(90.0, 100.0) }); |
90 | assert_eq!(instance.get_inner_x(), 10.); |
91 | assert_eq!(instance.get_outer_y(), 500.); |
92 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(20.0, 100.0) }); |
93 | slint_testing::mock_elapsed_time(16); |
94 | assert_eq!(instance.get_inner_x(), 80.); |
95 | assert_eq!(instance.get_outer_y(), 500.); |
96 | |
97 | // Scolling up still work as the outer flickable now intersepcts it, and then the inner one lost |
98 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(10.0, 190.0) }); |
99 | slint_testing::mock_elapsed_time(16); |
100 | assert_eq!(instance.get_inner_x(), 80.); |
101 | assert_eq!(instance.get_outer_y(), 410.); |
102 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(150.0, 200.0) }); |
103 | slint_testing::mock_elapsed_time(16); |
104 | assert_eq!(instance.get_inner_x(), 80.); |
105 | assert_eq!(instance.get_outer_y(), 400.); |
106 | slint_testing::mock_elapsed_time(1600); |
107 | instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(150.0, 200.0), button: PointerEventButton::Left }); |
108 | slint_testing::mock_elapsed_time(16000); // finish the animation |
109 | |
110 | |
111 | // scroll to the left |
112 | let old_outer_y = instance.get_outer_y(); |
113 | instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(100.0, 100.0), button: PointerEventButton::Left }); |
114 | slint_testing::mock_elapsed_time(160); |
115 | assert_eq!(instance.get_inner_x(), 80.); |
116 | assert_eq!(instance.get_outer_y(), old_outer_y); |
117 | // 103 is bellow the threshold, 120 is not |
118 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(120.0, 103.0) }); |
119 | slint_testing::mock_elapsed_time(16); |
120 | assert_eq!(instance.get_inner_x(), 60.); |
121 | assert_eq!(instance.get_outer_y(), old_outer_y); |
122 | |
123 | ``` |
124 | |
125 | */ |
126 | } |
127 | |
128 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
129 | use i_slint_backend_testing as slint_testing; |
130 | slint_testing::init(); |
131 | use slint::{platform::WindowEvent, platform::PointerEventButton, LogicalPosition}; |
132 | let instance = TestCase::new().unwrap(); |
133 | |
134 | // First, try to scroll up |
135 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(150.0, 200.0) }); |
136 | slint_testing::mock_elapsed_time(16); |
137 | instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(150.0, 200.0), button: PointerEventButton::Left }); |
138 | slint_testing::mock_elapsed_time(16); |
139 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(150.0, 205.0) }); |
140 | slint_testing::mock_elapsed_time(16); |
141 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(150.0, 290.0) }); |
142 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(150.0, 300.0) }); |
143 | // shouldn't move because we are already up |
144 | assert_eq!(instance.get_inner_x(), 0.); |
145 | assert_eq!(instance.get_outer_y(), 0.); |
146 | |
147 | // now, scroll down |
148 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(150.0, 202.0) }); |
149 | assert_eq!(instance.get_inner_x(), 0.); |
150 | assert_eq!(instance.get_outer_y(), 0.); |
151 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(150.0, 200.0) }); |
152 | assert_eq!(instance.get_inner_x(), 0.); |
153 | assert_eq!(instance.get_outer_y(), 0.); |
154 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(150.0, 198.0) }); |
155 | assert_eq!(instance.get_inner_x(), 0.); |
156 | assert_eq!(instance.get_outer_y(), 2.); |
157 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(150.0, 170.0) }); |
158 | assert_eq!(instance.get_inner_x(), 0.); |
159 | assert_eq!(instance.get_outer_y(), 30.); |
160 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(150.0, 150.0) }); |
161 | assert_eq!(instance.get_inner_x(), 0.); |
162 | assert_eq!(instance.get_outer_y(), 50.); |
163 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0, 150.0) }); |
164 | assert_eq!(instance.get_inner_x(), 0.); |
165 | assert_eq!(instance.get_outer_y(), 50.); |
166 | slint_testing::mock_elapsed_time(100); |
167 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0, -2000.0) }); |
168 | assert_eq!(instance.get_inner_x(), 0.); |
169 | // all the way down |
170 | assert_eq!(instance.get_outer_y(), 500.); |
171 | slint_testing::mock_elapsed_time(100); |
172 | instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(250.0, -2000.0), button: PointerEventButton::Left }); |
173 | slint_testing::mock_elapsed_time(1000); |
174 | assert_eq!(instance.get_inner_x(), 0.); |
175 | assert_eq!(instance.get_outer_y(), 500.); |
176 | |
177 | // Now, try to go to the right |
178 | instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(100.0, 100.0), button: PointerEventButton::Left }); |
179 | slint_testing::mock_elapsed_time(16); |
180 | assert_eq!(instance.get_inner_x(), 0.); |
181 | assert_eq!(instance.get_outer_y(), 500.); |
182 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(90.0, 100.0) }); |
183 | slint_testing::mock_elapsed_time(120); // we need to wait enough because of the delay in the outer one |
184 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(90.0, 100.0) }); |
185 | assert_eq!(instance.get_inner_x(), 10.); |
186 | assert_eq!(instance.get_outer_y(), 500.); |
187 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(20.0, 100.0) }); |
188 | slint_testing::mock_elapsed_time(16); |
189 | assert_eq!(instance.get_inner_x(), 80.); |
190 | assert_eq!(instance.get_outer_y(), 500.); |
191 | |
192 | // Scolling up still work as the outer flickable now intersepcts it, and then the inner one lost |
193 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(10.0, 190.0) }); |
194 | slint_testing::mock_elapsed_time(16); |
195 | assert_eq!(instance.get_inner_x(), 80.); |
196 | assert_eq!(instance.get_outer_y(), 410.); |
197 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(150.0, 200.0) }); |
198 | slint_testing::mock_elapsed_time(16); |
199 | assert_eq!(instance.get_inner_x(), 80.); |
200 | assert_eq!(instance.get_outer_y(), 400.); |
201 | slint_testing::mock_elapsed_time(1600); |
202 | instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(150.0, 200.0), button: PointerEventButton::Left }); |
203 | slint_testing::mock_elapsed_time(16000); // finish the animation |
204 | |
205 | |
206 | // scroll to the left |
207 | let old_outer_y = instance.get_outer_y(); |
208 | instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(100.0, 100.0), button: PointerEventButton::Left }); |
209 | slint_testing::mock_elapsed_time(160); |
210 | assert_eq!(instance.get_inner_x(), 80.); |
211 | assert_eq!(instance.get_outer_y(), old_outer_y); |
212 | // 103 is bellow the threshold, 120 is not |
213 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(120.0, 103.0) }); |
214 | slint_testing::mock_elapsed_time(16); |
215 | assert_eq!(instance.get_inner_x(), 60.); |
216 | assert_eq!(instance.get_outer_y(), old_outer_y); |
217 | |
218 | Ok(()) |
219 | } |