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 | |
5 | export component TestCase inherits Window { |
6 | width: 500px; |
7 | height: 500px; |
8 | in-out property<string> result; |
9 | f := Flickable { |
10 | viewport_width: 2100px; |
11 | viewport_height: 2100px; |
12 | ta1 := TouchArea { |
13 | x: 20px; |
14 | y: 20px; |
15 | width: 50px; |
16 | height: 50px; |
17 | Rectangle { background: red; } |
18 | scroll-event(e) => { |
19 | result += "ta1{" + e.delta-x/1px + "," + e.delta-y/1px + " at " + self.mouse-x/1px + "," + self.mouse-y/1px + "}" ; |
20 | accept |
21 | } |
22 | } |
23 | |
24 | ta2 := TouchArea { |
25 | x: 120px; |
26 | y: 20px; |
27 | width: 50px; |
28 | height: 50px; |
29 | Rectangle { background: green; } |
30 | scroll-event(e) => { |
31 | result += "ta2{" + e.delta-x/1px + "," + e.delta-y/1px + " at " + self.mouse-x/1px + "," + self.mouse-y/1px + "}" ; |
32 | EventResult.reject |
33 | } |
34 | } |
35 | } |
36 | |
37 | |
38 | out property<length> offset_x: -f.viewport_x; |
39 | out property<length> offset_y: -f.viewport_y; |
40 | } |
41 | |
42 | /* |
43 | |
44 | |
45 | ```rust |
46 | // Test wheel events |
47 | use slint::{LogicalPosition, platform::WindowEvent }; |
48 | let instance = TestCase::new().unwrap(); |
49 | |
50 | instance.window().dispatch_event(WindowEvent::PointerScrolled { position: LogicalPosition::new(25.0, 30.0), delta_x: -3.0, delta_y: -50.0 }); |
51 | assert_eq!(instance.get_result(), "ta1{-3,-50 at 5,10}"); |
52 | assert_eq!(instance.get_offset_y(), 0.0); |
53 | assert_eq!(instance.get_offset_x(), 0.0); |
54 | |
55 | instance.set_result("".into()); |
56 | |
57 | instance.window().dispatch_event(WindowEvent::PointerScrolled { position: LogicalPosition::new(155.0, 50.0), delta_x: -30.0, delta_y: -50.0 }); |
58 | assert_eq!(instance.get_result(), "ta2{-30,-50 at 35,30}"); |
59 | assert_eq!(instance.get_offset_x(), 30.0); |
60 | assert_eq!(instance.get_offset_y(), 50.0); |
61 | ``` |
62 | |
63 | */ |
64 | |