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 VerticalLayout {
21 padding: 1px;
22 TouchArea {
23 clicked => { last_clicked = x_; }
24 }
25 }
26 }
27
28 for x_[i] in xs: Rectangle {
29 background: i == 0 ? red : i == 1 ? green : blue;
30 min-height: 50px;
31 HorizontalLayout {
32 padding: 1px;
33 TouchArea {
34 clicked => { last_clicked = 10 + x_; }
35 }
36 }
37 }
38 }
39
40 property<int> last_clicked;
41}
42/*
43```cpp
44auto handle = TestCase::create();
45const TestCase &instance = *handle;
46
47// aim at the padding
48slint_testing::send_mouse_click(&instance, 5., 100.);
49assert_eq(instance.get_last_clicked(), 0);
50
51slint_testing::send_mouse_click(&instance, 5., 455.);
52assert_eq(instance.get_last_clicked(), 0);
53slint_testing::send_mouse_click(&instance, 5., 305.);
54assert_eq(instance.get_last_clicked(), 11);
55slint_testing::send_mouse_click(&instance, 5., 295.);
56assert_eq(instance.get_last_clicked(), 3);
57slint_testing::send_mouse_click(&instance, 5., 95.);
58assert_eq(instance.get_last_clicked(), 1);
59```
60
61
62```rust
63let instance = TestCase::new().unwrap();
64
65// aim at the padding
66slint_testing::send_mouse_click(&instance, 5., 100.);
67assert_eq!(instance.get_last_clicked(), 0);
68
69
70slint_testing::send_mouse_click(&instance, 5., 455.);
71assert_eq!(instance.get_last_clicked(), 0);
72slint_testing::send_mouse_click(&instance, 5., 305.);
73assert_eq!(instance.get_last_clicked(), 11);
74slint_testing::send_mouse_click(&instance, 5., 295.);
75assert_eq!(instance.get_last_clicked(), 3);
76slint_testing::send_mouse_click(&instance, 5., 95.);
77assert_eq!(instance.get_last_clicked(), 1);
78```
79
80```js
81var instance = new slint.TestCase();
82
83// aim at the padding
84slintlib.private_api.send_mouse_click(instance, 5., 100.);
85assert.equal(instance.last_clicked, 0);
86
87
88slintlib.private_api.send_mouse_click(instance, 5., 455.);
89assert.equal(instance.last_clicked, 0);
90slintlib.private_api.send_mouse_click(instance, 5., 305.);
91assert.equal(instance.last_clicked, 11);
92slintlib.private_api.send_mouse_click(instance, 5., 295.);
93assert.equal(instance.last_clicked, 3);
94slintlib.private_api.send_mouse_click(instance, 5., 95.);
95assert.equal(instance.last_clicked, 1);
96```
97*/
98}
99
100#[test] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
101 use i_slint_backend_testing as slint_testing;
102 slint_testing::init();
103 let instance = TestCase::new().unwrap();
104
105 // aim at the padding
106 slint_testing::send_mouse_click(&instance, x:5., y:100.);
107 assert_eq!(instance.get_last_clicked(), 0);
108
109
110 slint_testing::send_mouse_click(&instance, x:5., y:455.);
111 assert_eq!(instance.get_last_clicked(), 0);
112 slint_testing::send_mouse_click(&instance, x:5., y:305.);
113 assert_eq!(instance.get_last_clicked(), 11);
114 slint_testing::send_mouse_click(&instance, x:5., y:295.);
115 assert_eq!(instance.get_last_clicked(), 3);
116 slint_testing::send_mouse_click(&instance, x:5., y:95.);
117 assert_eq!(instance.get_last_clicked(), 1);
118 Ok(())
119}