1// Copyright © SixtyFPS GmbH <info@slint.dev>
2// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
3
4export component TestCase inherits Window {
5 width: 400px;
6 height: 400px;
7
8 in-out property <string> result;
9 out property swiping-sgh-with-ta <=> sgh-with-ta.swiping;
10 out property swiping-sgh-wo-ta <=> sgh-wo-ta.swiping;
11 out property swiping-sgh-disabled-ta <=> sgh-disabled-ta.swiping;
12
13
14 // With a TouchArea
15 sgh-with-ta := SwipeGestureHandler {
16 width: 200px;
17 height: 200px;
18 x: 0px;
19 y: 0px;
20 Rectangle {
21 background: yellow;
22 }
23 handle-swipe-down: true;
24 handle-swipe-up: true;
25 handle-swipe-left: true;
26 handle-swipe-right: true;
27 TouchArea {
28 clicked => { result += "ta1"; }
29 }
30 }
31
32 // Without a TouchArea
33 sgh-wo-ta := SwipeGestureHandler {
34 width: 200px;
35 height: 200px;
36 x: 200px;
37 y: 0px;
38 Rectangle {
39 background: green;
40 }
41 handle-swipe-down: true;
42 handle-swipe-up: true;
43 handle-swipe-left: true;
44 handle-swipe-right: true;
45 }
46
47 // With a disabled one
48 sgh-disabled-ta := SwipeGestureHandler {
49 width: 200px;
50 height: 200px;
51 x: 0px;
52 y: 200px;
53 Rectangle {
54 background: red;
55 }
56 handle-swipe-down: true;
57 handle-swipe-up: true;
58 handle-swipe-left: true;
59 handle-swipe-right: true;
60 ta := TouchArea {
61 enabled: false;
62 clicked => { result += "ta2"; }
63 }
64 }
65}
66
67
68/*
69```rust
70use slint::{platform::WindowEvent, LogicalPosition, platform::PointerEventButton};
71let instance = TestCase::new().unwrap();
72
73assert_eq!(instance.get_result(), "");
74assert_eq!(instance.get_swiping_sgh_with_ta(), false);
75assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
76assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
77
78
79// With TouchArea
80instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0, 100.0) });
81instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(100.0, 100.0), button: PointerEventButton::Left });
82slint_testing::mock_elapsed_time(200);
83assert_eq!(instance.get_swiping_sgh_with_ta(), false);
84assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
85assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
86instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0, 100.0) });
87slint_testing::mock_elapsed_time(50);
88assert_eq!(instance.get_swiping_sgh_with_ta(), false);
89assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
90assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
91instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(50.0, 50.0) });
92assert_eq!(instance.get_swiping_sgh_with_ta(), true, "we should be swiping 'with-ta'");
93assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
94assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
95slint_testing::mock_elapsed_time(50);
96
97
98instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(250.0, 250.0) }); //outside
99assert_eq!(instance.get_swiping_sgh_with_ta(), true, "we should be swiping 'with-ta'");
100assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
101assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
102slint_testing::mock_elapsed_time(50);
103
104instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0, 100.0) });
105assert_eq!(instance.get_swiping_sgh_with_ta(), true);
106assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
107assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
108instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(100.0, 100.0), button: PointerEventButton::Left });
109assert_eq!(instance.get_swiping_sgh_with_ta(), false);
110assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
111assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
112assert_eq!(instance.get_result(), "");
113
114
115// Without TouchArea
116instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(200.0 + 100.0, 100.0) });
117instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(200.0 + 100.0, 100.0), button: PointerEventButton::Left });
118slint_testing::mock_elapsed_time(200);
119assert_eq!(instance.get_swiping_sgh_with_ta(), false);
120assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
121assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
122instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(200.0 + 100.0, 100.0) });
123slint_testing::mock_elapsed_time(50);
124assert_eq!(instance.get_swiping_sgh_with_ta(), false);
125assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
126assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
127instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(200.0 + 50.0, 50.0) });
128assert_eq!(instance.get_swiping_sgh_with_ta(), false);
129assert_eq!(instance.get_swiping_sgh_wo_ta(), true, "we should be swiping 'without-ta'");
130assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
131slint_testing::mock_elapsed_time(50);
132
133instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(250.0, 250.0) }); //outside
134assert_eq!(instance.get_swiping_sgh_with_ta(), false);
135assert_eq!(instance.get_swiping_sgh_wo_ta(), true);
136assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
137slint_testing::mock_elapsed_time(50);
138
139
140instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(200.0 + 100.0, 100.0) });
141assert_eq!(instance.get_swiping_sgh_with_ta(), false);
142assert_eq!(instance.get_swiping_sgh_wo_ta(), true);
143assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
144instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(200.0 + 100.0, 100.0), button: PointerEventButton::Left });
145assert_eq!(instance.get_swiping_sgh_with_ta(), false);
146assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
147assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
148assert_eq!(instance.get_result(), "");
149
150// With disabled TouchArea
151instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0, 200.0 + 100.0) });
152instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(100.0, 200.0 + 100.0), button: PointerEventButton::Left });
153slint_testing::mock_elapsed_time(200);
154assert_eq!(instance.get_swiping_sgh_with_ta(), false);
155assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
156assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
157instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0, 200.0 + 100.0) });
158slint_testing::mock_elapsed_time(50);
159assert_eq!(instance.get_swiping_sgh_with_ta(), false);
160assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
161assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
162instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(50.0, 200.0 + 50.0) });
163assert_eq!(instance.get_swiping_sgh_with_ta(), false);
164assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
165assert_eq!(instance.get_swiping_sgh_disabled_ta(), true, "we should be swiping 'with-disabled-ta'");
166slint_testing::mock_elapsed_time(50);
167
168
169instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(250.0, 250.0) }); //outside
170assert_eq!(instance.get_swiping_sgh_with_ta(), false);
171assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
172assert_eq!(instance.get_swiping_sgh_disabled_ta(), true);
173slint_testing::mock_elapsed_time(50);
174
175instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0, 200.0 + 100.0) });
176assert_eq!(instance.get_swiping_sgh_with_ta(), false);
177assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
178assert_eq!(instance.get_swiping_sgh_disabled_ta(), true);
179instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(100.0, 200.0 + 100.0), button: PointerEventButton::Left });
180assert_eq!(instance.get_swiping_sgh_with_ta(), false);
181assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
182assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
183assert_eq!(instance.get_result(), "");
184
185// Do the click, now.
186instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0, 100.0) });
187instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(100.0, 100.0), button: PointerEventButton::Left });
188slint_testing::mock_elapsed_time(200);
189instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(101.0, 101.0) });
190assert_eq!(instance.get_swiping_sgh_with_ta(), false);
191assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
192assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
193instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(101.0, 101.0), button: PointerEventButton::Left });
194assert_eq!(instance.get_swiping_sgh_with_ta(), false);
195assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
196assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
197assert_eq!(instance.get_result(), "ta1");
198instance.set_result("".into());
199
200instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0 + 100.0, 100.0) });
201instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(100.0 + 100.0, 100.0), button: PointerEventButton::Left });
202slint_testing::mock_elapsed_time(200);
203instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0 + 101.0, 101.0) });
204assert_eq!(instance.get_swiping_sgh_with_ta(), false);
205assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
206assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
207instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(100.0 + 101.0, 101.0), button: PointerEventButton::Left });
208assert_eq!(instance.get_swiping_sgh_with_ta(), false);
209assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
210assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
211assert_eq!(instance.get_result(), "");
212
213instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0, 100.0 + 100.0) });
214instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(100.0, 100.0 + 100.0), button: PointerEventButton::Left });
215slint_testing::mock_elapsed_time(200);
216instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(101.0, 100.0 + 101.0) });
217assert_eq!(instance.get_swiping_sgh_with_ta(), false);
218assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
219assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
220instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(101.0, 100.0 + 101.0), button: PointerEventButton::Left });
221assert_eq!(instance.get_swiping_sgh_with_ta(), false);
222assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
223assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
224assert_eq!(instance.get_result(), "");
225
226
227```
228
229
230*/
231