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 | MaybeClip := 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 | |
25 | component 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 | |
38 | TestCase := 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 |
69 | auto handle = TestCase::create(); |
70 | const TestCase &instance = *handle; |
71 | |
72 | assert_eq(instance.get_test(), true); |
73 | assert_eq(instance.get_el1clip(), false); |
74 | |
75 | // clip, outside |
76 | slint_testing::send_mouse_click(&instance, 37., 27.); |
77 | assert_eq(instance.get_touch1(), 0); |
78 | assert_eq(instance.get_touch2(), 0); |
79 | |
80 | // clip, inside |
81 | slint_testing::send_mouse_click(&instance, 37., 33.); |
82 | assert_eq(instance.get_touch1(), 0); |
83 | assert_eq(instance.get_touch2(), 1); |
84 | |
85 | |
86 | // no-clip, outside |
87 | slint_testing::send_mouse_click(&instance, 17., 7.); |
88 | assert_eq(instance.get_touch1(), 1); |
89 | assert_eq(instance.get_touch2(), 1); |
90 | |
91 | // no-clip, inside |
92 | slint_testing::send_mouse_click(&instance, 17., 13.); |
93 | assert_eq(instance.get_touch1(), 2); |
94 | assert_eq(instance.get_touch2(), 1); |
95 | |
96 | // now clip also el1 |
97 | instance.set_el1clip(true); |
98 | slint_testing::send_mouse_click(&instance, 17., 7.); |
99 | assert_eq(instance.get_touch1(), 2); |
100 | assert_eq(instance.get_touch2(), 1); |
101 | |
102 | |
103 | ``` |
104 | |
105 | |
106 | ```rust |
107 | let instance = TestCase::new().unwrap(); |
108 | |
109 | assert_eq!(instance.get_test(), true); |
110 | assert_eq!(instance.get_el1clip(), false); |
111 | |
112 | // clip, outside |
113 | slint_testing::send_mouse_click(&instance, 37., 27.); |
114 | assert_eq!(instance.get_touch1(), 0, "a. touch1"); |
115 | assert_eq!(instance.get_touch2(), 0, "a. touch2"); |
116 | |
117 | // clip, inside |
118 | slint_testing::send_mouse_click(&instance, 37., 33.); |
119 | assert_eq!(instance.get_touch1(), 0, "b. touch1"); |
120 | assert_eq!(instance.get_touch2(), 1, "b. touch2"); |
121 | |
122 | // no-clip, outside |
123 | slint_testing::send_mouse_click(&instance, 17., 7.); |
124 | assert_eq!(instance.get_touch1(), 1, "c. touch1"); |
125 | assert_eq!(instance.get_touch2(), 1, "c. touch2"); |
126 | |
127 | // no-clip, inside |
128 | slint_testing::send_mouse_click(&instance, 17., 13.); |
129 | assert_eq!(instance.get_touch1(), 2, "d. touch1"); |
130 | assert_eq!(instance.get_touch2(), 1, "d. touch2"); |
131 | |
132 | // now clip also el1 |
133 | instance.set_el1clip(true); |
134 | slint_testing::send_mouse_click(&instance, 17., 7.); |
135 | assert_eq!(instance.get_touch1(), 2, "e. touch1"); |
136 | assert_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 | } |