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 | component Clip { |
6 | // the presence of a Clip element should not impact the rest |
7 | } |
8 | |
9 | |
10 | MaybeVisible := 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 | |
27 | Invisible := TouchArea { |
28 | visible: false; |
29 | } |
30 | |
31 | component VisibleAlias { |
32 | in property v <=> r.visible; |
33 | r := Rectangle { |
34 | TouchArea { |
35 | clicked => { |
36 | debug("Error" ); |
37 | } |
38 | } |
39 | } |
40 | } |
41 | |
42 | TestCase := 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 |
72 | auto handle = TestCase::create(); |
73 | const TestCase &instance = *handle; |
74 | |
75 | assert_eq(instance.get_test(), true); |
76 | assert_eq(instance.get_el1visible(), true); |
77 | |
78 | // el2 !visible, outside |
79 | slint_testing::send_mouse_click(&instance, 37., 27.); |
80 | assert_eq(instance.get_touch1(), 0); |
81 | assert_eq(instance.get_touch2(), 0); |
82 | assert(!instance.get_el1_has_hover()); |
83 | |
84 | // el2 !visible, inside |
85 | slint_testing::send_mouse_click(&instance, 37., 33.); |
86 | assert_eq(instance.get_touch1(), 0); |
87 | assert_eq(instance.get_touch2(), 0); |
88 | assert(!instance.get_el1_has_hover()); |
89 | |
90 | |
91 | // el1 visible, outside |
92 | slint_testing::send_mouse_click(&instance, 17., 7.); |
93 | assert_eq(instance.get_touch1(), 1); |
94 | assert_eq(instance.get_touch2(), 0); |
95 | assert(instance.get_el1_has_hover()); |
96 | |
97 | // el1 visible, inside |
98 | slint_testing::send_mouse_click(&instance, 17., 13.); |
99 | assert_eq(instance.get_touch1(), 2); |
100 | assert_eq(instance.get_touch2(), 0); |
101 | assert(instance.get_el1_has_hover()); |
102 | |
103 | // now makes el invisible |
104 | instance.set_el1visible(false); |
105 | slint_testing::send_mouse_click(&instance, 17., 7.); |
106 | assert_eq(instance.get_touch1(), 2); |
107 | assert_eq(instance.get_touch2(), 0); |
108 | assert(!instance.get_el1_has_hover()); |
109 | |
110 | ``` |
111 | |
112 | |
113 | ```rust |
114 | let instance = TestCase::new().unwrap(); |
115 | |
116 | |
117 | assert_eq!(instance.get_test(), true); |
118 | assert_eq!(instance.get_el1visible(), true); |
119 | |
120 | // el2 !visible, outside |
121 | slint_testing::send_mouse_click(&instance, 37., 27.); |
122 | assert_eq!(instance.get_touch1(), 0); |
123 | assert_eq!(instance.get_touch2(), 0); |
124 | |
125 | // el2 !visible, inside |
126 | slint_testing::send_mouse_click(&instance, 37., 33.); |
127 | assert_eq!(instance.get_touch1(), 0); |
128 | assert_eq!(instance.get_touch2(), 0); |
129 | assert!(!instance.get_el1_has_hover()); |
130 | |
131 | |
132 | // el1 visible, outside |
133 | slint_testing::send_mouse_click(&instance, 17., 7.); |
134 | assert_eq!(instance.get_touch1(), 1); |
135 | assert_eq!(instance.get_touch2(), 0); |
136 | assert!(instance.get_el1_has_hover()); |
137 | |
138 | // el1 visible, inside |
139 | slint_testing::send_mouse_click(&instance, 17., 13.); |
140 | assert_eq!(instance.get_touch1(), 2); |
141 | assert_eq!(instance.get_touch2(), 0); |
142 | assert!(instance.get_el1_has_hover()); |
143 | |
144 | // now makes el invisible |
145 | instance.set_el1visible(false); |
146 | slint_testing::send_mouse_click(&instance, 17., 7.); |
147 | assert_eq!(instance.get_touch1(), 2); |
148 | assert_eq!(instance.get_touch2(), 0); |
149 | assert!(!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 | } |