1// Copyright © SixtyFPS GmbH <info@slint.dev>
2// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
3
4
5SubWithConstraints := Rectangle {
6 min-height: 20px;
7}
8
9TestCase := Rectangle {
10 width: 300phx;
11 height: 300phx;
12
13 layout := GridLayout {
14 spacing: 0phx;
15 padding: 0phx;
16 Row {
17 rect1 := Rectangle {
18 background: red;
19 width: 10%;
20 }
21 rect2 := Rectangle {
22 background: blue;
23 height: 30%;
24 }
25 }
26
27 Row {
28 rect3 := SubWithConstraints { // min-height should be ignored because we override
29 background: green;
30 height: 20phx;
31 }
32 }
33
34 Row {
35 rect4 := Rectangle {
36 background: cyan;
37 }
38 rect5 := Rectangle {
39 background: yellow;
40 }
41 }
42
43
44 }
45
46 property <length> expected_y1: 300phx*0.3;
47 property <length> expected_y2: 300phx*0.3 + 20phx;
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 == expected_x1 && rect3.height == 20phx;
53 property <bool> rect4_pos_ok: rect4.x == 0phx && rect4.y == expected_y2 && rect4.width == expected_x1 && rect4.height == 300phx - expected_y2;
54 property <bool> rect5_pos_ok: rect5.x == expected_x1 && rect5.y == expected_y2 && rect5.width == 270phx && rect5.height == 300phx - expected_y2;
55}
56
57/*
58
59```cpp
60auto handle = TestCase::create();
61const TestCase &instance = *handle;
62slint_testing::send_mouse_click(&instance, 5., 95.);
63assert(instance.get_rect1_pos_ok());
64assert(instance.get_rect2_pos_ok());
65assert(instance.get_rect3_pos_ok());
66assert(instance.get_rect4_pos_ok());
67assert(instance.get_rect5_pos_ok());
68```
69
70```rust
71let instance = TestCase::new().unwrap();
72slint_testing::send_mouse_click(&instance, 5., 95.);
73assert!(instance.get_rect1_pos_ok());
74assert!(instance.get_rect2_pos_ok());
75assert!(instance.get_rect3_pos_ok());
76assert!(instance.get_rect4_pos_ok());
77assert!(instance.get_rect5_pos_ok());
78```
79
80
81```js
82var instance = new slint.TestCase();
83slintlib.private_api.send_mouse_click(instance, 5., 5.);
84assert(instance.rect1_pos_ok);
85assert(instance.rect2_pos_ok);
86assert(instance.rect3_pos_ok);
87assert(instance.rect4_pos_ok);
88assert(instance.rect5_pos_ok);
89```
90*/
91