1 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
2 | // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial |
3 | |
4 | Test := Rectangle { |
5 | // allow declaring brush properties and assigning colors |
6 | property<brush> color_brush: blue; |
7 | // allow to use brighter and darker on a brush |
8 | property<brush> lighter: true ? color_brush.brighter(50%) : color_brush.darker(50%); |
9 | // allow to use `transparentize` |
10 | property<brush> seethru: color_brush.transparentize(30%); |
11 | |
12 | VerticalLayout { |
13 | r1 := Rectangle { |
14 | background: @linear-gradient(1.2rad, red, blue); |
15 | } |
16 | r2 := Rectangle { |
17 | background: r1.background.darker(50%); |
18 | } |
19 | } |
20 | property <color> r2_col: r2.background; |
21 | property <brush> conditional: false ? Colors.white : true ? r2.background : Colors.green; |
22 | |
23 | test_circle := Rectangle { |
24 | background: @radial_gradient(circle, #abc, #123 10%, #fed); |
25 | property <color> colo: background; |
26 | property <bool> test: colo == #abc |
27 | && background.brighter(10%) == @radial_gradient(circle, (#abc).brighter(10%), (#123).brighter(10%) 10%, (#fed).brighter(10%)) |
28 | && background != colo; |
29 | } |
30 | |
31 | out property <bool> test_rgb: rgb(color_brush.red, color_brush.green, color_brush.blue) == color_brush; |
32 | |
33 | out property<bool> test: lighter == Colors.blue.brighter(50%) && r2_col == Colors.red.darker(50%) && conditional == r2.background && conditional != r2_col |
34 | && test_circle.test && seethru == color_brush.with_alpha(70%) && (#abc2).transparentize(-100%) == #abc4 && test_rgb; |
35 | } |
36 | |
37 | /* |
38 | ```cpp |
39 | auto handle = Test::create(); |
40 | const Test &t = *handle; |
41 | assert_eq(t.get_color_brush().color(), slint::Color::from_rgb_uint8(0, 0, 0xff)); |
42 | assert(t.get_test()); |
43 | |
44 | auto green = slint::Color::from_rgb_uint8(0, 0xff, 0); |
45 | t.set_color_brush(green); |
46 | assert_eq(t.get_color_brush().color(), green); |
47 | |
48 | ``` |
49 | |
50 | ```rust |
51 | let t = Test::new().unwrap(); |
52 | assert_eq!(t.get_color_brush().color(), slint::Color::from_rgb_u8(0, 0, 0xff)); |
53 | assert!(t.get_test()); |
54 | |
55 | let green = slint::Color::from_rgb_u8(0, 0xff, 0); |
56 | t.set_color_brush(green.into()); |
57 | assert_eq!(t.get_color_brush().color(), green); |
58 | |
59 | ``` |
60 | |
61 | ```js |
62 | var t = new slint.Test({}); |
63 | assert.equal(t.color_brush.toString(), "#0000ffff"); |
64 | assert(t.test); |
65 | |
66 | let green = "#00ff00ff"; |
67 | t.color_brush = "#00ff00"; // css-color-parser2 can't parse #rrggbbaa yet |
68 | assert.equal(t.color_brush.toString(), green); |
69 | |
70 | ``` |
71 | */ |
72 | |