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 := Rectangle {
6 width: 300phx;
7 height: 300phx;
8
9 VerticalLayout {
10 spacing: 0phx;
11 padding: 0phx;
12 hl1 := HorizontalLayout {
13 spacing: 0phx;
14 padding: 0phx;
15 rect1 := Rectangle {
16 background: red;
17 width: 10%;
18 }
19 rect2 := Rectangle {
20 background: blue;
21 height: 90px;
22 }
23 }
24
25 rect3 := Rectangle {
26 background: green;
27 height: 15%;
28 width: 100%;
29 }
30
31 hl2 := HorizontalLayout {
32 spacing: 0phx;
33 padding: 0phx;
34 rect4 := Rectangle {
35 background: cyan;
36 }
37 rect5 := Rectangle {
38 background: yellow;
39 width: 90%;
40 }
41 }
42
43
44 }
45
46 property <length> expected_y1: 90phx;
47 property <length> expected_y2: 90phx + 300phx * 0.15;
48 property <length> expected_x1: 30phx;
49
50 property <bool> rect1_pos_ok: rect1.x == 0phx && rect1.y == 0phx && rect1.width == expected_x1 && rect1.height == expected_y1;
51 property <bool> rect2_pos_ok: rect2.x == expected_x1 && rect2.y == 0phx && rect2.width == 270phx && rect2.height == expected_y1;
52 property <bool> rect3_pos_ok: rect3.x == 0phx && rect3.y == expected_y1 && rect3.width == 300phx && rect3.height == 300phx * 0.15;
53 property <bool> rect4_pos_ok: rect4.x == 0phx && hl2.y == expected_y2 && rect4.width == expected_x1 && rect4.height == 300phx - expected_y2;
54 property <bool> rect5_pos_ok: rect5.x == expected_x1 && hl2.y == expected_y2 && rect5.width == 270phx && rect5.height == 300phx - expected_y2;
55
56 property <bool> test: rect1_pos_ok && rect2_pos_ok && rect3_pos_ok && rect4_pos_ok && rect5_pos_ok;
57}
58
59/*
60
61```cpp
62auto handle = TestCase::create();
63const TestCase &instance = *handle;
64slint_testing::send_mouse_click(&instance, 5., 95.);
65assert(instance.get_rect1_pos_ok());
66assert(instance.get_rect2_pos_ok());
67assert(instance.get_rect3_pos_ok());
68assert(instance.get_rect4_pos_ok());
69assert(instance.get_rect5_pos_ok());
70```
71
72```rust
73let instance = TestCase::new().unwrap();
74slint_testing::send_mouse_click(&instance, 5., 95.);
75assert!(instance.get_rect1_pos_ok());
76assert!(instance.get_rect2_pos_ok());
77assert!(instance.get_rect3_pos_ok());
78assert!(instance.get_rect4_pos_ok());
79assert!(instance.get_rect5_pos_ok());
80```
81
82
83```js
84var instance = new slint.TestCase();
85slintlib.private_api.send_mouse_click(instance, 5., 5.);
86assert(instance.rect1_pos_ok);
87assert(instance.rect2_pos_ok);
88assert(instance.rect3_pos_ok);
89assert(instance.rect4_pos_ok);
90assert(instance.rect5_pos_ok);
91```
92*/
93}
94
95#[test] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
96 use i_slint_backend_testing as slint_testing;
97 slint_testing::init();
98 let instance = TestCase::new().unwrap();
99 slint_testing::send_mouse_click(&instance, x:5., y:95.);
100 assert!(instance.get_rect1_pos_ok());
101 assert!(instance.get_rect2_pos_ok());
102 assert!(instance.get_rect3_pos_ok());
103 assert!(instance.get_rect4_pos_ok());
104 assert!(instance.get_rect5_pos_ok());
105 Ok(())
106}