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
4Test := 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
39auto handle = Test::create();
40const Test &t = *handle;
41assert_eq(t.get_color_brush().color(), slint::Color::from_rgb_uint8(0, 0, 0xff));
42assert(t.get_test());
43
44auto green = slint::Color::from_rgb_uint8(0, 0xff, 0);
45t.set_color_brush(green);
46assert_eq(t.get_color_brush().color(), green);
47
48```
49
50```rust
51let t = Test::new().unwrap();
52assert_eq!(t.get_color_brush().color(), slint::Color::from_rgb_u8(0, 0, 0xff));
53assert!(t.get_test());
54
55let green = slint::Color::from_rgb_u8(0, 0xff, 0);
56t.set_color_brush(green.into());
57assert_eq!(t.get_color_brush().color(), green);
58
59```
60
61```js
62var t = new slint.Test({});
63assert.equal(t.color_brush.toString(), "#0000ffff");
64assert(t.test);
65
66let green = "#00ff00ff";
67t.color_brush = "#00ff00"; // css-color-parser2 can't parse #rrggbbaa yet
68assert.equal(t.color_brush.toString(), green);
69
70```
71*/
72