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