1 | #![allow (deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/elements"# ] |
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 | |
6 | TestCase := Window { |
7 | width: 500phx; |
8 | height: 500phx; |
9 | |
10 | f1 := Flickable { |
11 | x: 0phx; |
12 | width: 250phx; |
13 | viewport-height: 800phx; |
14 | |
15 | t1 := TouchArea { |
16 | height: 50phx; |
17 | y: 0px; |
18 | Rectangle { background: parent.has-hover ? red: blue; } |
19 | } |
20 | t1sec := TouchArea { |
21 | height: 10phx; |
22 | y: 50px; |
23 | Rectangle { background: parent.has-hover ? red: blue; } |
24 | } |
25 | } |
26 | |
27 | Flickable { |
28 | x: 250phx; |
29 | width: 250phx; |
30 | viewport-width: 800phx; |
31 | |
32 | t2 := TouchArea { |
33 | width: 50phx; |
34 | Rectangle { background: parent.has-hover ? green: yellow; } |
35 | } |
36 | } |
37 | |
38 | out property<bool> t1-has-hover: t1.has-hover; |
39 | out property<bool> t1sec-has-hover: t1sec.has-hover; |
40 | out property<bool> t2-has-hover: t2.has-hover; |
41 | |
42 | in-out property f1_pos <=> f1.viewport_y; |
43 | } |
44 | |
45 | /* |
46 | ```rust |
47 | // Test that mouse exit events are dispatched while scrolling |
48 | use slint::{platform::WindowEvent, LogicalPosition, platform::PointerEventButton}; |
49 | let instance = TestCase::new().unwrap(); |
50 | // Vertical |
51 | assert_eq!(instance.get_t1_has_hover(), false); |
52 | assert_eq!(instance.get_t1sec_has_hover(), false); |
53 | assert_eq!(instance.get_t2_has_hover(), false); |
54 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(25.0, 25.0) }); |
55 | assert_eq!(instance.get_t1_has_hover(), true); |
56 | assert_eq!(instance.get_t1sec_has_hover(), false); |
57 | assert_eq!(instance.get_t2_has_hover(), false); |
58 | instance.window().dispatch_event(WindowEvent::PointerScrolled { position: LogicalPosition::new(25.0, 25.0), delta_x: 0.0, delta_y: -30.0 }); |
59 | assert_eq!(instance.get_t1_has_hover(), false); |
60 | assert_eq!(instance.get_t1sec_has_hover(), true); |
61 | assert_eq!(instance.get_t2_has_hover(), false); |
62 | assert_eq!(instance.get_f1_pos(), -30.0); |
63 | |
64 | instance.window().dispatch_event(WindowEvent::PointerScrolled { position: LogicalPosition::new(25.0, 25.0), delta_x: 0.0, delta_y: -30.0 }); |
65 | assert_eq!(instance.get_t1_has_hover(), false); |
66 | assert_eq!(instance.get_t1sec_has_hover(), false); |
67 | assert_eq!(instance.get_t2_has_hover(), false); |
68 | assert_eq!(instance.get_f1_pos(), -60.0); |
69 | |
70 | |
71 | // Horizontal |
72 | assert_eq!(instance.get_t2_has_hover(), false); |
73 | assert_eq!(instance.get_t1_has_hover(), false); |
74 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(275.0, 25.0) }); |
75 | assert_eq!(instance.get_t2_has_hover(), true); |
76 | assert_eq!(instance.get_t1_has_hover(), false); |
77 | instance.window().dispatch_event(WindowEvent::PointerScrolled { position: LogicalPosition::new(275.0, 25.0), delta_x: -30.0, delta_y: 0.0 }); |
78 | assert_eq!(instance.get_t2_has_hover(), false); |
79 | assert_eq!(instance.get_t1_has_hover(), false); |
80 | |
81 | |
82 | |
83 | |
84 | // Test that it's not flicking when the mouse is released |
85 | assert_eq!(instance.get_f1_pos(), -60.0); |
86 | instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(25.0, 125.0), button: PointerEventButton::Left }); |
87 | slint_testing::mock_elapsed_time(100); |
88 | instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(25.0, 125.0), button: PointerEventButton::Left }); |
89 | slint_testing::mock_elapsed_time(100); |
90 | assert_eq!(instance.get_f1_pos(), -60.0); |
91 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(30.0, 25.0) }); |
92 | assert_eq!(instance.get_f1_pos(), -60.0); |
93 | ``` |
94 | |
95 | |
96 | */ |
97 | } |
98 | |
99 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
100 | use i_slint_backend_testing as slint_testing; |
101 | slint_testing::init(); |
102 | // Test that mouse exit events are dispatched while scrolling |
103 | use slint::{platform::WindowEvent, LogicalPosition, platform::PointerEventButton}; |
104 | let instance = TestCase::new().unwrap(); |
105 | // Vertical |
106 | assert_eq!(instance.get_t1_has_hover(), false); |
107 | assert_eq!(instance.get_t1sec_has_hover(), false); |
108 | assert_eq!(instance.get_t2_has_hover(), false); |
109 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(25.0, 25.0) }); |
110 | assert_eq!(instance.get_t1_has_hover(), true); |
111 | assert_eq!(instance.get_t1sec_has_hover(), false); |
112 | assert_eq!(instance.get_t2_has_hover(), false); |
113 | instance.window().dispatch_event(WindowEvent::PointerScrolled { position: LogicalPosition::new(25.0, 25.0), delta_x: 0.0, delta_y: -30.0 }); |
114 | assert_eq!(instance.get_t1_has_hover(), false); |
115 | assert_eq!(instance.get_t1sec_has_hover(), true); |
116 | assert_eq!(instance.get_t2_has_hover(), false); |
117 | assert_eq!(instance.get_f1_pos(), -30.0); |
118 | |
119 | instance.window().dispatch_event(WindowEvent::PointerScrolled { position: LogicalPosition::new(25.0, 25.0), delta_x: 0.0, delta_y: -30.0 }); |
120 | assert_eq!(instance.get_t1_has_hover(), false); |
121 | assert_eq!(instance.get_t1sec_has_hover(), false); |
122 | assert_eq!(instance.get_t2_has_hover(), false); |
123 | assert_eq!(instance.get_f1_pos(), -60.0); |
124 | |
125 | |
126 | // Horizontal |
127 | assert_eq!(instance.get_t2_has_hover(), false); |
128 | assert_eq!(instance.get_t1_has_hover(), false); |
129 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(275.0, 25.0) }); |
130 | assert_eq!(instance.get_t2_has_hover(), true); |
131 | assert_eq!(instance.get_t1_has_hover(), false); |
132 | instance.window().dispatch_event(WindowEvent::PointerScrolled { position: LogicalPosition::new(275.0, 25.0), delta_x: -30.0, delta_y: 0.0 }); |
133 | assert_eq!(instance.get_t2_has_hover(), false); |
134 | assert_eq!(instance.get_t1_has_hover(), false); |
135 | |
136 | |
137 | |
138 | |
139 | // Test that it's not flicking when the mouse is released |
140 | assert_eq!(instance.get_f1_pos(), -60.0); |
141 | instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(25.0, 125.0), button: PointerEventButton::Left }); |
142 | slint_testing::mock_elapsed_time(100); |
143 | instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(25.0, 125.0), button: PointerEventButton::Left }); |
144 | slint_testing::mock_elapsed_time(100); |
145 | assert_eq!(instance.get_f1_pos(), -60.0); |
146 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(30.0, 25.0) }); |
147 | assert_eq!(instance.get_f1_pos(), -60.0); |
148 | Ok(()) |
149 | } |