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 | |
5 | |
6 | RectRed := Rectangle { |
7 | background: red; |
8 | min_width: 200phx; |
9 | horizontal-stretch: 0; |
10 | HorizontalLayout { |
11 | spacing: 10px; |
12 | padding: 0phx; |
13 | rect_green := Rectangle { |
14 | background: green; |
15 | max_width: 50phx; |
16 | max_height: 50phx; |
17 | } |
18 | rect_pink := Rectangle { |
19 | background: pink; |
20 | } |
21 | } |
22 | |
23 | property <bool> rect_green_ok: |
24 | rect_green.x == 0phx && |
25 | rect_green.y == 0phx && |
26 | rect_green.width == 50phx && |
27 | rect_green.height == 50phx; |
28 | property <bool> rect_pink_ok: |
29 | rect_pink.x == 60phx && |
30 | rect_pink.y == 0phx && |
31 | rect_pink.width == 140phx && |
32 | rect_pink.height == 50phx; |
33 | } |
34 | |
35 | RedBlue := HorizontalLayout { |
36 | spacing: 0phx; |
37 | padding: 0phx; |
38 | |
39 | rect_red := RectRed {} |
40 | rect_blue := Rectangle { |
41 | horizontal-stretch: 1; |
42 | background: blue; |
43 | } |
44 | |
45 | property rect_green_ok <=> rect_red.rect_green_ok; |
46 | property rect_pink_ok <=> rect_red.rect_pink_ok; |
47 | |
48 | property <bool> rect_blue_ok: |
49 | rect_blue.x == 200phx && |
50 | rect_blue.y == 0phx && |
51 | rect_blue.width == 100phx && |
52 | rect_blue.height == 50phx; |
53 | property <bool> rect_red_ok: |
54 | rect_red.x == 0phx && |
55 | rect_red.y == 0phx && |
56 | rect_red.width == 200phx && |
57 | rect_red.height == 50phx; |
58 | } |
59 | |
60 | TestCase := Rectangle { |
61 | width: 300phx; |
62 | height: 300phx; |
63 | |
64 | VerticalLayout { |
65 | spacing: 0phx; |
66 | padding: 0phx; |
67 | |
68 | rect_orange := Rectangle { |
69 | background: orange; |
70 | max_height: 10phx; |
71 | } |
72 | hl_redblue := RedBlue {} |
73 | rect_yellow := Rectangle { |
74 | background: yellow; |
75 | HorizontalLayout { |
76 | padding-top: 2phx; |
77 | padding-bottom: 4phx; |
78 | spacing: 2phx; |
79 | padding-left: 8phx; |
80 | padding-right: 10phx; |
81 | vl1 := VerticalLayout { |
82 | spacing: 5phx; |
83 | padding-top: 5phx; |
84 | padding-bottom: 0phx; |
85 | padding-left: 0phx; |
86 | padding-right: 0phx; |
87 | rect_black1 := Rectangle { |
88 | background: black; |
89 | } |
90 | rect_white1 := Rectangle { |
91 | background: white; |
92 | } |
93 | } |
94 | vl2 := VerticalLayout { |
95 | spacing: 5phx; |
96 | padding-bottom: 5phx; |
97 | padding-top: 0phx; |
98 | padding-left: 0phx; |
99 | padding-right: 0phx; |
100 | rect_black2 := Rectangle { |
101 | background: black; |
102 | } |
103 | rect_white2 := Rectangle { |
104 | background: white; |
105 | } |
106 | } |
107 | } |
108 | } |
109 | |
110 | // This item should be empty |
111 | VerticalLayout { |
112 | if (false) : Rectangle { background: #858; } |
113 | } |
114 | } |
115 | |
116 | property <bool> rect_orange_ok: |
117 | rect_orange.x == 0phx && |
118 | rect_orange.y == 0phx && |
119 | rect_orange.width == 300phx && |
120 | rect_orange.height == 10phx; |
121 | property <bool> rect_blue_ok: |
122 | hl_redblue.y == 10phx && hl-redblue.rect-blue-ok; |
123 | property <bool> rect_red_ok: |
124 | hl_redblue.y == 10phx && hl-redblue.rect-red-ok; |
125 | property <bool> rect_yellow_ok: |
126 | rect_yellow.x == 0phx && |
127 | rect_yellow.y == 60phx && |
128 | rect_yellow.width == 300phx && |
129 | rect_yellow.height == 240phx; |
130 | property <bool> rect_black1_ok: |
131 | rect_black1.x + vl1.x == 8phx && |
132 | rect_black1.y + vl1.y == 1phx * (2 + 5) && |
133 | rect_black1.width == 1phx * (300 - 18 - 2)/2 && |
134 | rect_black1.height == 1phx * (240 - 6 - 10)/2 ; |
135 | property <bool> rect_black2_ok: |
136 | rect_black2.x + vl2.x == 300phx - 1phx * (300 - 20) / 2 - 10phx && |
137 | rect_black2.y + vl2.y == 2phx && |
138 | rect_black2.width == 1phx * (300 - 18 - 2)/2 && |
139 | rect_black2.height == 1phx * (240 - 6 - 10)/2 ; |
140 | |
141 | property rect_green_ok <=> hl_redblue.rect_green_ok; |
142 | property rect_pink_ok <=> hl_redblue.rect_pink_ok; |
143 | |
144 | property <bool> test: rect_orange_ok && rect_blue_ok && rect_red_ok && rect_green_ok && rect_pink_ok && rect_yellow_ok && rect_black1_ok && rect_black2_ok; |
145 | } |
146 | |
147 | /* |
148 | |
149 | ```cpp |
150 | auto handle = TestCase::create(); |
151 | const TestCase &instance = *handle; |
152 | assert(instance.get_rect_blue_ok()); |
153 | assert(instance.get_rect_orange_ok()); |
154 | assert(instance.get_rect_red_ok()); |
155 | assert(instance.get_rect_green_ok()); |
156 | assert(instance.get_rect_yellow_ok()); |
157 | assert(instance.get_rect_black1_ok()); |
158 | assert(instance.get_rect_black2_ok()); |
159 | ``` |
160 | |
161 | |
162 | ```rust |
163 | let instance = TestCase::new().unwrap(); |
164 | assert!(instance.get_rect_blue_ok()); |
165 | assert!(instance.get_rect_orange_ok()); |
166 | assert!(instance.get_rect_red_ok()); |
167 | assert!(instance.get_rect_green_ok()); |
168 | assert!(instance.get_rect_yellow_ok()); |
169 | assert!(instance.get_rect_black1_ok()); |
170 | assert!(instance.get_rect_black2_ok()); |
171 | ``` |
172 | |
173 | */ |
174 | } |
175 | |
176 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
177 | use i_slint_backend_testing as slint_testing; |
178 | slint_testing::init(); |
179 | let instance = TestCase::new().unwrap(); |
180 | assert!(instance.get_rect_blue_ok()); |
181 | assert!(instance.get_rect_orange_ok()); |
182 | assert!(instance.get_rect_red_ok()); |
183 | assert!(instance.get_rect_green_ok()); |
184 | assert!(instance.get_rect_yellow_ok()); |
185 | assert!(instance.get_rect_black1_ok()); |
186 | assert!(instance.get_rect_black2_ok()); |
187 | Ok(()) |
188 | } |