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 | MyWid := Rectangle { |
6 | min-width: 20phx; |
7 | min-height: 20phx; |
8 | horizontal-stretch:0; |
9 | vertical-stretch:0; |
10 | } |
11 | |
12 | |
13 | TestCase := 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 |
72 | auto handle = TestCase::create(); |
73 | const TestCase &instance = *handle; |
74 | assert(instance.get_v1()); |
75 | assert(instance.get_v2()); |
76 | assert(instance.get_v3()); |
77 | assert(instance.get_v4()); |
78 | assert(instance.get_s1()); |
79 | assert(instance.get_b1()); |
80 | assert(instance.get_c1()); |
81 | ``` |
82 | |
83 | |
84 | ```rust |
85 | let instance = TestCase::new().unwrap(); |
86 | assert!(instance.get_v1()); |
87 | assert!(instance.get_v2()); |
88 | assert!(instance.get_v3()); |
89 | assert!(instance.get_v4()); |
90 | assert!(instance.get_s1()); |
91 | assert!(instance.get_b1()); |
92 | assert!(instance.get_c1()); |
93 | ``` |
94 | |
95 | ```js |
96 | var instance = new slint.TestCase(); |
97 | slintlib.private_api.send_mouse_click(instance, 5., 5.); |
98 | assert(instance.v1); |
99 | assert(instance.v2); |
100 | assert(instance.v3); |
101 | assert(instance.v4); |
102 | assert(instance.s1); |
103 | assert(instance.b1); |
104 | assert(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 | } |