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
5MyWid := Rectangle {
6 min-width: 20phx;
7 min-height: 20phx;
8 horizontal-stretch:0;
9 vertical-stretch:0;
10}
11
12
13TestCase := Rectangle {
14 width: 300phx;
15 height: 300phx;
16
17 VerticalLayout {
18 alignment: end;
19 padding: 0phx;
20 spacing: 5phx;
21 ls := HorizontalLayout {
22 padding: 0phx;
23 spacing: 2phx;
24 alignment: start;
25 rs1 := MyWid { background: blue; }
26 rs2 := MyWid { background: red; }
27 rs3 := MyWid { background: yellow; }
28 }
29 lb := HorizontalLayout {
30 padding: 0phx;
31 spacing: 2phx;
32 alignment: space-between;
33 rb1 := MyWid { background: green; }
34 rb2 := MyWid { background: black; }
35 rb3 := MyWid { background: orange; }
36 }
37 la := HorizontalLayout {
38 padding: 0phx;
39 spacing: 2phx;
40 alignment: space-around;
41 ra1 := MyWid { background: pink; }
42 ra2 := MyWid { background: lightblue; }
43 ra3 := MyWid { background: gray; }
44 }
45 lc := HorizontalLayout {
46 padding: 0phx;
47 spacing: 2phx;
48 alignment: center;
49 rc1 := MyWid { background: violet; }
50 rc2 := MyWid { background: lightgreen; }
51 rc3 := MyWid { background: purple; }
52 }
53 }
54
55 // check the vertical layout
56 property <bool> v1: ls.y == height - (4*20phx + 15phx) && rs1.y == 0 && rs1.y == rs2.y && rs1.y == rs3.y;
57 property <bool> v2: lb.y == height - (3*20phx + 10phx) && rb1.y == 0 && rb1.y == rb2.y && rb1.y == rb3.y;
58 property <bool> v3: la.y == height - (2*20phx + 5phx) && ra1.y == 0 && ra1.y == ra2.y && ra1.y == ra3.y;
59 property <bool> v4: lc.y == height - (1*20phx + 0phx) && rc1.y == 0 && rc1.y == rc2.y && rc1.y == rc3.y;
60
61 // check the horizontal layout
62 property <bool> s1: rs1.x == 0phx && rs2.x == 22phx && rs3.x == 44phx;
63 property <bool> c1: rc1.x == (width - 64phx)/2 && rc2.x == (width - rc2.width)/2 && rc3.x == (width + 64phx)/2 - ra3.width;
64 property <bool> b1: rb1.x == 0phx && rb2.x == (width - rb2.width)/2 && rb3.x == width - rb3.width;
65
66 property <bool> test: v1 && v2 && v3 && v4 && s1 && c1 && b1;
67}
68
69/*
70
71```cpp
72auto handle = TestCase::create();
73const TestCase &instance = *handle;
74assert(instance.get_v1());
75assert(instance.get_v2());
76assert(instance.get_v3());
77assert(instance.get_v4());
78assert(instance.get_s1());
79assert(instance.get_b1());
80assert(instance.get_c1());
81```
82
83
84```rust
85let instance = TestCase::new().unwrap();
86assert!(instance.get_v1());
87assert!(instance.get_v2());
88assert!(instance.get_v3());
89assert!(instance.get_v4());
90assert!(instance.get_s1());
91assert!(instance.get_b1());
92assert!(instance.get_c1());
93```
94
95```js
96var instance = new slint.TestCase();
97slintlib.private_api.send_mouse_click(instance, 5., 5.);
98assert(instance.v1);
99assert(instance.v2);
100assert(instance.v3);
101assert(instance.v4);
102assert(instance.s1);
103assert(instance.b1);
104assert(instance.c1);
105```
106
107*/
108}
109
110#[test] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
111 use i_slint_backend_testing as slint_testing;
112 slint_testing::init();
113 let instance = TestCase::new().unwrap();
114 assert!(instance.get_v1());
115 assert!(instance.get_v2());
116 assert!(instance.get_v3());
117 assert!(instance.get_v4());
118 assert!(instance.get_s1());
119 assert!(instance.get_b1());
120 assert!(instance.get_c1());
121 Ok(())
122}