1#![allow(deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/layout"#]
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
5export TestCase := Window {
6 width: 100phx;
7 height: 100phx;
8 property<int> value: -10;
9 property <bool> cond: true;
10
11 VerticalLayout {
12 padding: 0px;
13 spacing: 0px;
14
15 Rectangle {
16 background: orange;
17 TouchArea {
18 clicked => {
19 root.value = 0;
20 }
21 }
22 }
23
24 if (true) : Rectangle {
25 background: blue;
26 TouchArea {
27 clicked => {
28 root.value = 1;
29 }
30 }
31 }
32 if (cond) : Rectangle {
33 background: red;
34 TouchArea {
35 clicked => {
36 root.value = 2;
37 }
38 }
39 }
40 if (false) : Rectangle {
41 background: green;
42 TouchArea {
43 clicked => {
44 root.value = 3;
45 }
46 }
47 }
48
49 Rectangle {
50 background: pink;
51 TouchArea {
52 clicked => {
53 root.value = 4;
54 }
55 }
56 }
57 }
58}
59
60// There should be 4 rectangle: so 100 divided by 4 is 25.
61// when cond is false, there is 3, so 33.3 pixel per rectangle
62
63/*
64```cpp
65auto handle = TestCase::create();
66const TestCase &instance = *handle;
67
68slint_testing::send_mouse_click(&instance, 5., 5.);
69assert_eq(instance.get_value(), 0);
70
71slint_testing::send_mouse_click(&instance, 5., 52.);
72assert_eq(instance.get_value(), 2);
73
74slint_testing::send_mouse_click(&instance, 5., 30.);
75assert_eq(instance.get_value(), 1);
76
77slint_testing::send_mouse_click(&instance, 5., 80.);
78assert_eq(instance.get_value(), 4);
79
80instance.set_cond(false);
81slint_testing::send_mouse_click(&instance, 5., 35.);
82assert_eq(instance.get_value(), 1);
83slint_testing::send_mouse_click(&instance, 5., 30.);
84assert_eq(instance.get_value(), 0);
85slint_testing::send_mouse_click(&instance, 5., 67.);
86assert_eq(instance.get_value(), 4);
87
88instance.set_cond(true);
89slint_testing::send_mouse_click(&instance, 5., 70.);
90assert_eq(instance.get_value(), 2);
91
92```
93
94
95```rust
96let instance = TestCase::new().unwrap();
97
98slint_testing::send_mouse_click(&instance, 5., 5.);
99assert_eq!(instance.get_value(), 0);
100
101slint_testing::send_mouse_click(&instance, 5., 52.);
102assert_eq!(instance.get_value(), 2);
103
104slint_testing::send_mouse_click(&instance, 5., 30.);
105assert_eq!(instance.get_value(), 1);
106
107slint_testing::send_mouse_click(&instance, 5., 80.);
108assert_eq!(instance.get_value(), 4);
109
110instance.set_cond(false);
111slint_testing::send_mouse_click(&instance, 5., 35.);
112assert_eq!(instance.get_value(), 1);
113slint_testing::send_mouse_click(&instance, 5., 30.);
114assert_eq!(instance.get_value(), 0);
115slint_testing::send_mouse_click(&instance, 5., 67.);
116assert_eq!(instance.get_value(), 4);
117
118instance.set_cond(true);
119slint_testing::send_mouse_click(&instance, 5., 70.);
120assert_eq!(instance.get_value(), 2);
121
122
123```
124
125```js
126var instance = new slint.TestCase();
127
128slintlib.private_api.send_mouse_click(instance, 5., 5.);
129assert.equal(instance.value, 0);
130
131slintlib.private_api.send_mouse_click(instance, 5., 52.);
132assert.equal(instance.value, 2);
133
134slintlib.private_api.send_mouse_click(instance, 5., 30.);
135assert.equal(instance.value, 1);
136
137slintlib.private_api.send_mouse_click(instance, 5., 80);
138assert.equal(instance.value, 4);
139
140instance.cond = false;
141slintlib.private_api.send_mouse_click(instance, 5., 35.);
142assert.equal(instance.value, 1);
143slintlib.private_api.send_mouse_click(instance, 5., 30.);
144assert.equal(instance.value, 0);
145slintlib.private_api.send_mouse_click(instance, 5., 67.);
146assert.equal(instance.value, 4);
147
148instance.cond = true;
149slintlib.private_api.send_mouse_click(instance, 5., 70.);
150assert.equal(instance.value, 2);
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 slint_testing::send_mouse_click(&instance, 5., 5.);
161 assert_eq!(instance.get_value(), 0);
162
163 slint_testing::send_mouse_click(&instance, 5., 52.);
164 assert_eq!(instance.get_value(), 2);
165
166 slint_testing::send_mouse_click(&instance, 5., 30.);
167 assert_eq!(instance.get_value(), 1);
168
169 slint_testing::send_mouse_click(&instance, 5., 80.);
170 assert_eq!(instance.get_value(), 4);
171
172 instance.set_cond(false);
173 slint_testing::send_mouse_click(&instance, 5., 35.);
174 assert_eq!(instance.get_value(), 1);
175 slint_testing::send_mouse_click(&instance, 5., 30.);
176 assert_eq!(instance.get_value(), 0);
177 slint_testing::send_mouse_click(&instance, 5., 67.);
178 assert_eq!(instance.get_value(), 4);
179
180 instance.set_cond(true);
181 slint_testing::send_mouse_click(&instance, 5., 70.);
182 assert_eq!(instance.get_value(), 2);
183
184
185 Ok(())
186}