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
5Test := 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
42auto handle = Test::create();
43const Test &t = *handle;
44assert_eq(t.get_r1(), t.get_r2());
45assert_eq(t.get_r1(), t.get_r3());
46assert_eq(t.get_r1(), t.get_r4());
47assert_eq(t.get_r1(), t.get_r5());
48assert_eq(t.get_b1(), t.get_b2());
49assert_eq(t.get_b1(), t.get_b3());
50assert_eq(t.get_b1(), t.get_b4());
51assert_eq(t.get_b1(), t.get_b5());
52assert(t.get_b1() != t.get_r5());
53assert_eq(t.get_y1(), t.get_y2());
54
55auto red = slint::Color::from_argb_float(1, 1, 0, 0);
56auto blue = slint::Color::from_rgb_float(0, 0, 1);
57auto g = slint::Color::from_rgb_uint8(0x99, 0x99, 0x99);
58assert_eq(t.get_r1(), red);
59assert_eq(t.get_b1(), blue);
60assert_eq(t.get_g1(), g);
61assert_eq(t.get_y1(), slint::Color::from_argb_encoded(0xffffff00));
62
63t.set_g1(blue);
64assert_eq(t.get_g1(), t.get_b1());
65
66assert_eq(t.get_c1().alpha(), 0x88);
67assert_eq(t.get_c1().red(), 0xff);
68assert_eq(t.get_c1().green(), 0x33);
69assert_eq(t.get_c1().blue(), 0x55);
70
71assert_eq(t.get_c2().alpha(), 0xff);
72assert_eq(t.get_c2().red(), 100);
73assert_eq(t.get_c2().green(), 23);
74assert_eq(t.get_c2().blue(), 42);
75
76assert_eq(t.get_c3().alpha(), uint8_t(255.*0.81));
77assert_eq(t.get_c3().red(), uint8_t(255.*0.39));
78assert_eq(t.get_c3().green(), uint8_t(255.*0.50));
79assert_eq(t.get_c3().blue(), uint8_t(255.*0.16));
80
81assert_eq(t.get_i1().alpha(), 0xff);
82assert_eq(t.get_i1().red(), 0);
83assert_eq(t.get_i1().green(), 255);
84assert_eq(t.get_i1().blue(), 0);
85
86assert(t.get_test_rgb());
87assert(t.get_test());
88```
89
90
91```rust
92let t = Test::new().unwrap();
93assert_eq!(t.get_r1(), t.get_r2());
94assert_eq!(t.get_r1(), t.get_r3());
95assert_eq!(t.get_r1(), t.get_r4());
96assert_eq!(t.get_r1(), t.get_r5());
97assert_eq!(t.get_b1(), t.get_b2());
98assert_eq!(t.get_b1(), t.get_b3());
99assert_eq!(t.get_b1(), t.get_b4());
100assert_eq!(t.get_b1(), t.get_b5());
101assert_ne!(t.get_b1(), t.get_r5());
102assert_eq!(t.get_y1(), t.get_y2());
103
104let red = slint::Color::from_argb_f32(1., 1., 0., 0.);
105let blue = slint::Color::from_rgb_f32(0., 0., 1.);
106let g = slint::Color::from_rgb_u8(0x99, 0x99, 0x99);
107assert_eq!(t.get_r1(), red);
108assert_eq!(t.get_b1(), blue);
109assert_eq!(t.get_g1(), g);
110assert_eq!(t.get_y1(), slint::Color::from_argb_encoded(0xffffff00));
111
112t.set_g1(blue);
113assert_eq!(t.get_g1(), t.get_b1());
114
115assert_eq!(t.get_c1().alpha(), 0x88);
116assert_eq!(t.get_c1().red(), 0xff);
117assert_eq!(t.get_c1().green(), 0x33);
118assert_eq!(t.get_c1().blue(), 0x55);
119
120assert_eq!(t.get_c2().alpha(), 0xff);
121assert_eq!(t.get_c2().red(), 100);
122assert_eq!(t.get_c2().green(), 23);
123assert_eq!(t.get_c2().blue(), 42);
124
125assert_eq!(t.get_c3().alpha(), (255.*0.81) as u8);
126assert_eq!(t.get_c3().red(), (255.*0.39) as u8);
127assert_eq!(t.get_c3().green(), (255.*0.50) as u8);
128assert_eq!(t.get_c3().blue(), (255.*0.16) as u8);
129
130assert_eq!(t.get_i1().alpha(), 0xff);
131assert_eq!(t.get_i1().red(), 0);
132assert_eq!(t.get_i1().green(), 255);
133assert_eq!(t.get_i1().blue(), 0);
134
135assert!(t.get_test_rgb());
136assert!(t.get_test());
137
138```
139
140```js
141var t = new slint.Test({});
142assert(t.r1.toString() == t.r2.toString());
143assert(t.r1.toString() == t.r3.toString());
144assert(t.r1.toString() == t.r4.toString());
145assert(t.r1.toString() == t.r5.toString());
146assert(t.b1.toString() == t.b2.toString());
147assert(t.b1.toString() == t.b3.toString());
148assert(t.b1.toString() == t.b4.toString());
149assert(t.b1.toString() == t.b5.toString());
150assert(t.b1.toString() != t.r5.toString());
151
152let red = "#ff0000ff";
153let blue = "#0000ffff";
154let g = "#999999ff";
155assert.equal(t.r1.toString(), red);
156assert.equal(t.b1.toString(), blue);
157assert.equal(t.g1.toString(), g);
158assert.equal(t.y1.toString(), "#ffff00ff");
159
160t.g1 = "blue";
161assert.equal(t.g1.toString(), t.b1.toString());
162t.g1 = "#f00";
163assert.equal(t.g1.toString(), t.r1.toString());
164
165assert.equal(t.c1.toString(), "#ff335588");
166assert.equal(t.c2.toString(), "#64172aff");
167assert.equal(t.c3.toString(), "#637f28ce");
168assert.equal(t.i1.toString(), "#00ff00ff");
169
170assert(t.test_rgb);
171assert(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}