1#![allow(deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/input"#]
2// Copyright © SixtyFPS GmbH <info@slint.dev>
3// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial
4
5
6export component TestCase inherits Window {
7 width: 500px;
8 height: 500px;
9 in-out property<string> result;
10 f := Flickable {
11 viewport_width: 2100px;
12 viewport_height: 2100px;
13 ta1 := TouchArea {
14 x: 20px;
15 y: 20px;
16 width: 50px;
17 height: 50px;
18 Rectangle { background: red; }
19 scroll-event(e) => {
20 result += "ta1{" + e.delta-x/1px + "," + e.delta-y/1px + " at " + self.mouse-x/1px + "," + self.mouse-y/1px + "}";
21 accept
22 }
23 }
24
25 ta2 := TouchArea {
26 x: 120px;
27 y: 20px;
28 width: 50px;
29 height: 50px;
30 Rectangle { background: green; }
31 scroll-event(e) => {
32 result += "ta2{" + e.delta-x/1px + "," + e.delta-y/1px + " at " + self.mouse-x/1px + "," + self.mouse-y/1px + "}";
33 EventResult.reject
34 }
35 }
36 }
37
38
39 out property<length> offset_x: -f.viewport_x;
40 out property<length> offset_y: -f.viewport_y;
41}
42
43/*
44
45
46```rust
47// Test wheel events
48use slint::{LogicalPosition, platform::WindowEvent };
49let instance = TestCase::new().unwrap();
50
51instance.window().dispatch_event(WindowEvent::PointerScrolled { position: LogicalPosition::new(25.0, 30.0), delta_x: -3.0, delta_y: -50.0 });
52assert_eq!(instance.get_result(), "ta1{-3,-50 at 5,10}");
53assert_eq!(instance.get_offset_y(), 0.0);
54assert_eq!(instance.get_offset_x(), 0.0);
55
56instance.set_result("".into());
57
58instance.window().dispatch_event(WindowEvent::PointerScrolled { position: LogicalPosition::new(155.0, 50.0), delta_x: -30.0, delta_y: -50.0 });
59assert_eq!(instance.get_result(), "ta2{-30,-50 at 35,30}");
60assert_eq!(instance.get_offset_x(), 30.0);
61assert_eq!(instance.get_offset_y(), 50.0);
62```
63
64*/
65}
66
67#[test] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
68 use i_slint_backend_testing as slint_testing;
69 slint_testing::init();
70 // Test wheel events
71 use slint::{LogicalPosition, platform::WindowEvent };
72 let instance = TestCase::new().unwrap();
73
74 instance.window().dispatch_event(WindowEvent::PointerScrolled { position: LogicalPosition::new(x:25.0, y:30.0), delta_x: -3.0, delta_y: -50.0 });
75 assert_eq!(instance.get_result(), "ta1{-3,-50 at 5,10}");
76 assert_eq!(instance.get_offset_y(), 0.0);
77 assert_eq!(instance.get_offset_x(), 0.0);
78
79 instance.set_result("".into());
80
81 instance.window().dispatch_event(WindowEvent::PointerScrolled { position: LogicalPosition::new(x:155.0, y:50.0), delta_x: -30.0, delta_y: -50.0 });
82 assert_eq!(instance.get_result(), "ta2{-30,-50 at 35,30}");
83 assert_eq!(instance.get_offset_x(), 30.0);
84 assert_eq!(instance.get_offset_y(), 50.0);
85 Ok(())
86}