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
5component Clip {
6 // the presence of a Clip element should not impact the rest
7}
8
9
10MaybeVisible := Rectangle {
11 width: 10phx;
12 height: 10phx;
13 property <int> touch;
14 out property has-hover <=> ta.has-hover;
15 Rectangle {
16 background: red;
17 x: 5phx;
18 y: -10phx;
19 width: 15phx;
20 height: 15phx;
21 ta := TouchArea {
22 clicked => { touch+=1; }
23 }
24 }
25}
26
27Invisible := TouchArea {
28 visible: false;
29}
30
31component VisibleAlias {
32 in property v <=> r.visible;
33 r := Rectangle {
34 TouchArea {
35 clicked => {
36 debug("Error");
37 }
38 }
39 }
40}
41
42TestCase := Rectangle {
43 height: 100phx;
44 width: 100phx;
45 property <int> touch1 <=> el1.touch;
46 property <int> touch2 <=> el2.touch;
47 property <bool> el1visible : true;
48 out property el1-has-hover <=> el1.has-hover;
49
50 el1 := MaybeVisible {
51 visible <=> el1visible;
52 x: 10phx;
53 y: 10phx;
54 }
55
56 el2 := MaybeVisible {
57 visible: false;
58 x: 30phx;
59 y: 30phx;
60 }
61
62 Invisible { }
63
64 VisibleAlias { v:false; width: 100%; height: 100%; }
65
66 test_rect := Rectangle { }
67 property <bool> test: test_rect.visible && !el2.visible && el1.visible;
68}
69
70/*
71```cpp
72auto handle = TestCase::create();
73const TestCase &instance = *handle;
74
75assert_eq(instance.get_test(), true);
76assert_eq(instance.get_el1visible(), true);
77
78// el2 !visible, outside
79slint_testing::send_mouse_click(&instance, 37., 27.);
80assert_eq(instance.get_touch1(), 0);
81assert_eq(instance.get_touch2(), 0);
82assert(!instance.get_el1_has_hover());
83
84// el2 !visible, inside
85slint_testing::send_mouse_click(&instance, 37., 33.);
86assert_eq(instance.get_touch1(), 0);
87assert_eq(instance.get_touch2(), 0);
88assert(!instance.get_el1_has_hover());
89
90
91// el1 visible, outside
92slint_testing::send_mouse_click(&instance, 17., 7.);
93assert_eq(instance.get_touch1(), 1);
94assert_eq(instance.get_touch2(), 0);
95assert(instance.get_el1_has_hover());
96
97// el1 visible, inside
98slint_testing::send_mouse_click(&instance, 17., 13.);
99assert_eq(instance.get_touch1(), 2);
100assert_eq(instance.get_touch2(), 0);
101assert(instance.get_el1_has_hover());
102
103// now makes el invisible
104instance.set_el1visible(false);
105slint_testing::send_mouse_click(&instance, 17., 7.);
106assert_eq(instance.get_touch1(), 2);
107assert_eq(instance.get_touch2(), 0);
108assert(!instance.get_el1_has_hover());
109
110```
111
112
113```rust
114let instance = TestCase::new().unwrap();
115
116
117assert_eq!(instance.get_test(), true);
118assert_eq!(instance.get_el1visible(), true);
119
120// el2 !visible, outside
121slint_testing::send_mouse_click(&instance, 37., 27.);
122assert_eq!(instance.get_touch1(), 0);
123assert_eq!(instance.get_touch2(), 0);
124
125// el2 !visible, inside
126slint_testing::send_mouse_click(&instance, 37., 33.);
127assert_eq!(instance.get_touch1(), 0);
128assert_eq!(instance.get_touch2(), 0);
129assert!(!instance.get_el1_has_hover());
130
131
132// el1 visible, outside
133slint_testing::send_mouse_click(&instance, 17., 7.);
134assert_eq!(instance.get_touch1(), 1);
135assert_eq!(instance.get_touch2(), 0);
136assert!(instance.get_el1_has_hover());
137
138// el1 visible, inside
139slint_testing::send_mouse_click(&instance, 17., 13.);
140assert_eq!(instance.get_touch1(), 2);
141assert_eq!(instance.get_touch2(), 0);
142assert!(instance.get_el1_has_hover());
143
144// now makes el invisible
145instance.set_el1visible(false);
146slint_testing::send_mouse_click(&instance, 17., 7.);
147assert_eq!(instance.get_touch1(), 2);
148assert_eq!(instance.get_touch2(), 0);
149assert!(!instance.get_el1_has_hover());
150```
151
152*/
153}
154
155#[test] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
156 use i_slint_backend_testing as slint_testing;
157 slint_testing::init();
158 let instance = TestCase::new().unwrap();
159
160
161 assert_eq!(instance.get_test(), true);
162 assert_eq!(instance.get_el1visible(), true);
163
164 // el2 !visible, outside
165 slint_testing::send_mouse_click(&instance, 37., 27.);
166 assert_eq!(instance.get_touch1(), 0);
167 assert_eq!(instance.get_touch2(), 0);
168
169 // el2 !visible, inside
170 slint_testing::send_mouse_click(&instance, 37., 33.);
171 assert_eq!(instance.get_touch1(), 0);
172 assert_eq!(instance.get_touch2(), 0);
173 assert!(!instance.get_el1_has_hover());
174
175
176 // el1 visible, outside
177 slint_testing::send_mouse_click(&instance, 17., 7.);
178 assert_eq!(instance.get_touch1(), 1);
179 assert_eq!(instance.get_touch2(), 0);
180 assert!(instance.get_el1_has_hover());
181
182 // el1 visible, inside
183 slint_testing::send_mouse_click(&instance, 17., 13.);
184 assert_eq!(instance.get_touch1(), 2);
185 assert_eq!(instance.get_touch2(), 0);
186 assert!(instance.get_el1_has_hover());
187
188 // now makes el invisible
189 instance.set_el1visible(false);
190 slint_testing::send_mouse_click(&instance, 17., 7.);
191 assert_eq!(instance.get_touch1(), 2);
192 assert_eq!(instance.get_touch2(), 0);
193 assert!(!instance.get_el1_has_hover());
194 Ok(())
195}