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 | TestCase := Window { |
6 | width: 500phx; |
7 | height: 500phx; |
8 | |
9 | f1 := Flickable { |
10 | x: 0phx; |
11 | width: 250phx; |
12 | viewport-height: 800phx; |
13 | |
14 | t1 := TouchArea { |
15 | height: 50phx; |
16 | y: 0px; |
17 | Rectangle { background: parent.has-hover ? red: blue; } |
18 | } |
19 | t1sec := TouchArea { |
20 | height: 10phx; |
21 | y: 50px; |
22 | Rectangle { background: parent.has-hover ? red: blue; } |
23 | } |
24 | } |
25 | |
26 | Flickable { |
27 | x: 250phx; |
28 | width: 250phx; |
29 | viewport-width: 800phx; |
30 | |
31 | t2 := TouchArea { |
32 | width: 50phx; |
33 | Rectangle { background: parent.has-hover ? green: yellow; } |
34 | } |
35 | } |
36 | |
37 | out property<bool> t1-has-hover: t1.has-hover; |
38 | out property<bool> t1sec-has-hover: t1sec.has-hover; |
39 | out property<bool> t2-has-hover: t2.has-hover; |
40 | |
41 | in-out property f1_pos <=> f1.viewport_y; |
42 | } |
43 | |
44 | /* |
45 | ```rust |
46 | // Test that mouse exit events are dispatched while scrolling |
47 | use slint::{platform::WindowEvent, LogicalPosition, platform::PointerEventButton}; |
48 | let instance = TestCase::new().unwrap(); |
49 | // Vertical |
50 | assert_eq!(instance.get_t1_has_hover(), false); |
51 | assert_eq!(instance.get_t1sec_has_hover(), false); |
52 | assert_eq!(instance.get_t2_has_hover(), false); |
53 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(25.0, 25.0) }); |
54 | assert_eq!(instance.get_t1_has_hover(), true); |
55 | assert_eq!(instance.get_t1sec_has_hover(), false); |
56 | assert_eq!(instance.get_t2_has_hover(), false); |
57 | instance.window().dispatch_event(WindowEvent::PointerScrolled { position: LogicalPosition::new(25.0, 25.0), delta_x: 0.0, delta_y: -30.0 }); |
58 | assert_eq!(instance.get_t1_has_hover(), false); |
59 | assert_eq!(instance.get_t1sec_has_hover(), true); |
60 | assert_eq!(instance.get_t2_has_hover(), false); |
61 | assert_eq!(instance.get_f1_pos(), -30.0); |
62 | |
63 | instance.window().dispatch_event(WindowEvent::PointerScrolled { position: LogicalPosition::new(25.0, 25.0), delta_x: 0.0, delta_y: -30.0 }); |
64 | assert_eq!(instance.get_t1_has_hover(), false); |
65 | assert_eq!(instance.get_t1sec_has_hover(), false); |
66 | assert_eq!(instance.get_t2_has_hover(), false); |
67 | assert_eq!(instance.get_f1_pos(), -60.0); |
68 | |
69 | |
70 | // Horizontal |
71 | assert_eq!(instance.get_t2_has_hover(), false); |
72 | assert_eq!(instance.get_t1_has_hover(), false); |
73 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(275.0, 25.0) }); |
74 | assert_eq!(instance.get_t2_has_hover(), true); |
75 | assert_eq!(instance.get_t1_has_hover(), false); |
76 | instance.window().dispatch_event(WindowEvent::PointerScrolled { position: LogicalPosition::new(275.0, 25.0), delta_x: -30.0, delta_y: 0.0 }); |
77 | assert_eq!(instance.get_t2_has_hover(), false); |
78 | assert_eq!(instance.get_t1_has_hover(), false); |
79 | |
80 | |
81 | |
82 | |
83 | // Test that it's not flicking when the mouse is released |
84 | assert_eq!(instance.get_f1_pos(), -60.0); |
85 | instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(25.0, 125.0), button: PointerEventButton::Left }); |
86 | slint_testing::mock_elapsed_time(100); |
87 | instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(25.0, 125.0), button: PointerEventButton::Left }); |
88 | slint_testing::mock_elapsed_time(100); |
89 | assert_eq!(instance.get_f1_pos(), -60.0); |
90 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(30.0, 25.0) }); |
91 | assert_eq!(instance.get_f1_pos(), -60.0); |
92 | ``` |
93 | |
94 | |
95 | */ |
96 | |