1 | #![allow (deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/types"# ] |
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 | Test := Rectangle { |
6 | property<color> b1: blue; |
7 | property<color> b2: #00f; |
8 | property<color> b3: #0000ff; |
9 | property<color> b4: #00ff; |
10 | property<color> b5: #0000ffff; |
11 | property<color> r1: red; |
12 | property<color> r2: #f00; |
13 | property<color> r3: #ff0000; |
14 | property<color> r4: #f00f; |
15 | property<color> r5: #ff0000ff; |
16 | |
17 | property<color> y1: yellow; |
18 | property<color> y2: #ff0; |
19 | |
20 | property<color> g1: #999; |
21 | |
22 | property<color> c1: #ff335588; |
23 | property<color> c2: rgb(100, 23, 42); |
24 | property<color> c3: rgba(39%, 50%, 16%, 81%); |
25 | |
26 | property<color> i1: rgb(0, 666, -85); |
27 | |
28 | // allow to use `mix` on colors |
29 | property<color> p1: true ? b1.mix(r1, 30%) : y1.mix(c1, 70%); |
30 | // allow to use `with_alpha` on colors |
31 | property<brush> invisible: b1.with-alpha(0%); |
32 | |
33 | out property <bool> test_rgb: Colors.blue.blue == 255 && Colors.blue.red == 0 && Colors.blue.green == 0 && Colors.blue.alpha == 255 |
34 | && Colors.rgb(45, 12, 78).red == 45 && Colors.rgb(45, 12, 78).green == 12 && Colors.rgba(45, 12, 78, 12/255).alpha == 12 && Colors.rgba(145, 112, 178, 85%).alpha == floor(85% * 255) |
35 | && #abc.green == (11 * 16 + 11) && #abcd.alpha == (13 * 16 + 13) && #abcdef.red == (10 * 16 + 11); |
36 | |
37 | property<bool> test: b1 == b2 && b2 == b5 && b3 == Colors.blue && Colors.red == r4 && y1 == Colors.rgba(255, 100%, 0, 100%) && test_rgb; |
38 | } |
39 | |
40 | /* |
41 | ```cpp |
42 | auto handle = Test::create(); |
43 | const Test &t = *handle; |
44 | assert_eq(t.get_r1(), t.get_r2()); |
45 | assert_eq(t.get_r1(), t.get_r3()); |
46 | assert_eq(t.get_r1(), t.get_r4()); |
47 | assert_eq(t.get_r1(), t.get_r5()); |
48 | assert_eq(t.get_b1(), t.get_b2()); |
49 | assert_eq(t.get_b1(), t.get_b3()); |
50 | assert_eq(t.get_b1(), t.get_b4()); |
51 | assert_eq(t.get_b1(), t.get_b5()); |
52 | assert(t.get_b1() != t.get_r5()); |
53 | assert_eq(t.get_y1(), t.get_y2()); |
54 | |
55 | auto red = slint::Color::from_argb_float(1, 1, 0, 0); |
56 | auto blue = slint::Color::from_rgb_float(0, 0, 1); |
57 | auto g = slint::Color::from_rgb_uint8(0x99, 0x99, 0x99); |
58 | assert_eq(t.get_r1(), red); |
59 | assert_eq(t.get_b1(), blue); |
60 | assert_eq(t.get_g1(), g); |
61 | assert_eq(t.get_y1(), slint::Color::from_argb_encoded(0xffffff00)); |
62 | |
63 | t.set_g1(blue); |
64 | assert_eq(t.get_g1(), t.get_b1()); |
65 | |
66 | assert_eq(t.get_c1().alpha(), 0x88); |
67 | assert_eq(t.get_c1().red(), 0xff); |
68 | assert_eq(t.get_c1().green(), 0x33); |
69 | assert_eq(t.get_c1().blue(), 0x55); |
70 | |
71 | assert_eq(t.get_c2().alpha(), 0xff); |
72 | assert_eq(t.get_c2().red(), 100); |
73 | assert_eq(t.get_c2().green(), 23); |
74 | assert_eq(t.get_c2().blue(), 42); |
75 | |
76 | assert_eq(t.get_c3().alpha(), uint8_t(255.*0.81)); |
77 | assert_eq(t.get_c3().red(), uint8_t(255.*0.39)); |
78 | assert_eq(t.get_c3().green(), uint8_t(255.*0.50)); |
79 | assert_eq(t.get_c3().blue(), uint8_t(255.*0.16)); |
80 | |
81 | assert_eq(t.get_i1().alpha(), 0xff); |
82 | assert_eq(t.get_i1().red(), 0); |
83 | assert_eq(t.get_i1().green(), 255); |
84 | assert_eq(t.get_i1().blue(), 0); |
85 | |
86 | assert(t.get_test_rgb()); |
87 | assert(t.get_test()); |
88 | ``` |
89 | |
90 | |
91 | ```rust |
92 | let t = Test::new().unwrap(); |
93 | assert_eq!(t.get_r1(), t.get_r2()); |
94 | assert_eq!(t.get_r1(), t.get_r3()); |
95 | assert_eq!(t.get_r1(), t.get_r4()); |
96 | assert_eq!(t.get_r1(), t.get_r5()); |
97 | assert_eq!(t.get_b1(), t.get_b2()); |
98 | assert_eq!(t.get_b1(), t.get_b3()); |
99 | assert_eq!(t.get_b1(), t.get_b4()); |
100 | assert_eq!(t.get_b1(), t.get_b5()); |
101 | assert_ne!(t.get_b1(), t.get_r5()); |
102 | assert_eq!(t.get_y1(), t.get_y2()); |
103 | |
104 | let red = slint::Color::from_argb_f32(1., 1., 0., 0.); |
105 | let blue = slint::Color::from_rgb_f32(0., 0., 1.); |
106 | let g = slint::Color::from_rgb_u8(0x99, 0x99, 0x99); |
107 | assert_eq!(t.get_r1(), red); |
108 | assert_eq!(t.get_b1(), blue); |
109 | assert_eq!(t.get_g1(), g); |
110 | assert_eq!(t.get_y1(), slint::Color::from_argb_encoded(0xffffff00)); |
111 | |
112 | t.set_g1(blue); |
113 | assert_eq!(t.get_g1(), t.get_b1()); |
114 | |
115 | assert_eq!(t.get_c1().alpha(), 0x88); |
116 | assert_eq!(t.get_c1().red(), 0xff); |
117 | assert_eq!(t.get_c1().green(), 0x33); |
118 | assert_eq!(t.get_c1().blue(), 0x55); |
119 | |
120 | assert_eq!(t.get_c2().alpha(), 0xff); |
121 | assert_eq!(t.get_c2().red(), 100); |
122 | assert_eq!(t.get_c2().green(), 23); |
123 | assert_eq!(t.get_c2().blue(), 42); |
124 | |
125 | assert_eq!(t.get_c3().alpha(), (255.*0.81) as u8); |
126 | assert_eq!(t.get_c3().red(), (255.*0.39) as u8); |
127 | assert_eq!(t.get_c3().green(), (255.*0.50) as u8); |
128 | assert_eq!(t.get_c3().blue(), (255.*0.16) as u8); |
129 | |
130 | assert_eq!(t.get_i1().alpha(), 0xff); |
131 | assert_eq!(t.get_i1().red(), 0); |
132 | assert_eq!(t.get_i1().green(), 255); |
133 | assert_eq!(t.get_i1().blue(), 0); |
134 | |
135 | assert!(t.get_test_rgb()); |
136 | assert!(t.get_test()); |
137 | |
138 | ``` |
139 | |
140 | ```js |
141 | var t = new slint.Test({}); |
142 | assert(t.r1.toString() == t.r2.toString()); |
143 | assert(t.r1.toString() == t.r3.toString()); |
144 | assert(t.r1.toString() == t.r4.toString()); |
145 | assert(t.r1.toString() == t.r5.toString()); |
146 | assert(t.b1.toString() == t.b2.toString()); |
147 | assert(t.b1.toString() == t.b3.toString()); |
148 | assert(t.b1.toString() == t.b4.toString()); |
149 | assert(t.b1.toString() == t.b5.toString()); |
150 | assert(t.b1.toString() != t.r5.toString()); |
151 | |
152 | let red = "#ff0000ff"; |
153 | let blue = "#0000ffff"; |
154 | let g = "#999999ff"; |
155 | assert.equal(t.r1.toString(), red); |
156 | assert.equal(t.b1.toString(), blue); |
157 | assert.equal(t.g1.toString(), g); |
158 | assert.equal(t.y1.toString(), "#ffff00ff"); |
159 | |
160 | t.g1 = "blue"; |
161 | assert.equal(t.g1.toString(), t.b1.toString()); |
162 | t.g1 = "#f00"; |
163 | assert.equal(t.g1.toString(), t.r1.toString()); |
164 | |
165 | assert.equal(t.c1.toString(), "#ff335588"); |
166 | assert.equal(t.c2.toString(), "#64172aff"); |
167 | assert.equal(t.c3.toString(), "#637f28ce"); |
168 | assert.equal(t.i1.toString(), "#00ff00ff"); |
169 | |
170 | assert(t.test_rgb); |
171 | assert(t.test); |
172 | |
173 | ``` |
174 | */ |
175 | } |
176 | |
177 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
178 | use i_slint_backend_testing as slint_testing; |
179 | slint_testing::init(); |
180 | let t = Test::new().unwrap(); |
181 | assert_eq!(t.get_r1(), t.get_r2()); |
182 | assert_eq!(t.get_r1(), t.get_r3()); |
183 | assert_eq!(t.get_r1(), t.get_r4()); |
184 | assert_eq!(t.get_r1(), t.get_r5()); |
185 | assert_eq!(t.get_b1(), t.get_b2()); |
186 | assert_eq!(t.get_b1(), t.get_b3()); |
187 | assert_eq!(t.get_b1(), t.get_b4()); |
188 | assert_eq!(t.get_b1(), t.get_b5()); |
189 | assert_ne!(t.get_b1(), t.get_r5()); |
190 | assert_eq!(t.get_y1(), t.get_y2()); |
191 | |
192 | let red = slint::Color::from_argb_f32(1., 1., 0., 0.); |
193 | let blue = slint::Color::from_rgb_f32(0., 0., 1.); |
194 | let g = slint::Color::from_rgb_u8(0x99, 0x99, 0x99); |
195 | assert_eq!(t.get_r1(), red); |
196 | assert_eq!(t.get_b1(), blue); |
197 | assert_eq!(t.get_g1(), g); |
198 | assert_eq!(t.get_y1(), slint::Color::from_argb_encoded(0xffffff00)); |
199 | |
200 | t.set_g1(blue); |
201 | assert_eq!(t.get_g1(), t.get_b1()); |
202 | |
203 | assert_eq!(t.get_c1().alpha(), 0x88); |
204 | assert_eq!(t.get_c1().red(), 0xff); |
205 | assert_eq!(t.get_c1().green(), 0x33); |
206 | assert_eq!(t.get_c1().blue(), 0x55); |
207 | |
208 | assert_eq!(t.get_c2().alpha(), 0xff); |
209 | assert_eq!(t.get_c2().red(), 100); |
210 | assert_eq!(t.get_c2().green(), 23); |
211 | assert_eq!(t.get_c2().blue(), 42); |
212 | |
213 | assert_eq!(t.get_c3().alpha(), (255.*0.81) as u8); |
214 | assert_eq!(t.get_c3().red(), (255.*0.39) as u8); |
215 | assert_eq!(t.get_c3().green(), (255.*0.50) as u8); |
216 | assert_eq!(t.get_c3().blue(), (255.*0.16) as u8); |
217 | |
218 | assert_eq!(t.get_i1().alpha(), 0xff); |
219 | assert_eq!(t.get_i1().red(), 0); |
220 | assert_eq!(t.get_i1().green(), 255); |
221 | assert_eq!(t.get_i1().blue(), 0); |
222 | |
223 | assert!(t.get_test_rgb()); |
224 | assert!(t.get_test()); |
225 | |
226 | Ok(()) |
227 | } |