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
4TestCase := Window {
5 width: 500px;
6 height: 500px;
7 no-frame: false;
8
9 outer := Flickable {
10 x: 10px;
11 y: 10px;
12 width: parent.width - 20px;
13 height: parent.height - 20px;
14 viewport_width: width;
15 viewport_height: 980px;
16
17 inner := Flickable {
18 viewport_width: 1500px;
19 Rectangle {
20 background: @radial-gradient(circle, yellow, blue, red, green);
21 }
22 }
23 }
24
25 property<length> outer_y: - outer.viewport-y;
26 property<length> inner_x: - inner.viewport-x;
27
28 property <bool> test: outer.viewport-x == 0 && inner.viewport-y == 0;
29
30}
31
32/*
33
34```rust
35use slint::{platform::WindowEvent, platform::PointerEventButton, LogicalPosition};
36let instance = TestCase::new().unwrap();
37
38// First, try to scroll up
39instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(150.0, 200.0) });
40slint_testing::mock_elapsed_time(16);
41instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(150.0, 200.0), button: PointerEventButton::Left });
42slint_testing::mock_elapsed_time(16);
43instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(150.0, 205.0) });
44slint_testing::mock_elapsed_time(16);
45instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(150.0, 290.0) });
46instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(150.0, 300.0) });
47// shouldn't move because we are already up
48assert_eq!(instance.get_inner_x(), 0.);
49assert_eq!(instance.get_outer_y(), 0.);
50
51// now, scroll down
52instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(150.0, 202.0) });
53assert_eq!(instance.get_inner_x(), 0.);
54assert_eq!(instance.get_outer_y(), 0.);
55instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(150.0, 200.0) });
56assert_eq!(instance.get_inner_x(), 0.);
57assert_eq!(instance.get_outer_y(), 0.);
58instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(150.0, 198.0) });
59assert_eq!(instance.get_inner_x(), 0.);
60assert_eq!(instance.get_outer_y(), 2.);
61instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(150.0, 170.0) });
62assert_eq!(instance.get_inner_x(), 0.);
63assert_eq!(instance.get_outer_y(), 30.);
64instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(150.0, 150.0) });
65assert_eq!(instance.get_inner_x(), 0.);
66assert_eq!(instance.get_outer_y(), 50.);
67instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0, 150.0) });
68assert_eq!(instance.get_inner_x(), 0.);
69assert_eq!(instance.get_outer_y(), 50.);
70slint_testing::mock_elapsed_time(100);
71instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0, -2000.0) });
72assert_eq!(instance.get_inner_x(), 0.);
73// all the way down
74assert_eq!(instance.get_outer_y(), 500.);
75slint_testing::mock_elapsed_time(100);
76instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(250.0, -2000.0), button: PointerEventButton::Left });
77slint_testing::mock_elapsed_time(1000);
78assert_eq!(instance.get_inner_x(), 0.);
79assert_eq!(instance.get_outer_y(), 500.);
80
81// Now, try to go to the right
82instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(100.0, 100.0), button: PointerEventButton::Left });
83slint_testing::mock_elapsed_time(16);
84assert_eq!(instance.get_inner_x(), 0.);
85assert_eq!(instance.get_outer_y(), 500.);
86instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(90.0, 100.0) });
87slint_testing::mock_elapsed_time(120); // we need to wait enough because of the delay in the outer one
88instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(90.0, 100.0) });
89assert_eq!(instance.get_inner_x(), 10.);
90assert_eq!(instance.get_outer_y(), 500.);
91instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(20.0, 100.0) });
92slint_testing::mock_elapsed_time(16);
93assert_eq!(instance.get_inner_x(), 80.);
94assert_eq!(instance.get_outer_y(), 500.);
95
96// Scolling up still work as the outer flickable now intersepcts it, and then the inner one lost
97instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(10.0, 190.0) });
98slint_testing::mock_elapsed_time(16);
99assert_eq!(instance.get_inner_x(), 80.);
100assert_eq!(instance.get_outer_y(), 410.);
101instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(150.0, 200.0) });
102slint_testing::mock_elapsed_time(16);
103assert_eq!(instance.get_inner_x(), 80.);
104assert_eq!(instance.get_outer_y(), 400.);
105slint_testing::mock_elapsed_time(1600);
106instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(150.0, 200.0), button: PointerEventButton::Left });
107slint_testing::mock_elapsed_time(16000); // finish the animation
108
109
110// scroll to the left
111let old_outer_y = instance.get_outer_y();
112instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(100.0, 100.0), button: PointerEventButton::Left });
113slint_testing::mock_elapsed_time(160);
114assert_eq!(instance.get_inner_x(), 80.);
115assert_eq!(instance.get_outer_y(), old_outer_y);
116// 103 is bellow the threshold, 120 is not
117instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(120.0, 103.0) });
118slint_testing::mock_elapsed_time(16);
119assert_eq!(instance.get_inner_x(), 60.);
120assert_eq!(instance.get_outer_y(), old_outer_y);
121
122```
123
124*/
125