1#![allow(deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/children"#]
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
5TestCase := Rectangle {
6 width: 100phx;
7 height: 100phx;
8
9 property <int> touch_error;
10 property <int> touch1;
11 property <int> value;
12
13
14 HorizontalLayout {
15 spacing: 0;
16 padding: 0;
17 Rectangle {
18 background: orange;
19 z: 400;
20 TouchArea {
21 clicked => { touch_error+=78 }
22 }
23 }
24
25 Rectangle {
26 background: green;
27 z: 3;
28
29 TouchArea {
30 clicked => { touch_error+=1 }
31 }
32
33 for i in [
34 {color: #0f0, value: 8, },
35 {color: #00f, value: 9, },
36 {color: #f00, value: 10, },
37 ] : Rectangle {
38 z: 78;
39 background: i.color;
40 TouchArea {
41 clicked => {
42 root.value = i.value;
43 }
44 }
45 }
46
47 TouchArea {
48 clicked => { touch_error+=5 }
49 }
50
51 TouchArea {
52 z: 4;
53 clicked => { touch_error+=8 }
54 }
55
56 }
57
58 Rectangle {
59 background: pink;
60 z: -43;
61
62 TouchArea {
63 clicked => { touch_error+=1 }
64 }
65
66 TouchArea {
67 clicked => { touch_error+=180 }
68 }
69
70 TouchArea {
71 clicked => {
72 debug("HI");
73 touch1+=1
74 }
75 }
76
77 TouchArea {
78 z: -1;
79 clicked => { touch_error+=12 }
80 }
81 }
82 }
83}
84
85/*
86```cpp
87auto handle = TestCase::create();
88const TestCase &instance = *handle;
89
90slint_testing::send_mouse_click(&instance, 38, 5.);
91assert_eq(instance.get_touch1(), 0);
92assert_eq(instance.get_value(), 10);
93assert_eq(instance.get_touch_error(), 0);
94
95slint_testing::send_mouse_click(&instance, 95, 5.);
96assert_eq(instance.get_touch1(), 1);
97assert_eq(instance.get_value(), 10);
98assert_eq(instance.get_touch_error(), 0);
99
100```
101
102
103```rust
104let instance = TestCase::new().unwrap();
105slint_testing::send_mouse_click(&instance, 38., 5.);
106assert_eq!(instance.get_touch1(), 0);
107assert_eq!(instance.get_value(), 10);
108assert_eq!(instance.get_touch_error(), 0);
109
110slint_testing::send_mouse_click(&instance, 95., 5.);
111assert_eq!(instance.get_touch1(), 1);
112assert_eq!(instance.get_value(), 10);
113assert_eq!(instance.get_touch_error(), 0);
114```
115
116```js
117var instance = new slint.TestCase();
118
119slintlib.private_api.send_mouse_click(instance, 38., 5.);
120assert.equal(instance.touch1, 0);
121assert.equal(instance.value, 10);
122assert.equal(instance.touch_error, 0);
123
124slintlib.private_api.send_mouse_click(instance, 95., 5.);
125assert.equal(instance.touch1, 1);
126assert.equal(instance.value, 10);
127assert.equal(instance.touch_error, 0);
128```
129*/
130}
131
132#[test] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
133 use i_slint_backend_testing as slint_testing;
134 slint_testing::init();
135 let instance = TestCase::new().unwrap();
136 slint_testing::send_mouse_click(&instance, x:38., y:5.);
137 assert_eq!(instance.get_touch1(), 0);
138 assert_eq!(instance.get_value(), 10);
139 assert_eq!(instance.get_touch_error(), 0);
140
141 slint_testing::send_mouse_click(&instance, x:95., y:5.);
142 assert_eq!(instance.get_touch1(), 1);
143 assert_eq!(instance.get_value(), 10);
144 assert_eq!(instance.get_touch_error(), 0);
145 Ok(())
146}