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
5TestCase := 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
36use slint::{platform::WindowEvent, platform::PointerEventButton, LogicalPosition};
37let instance = TestCase::new().unwrap();
38
39// First, try to scroll up
40instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(150.0, 200.0) });
41slint_testing::mock_elapsed_time(16);
42instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(150.0, 200.0), button: PointerEventButton::Left });
43slint_testing::mock_elapsed_time(16);
44instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(150.0, 205.0) });
45slint_testing::mock_elapsed_time(16);
46instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(150.0, 290.0) });
47instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(150.0, 300.0) });
48// shouldn't move because we are already up
49assert_eq!(instance.get_inner_x(), 0.);
50assert_eq!(instance.get_outer_y(), 0.);
51
52// now, scroll down
53instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(150.0, 202.0) });
54assert_eq!(instance.get_inner_x(), 0.);
55assert_eq!(instance.get_outer_y(), 0.);
56instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(150.0, 200.0) });
57assert_eq!(instance.get_inner_x(), 0.);
58assert_eq!(instance.get_outer_y(), 0.);
59instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(150.0, 198.0) });
60assert_eq!(instance.get_inner_x(), 0.);
61assert_eq!(instance.get_outer_y(), 2.);
62instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(150.0, 170.0) });
63assert_eq!(instance.get_inner_x(), 0.);
64assert_eq!(instance.get_outer_y(), 30.);
65instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(150.0, 150.0) });
66assert_eq!(instance.get_inner_x(), 0.);
67assert_eq!(instance.get_outer_y(), 50.);
68instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0, 150.0) });
69assert_eq!(instance.get_inner_x(), 0.);
70assert_eq!(instance.get_outer_y(), 50.);
71slint_testing::mock_elapsed_time(100);
72instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0, -2000.0) });
73assert_eq!(instance.get_inner_x(), 0.);
74// all the way down
75assert_eq!(instance.get_outer_y(), 500.);
76slint_testing::mock_elapsed_time(100);
77instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(250.0, -2000.0), button: PointerEventButton::Left });
78slint_testing::mock_elapsed_time(1000);
79assert_eq!(instance.get_inner_x(), 0.);
80assert_eq!(instance.get_outer_y(), 500.);
81
82// Now, try to go to the right
83instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(100.0, 100.0), button: PointerEventButton::Left });
84slint_testing::mock_elapsed_time(16);
85assert_eq!(instance.get_inner_x(), 0.);
86assert_eq!(instance.get_outer_y(), 500.);
87instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(90.0, 100.0) });
88slint_testing::mock_elapsed_time(120); // we need to wait enough because of the delay in the outer one
89instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(90.0, 100.0) });
90assert_eq!(instance.get_inner_x(), 10.);
91assert_eq!(instance.get_outer_y(), 500.);
92instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(20.0, 100.0) });
93slint_testing::mock_elapsed_time(16);
94assert_eq!(instance.get_inner_x(), 80.);
95assert_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
98instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(10.0, 190.0) });
99slint_testing::mock_elapsed_time(16);
100assert_eq!(instance.get_inner_x(), 80.);
101assert_eq!(instance.get_outer_y(), 410.);
102instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(150.0, 200.0) });
103slint_testing::mock_elapsed_time(16);
104assert_eq!(instance.get_inner_x(), 80.);
105assert_eq!(instance.get_outer_y(), 400.);
106slint_testing::mock_elapsed_time(1600);
107instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(150.0, 200.0), button: PointerEventButton::Left });
108slint_testing::mock_elapsed_time(16000); // finish the animation
109
110
111// scroll to the left
112let old_outer_y = instance.get_outer_y();
113instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(100.0, 100.0), button: PointerEventButton::Left });
114slint_testing::mock_elapsed_time(160);
115assert_eq!(instance.get_inner_x(), 80.);
116assert_eq!(instance.get_outer_y(), old_outer_y);
117// 103 is bellow the threshold, 120 is not
118instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(120.0, 103.0) });
119slint_testing::mock_elapsed_time(16);
120assert_eq!(instance.get_inner_x(), 60.);
121assert_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}