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
5TestCase := Window {
6 width: 500px;
7 height: 550px;
8 background: #ecedeb;
9
10 property<[int]> xs: [1, 2, 3];
11
12 VerticalLayout {
13 padding: 0px;
14 spacing: 0px;
15 alignment: start;
16
17 for x_[i] in xs: Rectangle {
18 background: i == 0 ? red : i == 1 ? green : blue;
19 height: 100px;
20 TouchArea {
21 clicked => { last_clicked = x_; }
22 }
23 }
24
25 for x_[i] in xs: Rectangle {
26 background: i == 0 ? red : i == 1 ? green : blue;
27 min-height: 50px;
28 TouchArea {
29 clicked => { last_clicked = 10 + x_; }
30 }
31 }
32 }
33
34 property<int> last_clicked;
35}
36/*
37```cpp
38auto handle = TestCase::create();
39const TestCase &instance = *handle;
40
41slint_testing::send_mouse_click(&instance, 5., 455.);
42assert_eq(instance.get_last_clicked(), 0);
43slint_testing::send_mouse_click(&instance, 5., 305.);
44assert_eq(instance.get_last_clicked(), 11);
45slint_testing::send_mouse_click(&instance, 5., 295.);
46assert_eq(instance.get_last_clicked(), 3);
47slint_testing::send_mouse_click(&instance, 5., 95.);
48assert_eq(instance.get_last_clicked(), 1);
49```
50
51
52```rust
53let instance = TestCase::new().unwrap();
54
55slint_testing::send_mouse_click(&instance, 5., 455.);
56assert_eq!(instance.get_last_clicked(), 0);
57slint_testing::send_mouse_click(&instance, 5., 305.);
58assert_eq!(instance.get_last_clicked(), 11);
59slint_testing::send_mouse_click(&instance, 5., 295.);
60assert_eq!(instance.get_last_clicked(), 3);
61slint_testing::send_mouse_click(&instance, 5., 95.);
62assert_eq!(instance.get_last_clicked(), 1);
63```
64
65```js
66var instance = new slint.TestCase();
67slintlib.private_api.send_mouse_click(instance, 5., 455.);
68assert.equal(instance.last_clicked, 0);
69slintlib.private_api.send_mouse_click(instance, 5., 305.);
70assert.equal(instance.last_clicked, 11);
71slintlib.private_api.send_mouse_click(instance, 5., 295.);
72assert.equal(instance.last_clicked, 3);
73slintlib.private_api.send_mouse_click(instance, 5., 95.);
74assert.equal(instance.last_clicked, 1);
75```
76*/
77}
78
79#[test] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
80 use i_slint_backend_testing as slint_testing;
81 slint_testing::init();
82 let instance = TestCase::new().unwrap();
83
84 slint_testing::send_mouse_click(&instance, x:5., y:455.);
85 assert_eq!(instance.get_last_clicked(), 0);
86 slint_testing::send_mouse_click(&instance, x:5., y:305.);
87 assert_eq!(instance.get_last_clicked(), 11);
88 slint_testing::send_mouse_click(&instance, x:5., y:295.);
89 assert_eq!(instance.get_last_clicked(), 3);
90 slint_testing::send_mouse_click(&instance, x:5., y:95.);
91 assert_eq!(instance.get_last_clicked(), 1);
92 Ok(())
93}