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
9MaybeClip := Rectangle {
10 width: 10phx;
11 height: 10phx;
12 property <int> touch;
13 Rectangle {
14 background: red;
15 x: 5phx;
16 y: -10phx;
17 width: 15phx;
18 height: 15phx;
19 TouchArea {
20 clicked => { touch+=1; }
21 }
22 }
23}
24
25component ClipAlias {
26 in property c <=> r.clip;
27 r := Rectangle {
28 width: 0px;
29 TouchArea {
30 width: root.width;
31 clicked => {
32 debug("Error");
33 }
34 }
35 }
36}
37
38TestCase := Rectangle {
39 height: 100phx;
40 width: 100phx;
41 property <int> touch1 <=> el1.touch;
42 property <int> touch2 <=> el2.touch;
43 property <bool> el1clip;
44
45 el1 := MaybeClip {
46 clip <=> el1clip;
47 x: 10phx;
48 y: 10phx;
49 }
50
51 el2 := MaybeClip {
52 clip: true;
53 x: 30phx;
54 y: 30phx;
55 }
56
57 // MaybeClip must be inlined when "clip" is set, but not when it isn't. Test that we can have
58 // a combination of inlined and non inlined item
59 MaybeClip { x: 5000px; }
60
61 ClipAlias { c: true; width: 100%; height:100%; }
62
63 test_rect := Rectangle { clip: true; }
64 property <bool> test: test_rect.clip;
65}
66
67/*
68```cpp
69auto handle = TestCase::create();
70const TestCase &instance = *handle;
71
72assert_eq(instance.get_test(), true);
73assert_eq(instance.get_el1clip(), false);
74
75// clip, outside
76slint_testing::send_mouse_click(&instance, 37., 27.);
77assert_eq(instance.get_touch1(), 0);
78assert_eq(instance.get_touch2(), 0);
79
80// clip, inside
81slint_testing::send_mouse_click(&instance, 37., 33.);
82assert_eq(instance.get_touch1(), 0);
83assert_eq(instance.get_touch2(), 1);
84
85
86// no-clip, outside
87slint_testing::send_mouse_click(&instance, 17., 7.);
88assert_eq(instance.get_touch1(), 1);
89assert_eq(instance.get_touch2(), 1);
90
91// no-clip, inside
92slint_testing::send_mouse_click(&instance, 17., 13.);
93assert_eq(instance.get_touch1(), 2);
94assert_eq(instance.get_touch2(), 1);
95
96// now clip also el1
97instance.set_el1clip(true);
98slint_testing::send_mouse_click(&instance, 17., 7.);
99assert_eq(instance.get_touch1(), 2);
100assert_eq(instance.get_touch2(), 1);
101
102
103```
104
105
106```rust
107let instance = TestCase::new().unwrap();
108
109assert_eq!(instance.get_test(), true);
110assert_eq!(instance.get_el1clip(), false);
111
112// clip, outside
113slint_testing::send_mouse_click(&instance, 37., 27.);
114assert_eq!(instance.get_touch1(), 0, "a. touch1");
115assert_eq!(instance.get_touch2(), 0, "a. touch2");
116
117// clip, inside
118slint_testing::send_mouse_click(&instance, 37., 33.);
119assert_eq!(instance.get_touch1(), 0, "b. touch1");
120assert_eq!(instance.get_touch2(), 1, "b. touch2");
121
122// no-clip, outside
123slint_testing::send_mouse_click(&instance, 17., 7.);
124assert_eq!(instance.get_touch1(), 1, "c. touch1");
125assert_eq!(instance.get_touch2(), 1, "c. touch2");
126
127// no-clip, inside
128slint_testing::send_mouse_click(&instance, 17., 13.);
129assert_eq!(instance.get_touch1(), 2, "d. touch1");
130assert_eq!(instance.get_touch2(), 1, "d. touch2");
131
132// now clip also el1
133instance.set_el1clip(true);
134slint_testing::send_mouse_click(&instance, 17., 7.);
135assert_eq!(instance.get_touch1(), 2, "e. touch1");
136assert_eq!(instance.get_touch2(), 1, "e. touch2");
137```
138
139*/
140}
141
142#[test] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
143 use i_slint_backend_testing as slint_testing;
144 slint_testing::init();
145 let instance = TestCase::new().unwrap();
146
147 assert_eq!(instance.get_test(), true);
148 assert_eq!(instance.get_el1clip(), false);
149
150 // clip, outside
151 slint_testing::send_mouse_click(&instance, 37., 27.);
152 assert_eq!(instance.get_touch1(), 0, "a. touch1");
153 assert_eq!(instance.get_touch2(), 0, "a. touch2");
154
155 // clip, inside
156 slint_testing::send_mouse_click(&instance, 37., 33.);
157 assert_eq!(instance.get_touch1(), 0, "b. touch1");
158 assert_eq!(instance.get_touch2(), 1, "b. touch2");
159
160 // no-clip, outside
161 slint_testing::send_mouse_click(&instance, 17., 7.);
162 assert_eq!(instance.get_touch1(), 1, "c. touch1");
163 assert_eq!(instance.get_touch2(), 1, "c. touch2");
164
165 // no-clip, inside
166 slint_testing::send_mouse_click(&instance, 17., 13.);
167 assert_eq!(instance.get_touch1(), 2, "d. touch1");
168 assert_eq!(instance.get_touch2(), 1, "d. touch2");
169
170 // now clip also el1
171 instance.set_el1clip(true);
172 slint_testing::send_mouse_click(&instance, 17., 7.);
173 assert_eq!(instance.get_touch1(), 2, "e. touch1");
174 assert_eq!(instance.get_touch2(), 1, "e. touch2");
175 Ok(())
176}