|
| 1 | +// Copyright © SixtyFPS GmbH <[email protected]> |
| 2 | +// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0 |
| 3 | + |
| 4 | +export 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 |
| 70 | +use slint::{platform::WindowEvent, LogicalPosition, platform::PointerEventButton}; |
| 71 | +let instance = TestCase::new().unwrap(); |
| 72 | +
|
| 73 | +assert_eq!(instance.get_result(), ""); |
| 74 | +assert_eq!(instance.get_swiping_sgh_with_ta(), false); |
| 75 | +assert_eq!(instance.get_swiping_sgh_wo_ta(), false); |
| 76 | +assert_eq!(instance.get_swiping_sgh_disabled_ta(), false); |
| 77 | +
|
| 78 | +
|
| 79 | +// With TouchArea |
| 80 | +instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0, 100.0) }); |
| 81 | +instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(100.0, 100.0), button: PointerEventButton::Left }); |
| 82 | +slint_testing::mock_elapsed_time(200); |
| 83 | +assert_eq!(instance.get_swiping_sgh_with_ta(), false); |
| 84 | +assert_eq!(instance.get_swiping_sgh_wo_ta(), false); |
| 85 | +assert_eq!(instance.get_swiping_sgh_disabled_ta(), false); |
| 86 | +instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0, 100.0) }); |
| 87 | +slint_testing::mock_elapsed_time(50); |
| 88 | +assert_eq!(instance.get_swiping_sgh_with_ta(), false); |
| 89 | +assert_eq!(instance.get_swiping_sgh_wo_ta(), false); |
| 90 | +assert_eq!(instance.get_swiping_sgh_disabled_ta(), false); |
| 91 | +instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(50.0, 50.0) }); |
| 92 | +assert_eq!(instance.get_swiping_sgh_with_ta(), true, "we should be swiping 'with-ta'"); |
| 93 | +assert_eq!(instance.get_swiping_sgh_wo_ta(), false); |
| 94 | +assert_eq!(instance.get_swiping_sgh_disabled_ta(), false); |
| 95 | +slint_testing::mock_elapsed_time(50); |
| 96 | +
|
| 97 | +
|
| 98 | +instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(250.0, 250.0) }); //outside |
| 99 | +assert_eq!(instance.get_swiping_sgh_with_ta(), true, "we should be swiping 'with-ta'"); |
| 100 | +assert_eq!(instance.get_swiping_sgh_wo_ta(), false); |
| 101 | +assert_eq!(instance.get_swiping_sgh_disabled_ta(), false); |
| 102 | +slint_testing::mock_elapsed_time(50); |
| 103 | +
|
| 104 | +instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0, 100.0) }); |
| 105 | +assert_eq!(instance.get_swiping_sgh_with_ta(), true); |
| 106 | +assert_eq!(instance.get_swiping_sgh_wo_ta(), false); |
| 107 | +assert_eq!(instance.get_swiping_sgh_disabled_ta(), false); |
| 108 | +instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(100.0, 100.0), button: PointerEventButton::Left }); |
| 109 | +assert_eq!(instance.get_swiping_sgh_with_ta(), false); |
| 110 | +assert_eq!(instance.get_swiping_sgh_wo_ta(), false); |
| 111 | +assert_eq!(instance.get_swiping_sgh_disabled_ta(), false); |
| 112 | +assert_eq!(instance.get_result(), ""); |
| 113 | +
|
| 114 | +
|
| 115 | +// Without TouhArea |
| 116 | +instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(200.0 + 100.0, 100.0) }); |
| 117 | +instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(200.0 + 100.0, 100.0), button: PointerEventButton::Left }); |
| 118 | +slint_testing::mock_elapsed_time(200); |
| 119 | +assert_eq!(instance.get_swiping_sgh_with_ta(), false); |
| 120 | +assert_eq!(instance.get_swiping_sgh_wo_ta(), false); |
| 121 | +assert_eq!(instance.get_swiping_sgh_disabled_ta(), false); |
| 122 | +instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(200.0 + 100.0, 100.0) }); |
| 123 | +slint_testing::mock_elapsed_time(50); |
| 124 | +assert_eq!(instance.get_swiping_sgh_with_ta(), false); |
| 125 | +assert_eq!(instance.get_swiping_sgh_wo_ta(), false); |
| 126 | +assert_eq!(instance.get_swiping_sgh_disabled_ta(), false); |
| 127 | +instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(200.0 + 50.0, 50.0) }); |
| 128 | +assert_eq!(instance.get_swiping_sgh_with_ta(), false); |
| 129 | +assert_eq!(instance.get_swiping_sgh_wo_ta(), true, "we should be swiping 'without-ta'"); |
| 130 | +assert_eq!(instance.get_swiping_sgh_disabled_ta(), false); |
| 131 | +slint_testing::mock_elapsed_time(50); |
| 132 | +
|
| 133 | +instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(250.0, 250.0) }); //outside |
| 134 | +assert_eq!(instance.get_swiping_sgh_with_ta(), false); |
| 135 | +assert_eq!(instance.get_swiping_sgh_wo_ta(), true); |
| 136 | +assert_eq!(instance.get_swiping_sgh_disabled_ta(), false); |
| 137 | +slint_testing::mock_elapsed_time(50); |
| 138 | +
|
| 139 | +
|
| 140 | +instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(200.0 + 100.0, 100.0) }); |
| 141 | +assert_eq!(instance.get_swiping_sgh_with_ta(), false); |
| 142 | +assert_eq!(instance.get_swiping_sgh_wo_ta(), true); |
| 143 | +assert_eq!(instance.get_swiping_sgh_disabled_ta(), false); |
| 144 | +instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(200.0 + 100.0, 100.0), button: PointerEventButton::Left }); |
| 145 | +assert_eq!(instance.get_swiping_sgh_with_ta(), false); |
| 146 | +assert_eq!(instance.get_swiping_sgh_wo_ta(), false); |
| 147 | +assert_eq!(instance.get_swiping_sgh_disabled_ta(), false); |
| 148 | +assert_eq!(instance.get_result(), ""); |
| 149 | +
|
| 150 | +// With disabled TouchArea |
| 151 | +instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0, 200.0 + 100.0) }); |
| 152 | +instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(100.0, 200.0 + 100.0), button: PointerEventButton::Left }); |
| 153 | +slint_testing::mock_elapsed_time(200); |
| 154 | +assert_eq!(instance.get_swiping_sgh_with_ta(), false); |
| 155 | +assert_eq!(instance.get_swiping_sgh_wo_ta(), false); |
| 156 | +assert_eq!(instance.get_swiping_sgh_disabled_ta(), false); |
| 157 | +instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0, 200.0 + 100.0) }); |
| 158 | +slint_testing::mock_elapsed_time(50); |
| 159 | +assert_eq!(instance.get_swiping_sgh_with_ta(), false); |
| 160 | +assert_eq!(instance.get_swiping_sgh_wo_ta(), false); |
| 161 | +assert_eq!(instance.get_swiping_sgh_disabled_ta(), false); |
| 162 | +instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(50.0, 200.0 + 50.0) }); |
| 163 | +assert_eq!(instance.get_swiping_sgh_with_ta(), false); |
| 164 | +assert_eq!(instance.get_swiping_sgh_wo_ta(), false); |
| 165 | +assert_eq!(instance.get_swiping_sgh_disabled_ta(), true, "we should be swiping 'with-disabled-ta'"); |
| 166 | +slint_testing::mock_elapsed_time(50); |
| 167 | +
|
| 168 | +
|
| 169 | +instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(250.0, 250.0) }); //outside |
| 170 | +assert_eq!(instance.get_swiping_sgh_with_ta(), false); |
| 171 | +assert_eq!(instance.get_swiping_sgh_wo_ta(), false); |
| 172 | +assert_eq!(instance.get_swiping_sgh_disabled_ta(), true); |
| 173 | +slint_testing::mock_elapsed_time(50); |
| 174 | +
|
| 175 | +instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0, 200.0 + 100.0) }); |
| 176 | +assert_eq!(instance.get_swiping_sgh_with_ta(), false); |
| 177 | +assert_eq!(instance.get_swiping_sgh_wo_ta(), false); |
| 178 | +assert_eq!(instance.get_swiping_sgh_disabled_ta(), true); |
| 179 | +instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(100.0, 200.0 + 100.0), button: PointerEventButton::Left }); |
| 180 | +assert_eq!(instance.get_swiping_sgh_with_ta(), false); |
| 181 | +assert_eq!(instance.get_swiping_sgh_wo_ta(), false); |
| 182 | +assert_eq!(instance.get_swiping_sgh_disabled_ta(), false); |
| 183 | +assert_eq!(instance.get_result(), ""); |
| 184 | +
|
| 185 | +// Do ther click, now. |
| 186 | +instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0, 100.0) }); |
| 187 | +instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(100.0, 100.0), button: PointerEventButton::Left }); |
| 188 | +slint_testing::mock_elapsed_time(200); |
| 189 | +instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(101.0, 101.0) }); |
| 190 | +assert_eq!(instance.get_swiping_sgh_with_ta(), false); |
| 191 | +assert_eq!(instance.get_swiping_sgh_wo_ta(), false); |
| 192 | +assert_eq!(instance.get_swiping_sgh_disabled_ta(), false); |
| 193 | +instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(101.0, 101.0), button: PointerEventButton::Left }); |
| 194 | +assert_eq!(instance.get_swiping_sgh_with_ta(), false); |
| 195 | +assert_eq!(instance.get_swiping_sgh_wo_ta(), false); |
| 196 | +assert_eq!(instance.get_swiping_sgh_disabled_ta(), false); |
| 197 | +assert_eq!(instance.get_result(), "ta1"); |
| 198 | +instance.set_result("".into()); |
| 199 | +
|
| 200 | +instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0 + 100.0, 100.0) }); |
| 201 | +instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(100.0 + 100.0, 100.0), button: PointerEventButton::Left }); |
| 202 | +slint_testing::mock_elapsed_time(200); |
| 203 | +instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0 + 101.0, 101.0) }); |
| 204 | +assert_eq!(instance.get_swiping_sgh_with_ta(), false); |
| 205 | +assert_eq!(instance.get_swiping_sgh_wo_ta(), false); |
| 206 | +assert_eq!(instance.get_swiping_sgh_disabled_ta(), false); |
| 207 | +instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(100.0 + 101.0, 101.0), button: PointerEventButton::Left }); |
| 208 | +assert_eq!(instance.get_swiping_sgh_with_ta(), false); |
| 209 | +assert_eq!(instance.get_swiping_sgh_wo_ta(), false); |
| 210 | +assert_eq!(instance.get_swiping_sgh_disabled_ta(), false); |
| 211 | +assert_eq!(instance.get_result(), ""); |
| 212 | +
|
| 213 | +instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0, 100.0 + 100.0) }); |
| 214 | +instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(100.0, 100.0 + 100.0), button: PointerEventButton::Left }); |
| 215 | +slint_testing::mock_elapsed_time(200); |
| 216 | +instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(101.0, 100.0 + 101.0) }); |
| 217 | +assert_eq!(instance.get_swiping_sgh_with_ta(), false); |
| 218 | +assert_eq!(instance.get_swiping_sgh_wo_ta(), false); |
| 219 | +assert_eq!(instance.get_swiping_sgh_disabled_ta(), false); |
| 220 | +instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(101.0, 100.0 + 101.0), button: PointerEventButton::Left }); |
| 221 | +assert_eq!(instance.get_swiping_sgh_with_ta(), false); |
| 222 | +assert_eq!(instance.get_swiping_sgh_wo_ta(), false); |
| 223 | +assert_eq!(instance.get_swiping_sgh_disabled_ta(), false); |
| 224 | +assert_eq!(instance.get_result(), ""); |
| 225 | +
|
| 226 | +
|
| 227 | +``` |
| 228 | +
|
| 229 | +
|
| 230 | +*/ |
0 commit comments