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 // allow declaring brush properties and assigning colors
7 property<brush> color_brush: blue;
8 // allow to use brighter and darker on a brush
9 property<brush> lighter: true ? color_brush.brighter(50%) : color_brush.darker(50%);
10 // allow to use `transparentize`
11 property<brush> seethru: color_brush.transparentize(30%);
12
13 VerticalLayout {
14 r1 := Rectangle {
15 background: @linear-gradient(1.2rad, red, blue);
16 }
17 r2 := Rectangle {
18 background: r1.background.darker(50%);
19 }
20 }
21 property <color> r2_col: r2.background;
22 property <brush> conditional: false ? Colors.white : true ? r2.background : Colors.green;
23
24 test_circle := Rectangle {
25 background: @radial_gradient(circle, #abc, #123 10%, #fed);
26 property <color> colo: background;
27 property <bool> test: colo == #abc
28 && background.brighter(10%) == @radial_gradient(circle, (#abc).brighter(10%), (#123).brighter(10%) 10%, (#fed).brighter(10%))
29 && background != colo;
30 }
31
32 out property <bool> test_rgb: rgb(color_brush.red, color_brush.green, color_brush.blue) == color_brush;
33
34 out property<bool> test: lighter == Colors.blue.brighter(50%) && r2_col == Colors.red.darker(50%) && conditional == r2.background && conditional != r2_col
35 && test_circle.test && seethru == color_brush.with_alpha(70%) && (#abc2).transparentize(-100%) == #abc4 && test_rgb;
36}
37
38/*
39```cpp
40auto handle = Test::create();
41const Test &t = *handle;
42assert_eq(t.get_color_brush().color(), slint::Color::from_rgb_uint8(0, 0, 0xff));
43assert(t.get_test());
44
45auto green = slint::Color::from_rgb_uint8(0, 0xff, 0);
46t.set_color_brush(green);
47assert_eq(t.get_color_brush().color(), green);
48
49```
50
51```rust
52let t = Test::new().unwrap();
53assert_eq!(t.get_color_brush().color(), slint::Color::from_rgb_u8(0, 0, 0xff));
54assert!(t.get_test());
55
56let green = slint::Color::from_rgb_u8(0, 0xff, 0);
57t.set_color_brush(green.into());
58assert_eq!(t.get_color_brush().color(), green);
59
60```
61
62```js
63var t = new slint.Test({});
64assert.equal(t.color_brush.toString(), "#0000ffff");
65assert(t.test);
66
67let green = "#00ff00ff";
68t.color_brush = "#00ff00"; // css-color-parser2 can't parse #rrggbbaa yet
69assert.equal(t.color_brush.toString(), green);
70
71```
72*/
73}
74
75#[test] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
76 use i_slint_backend_testing as slint_testing;
77 slint_testing::init();
78 let t = Test::new().unwrap();
79 assert_eq!(t.get_color_brush().color(), slint::Color::from_rgb_u8(0, 0, 0xff));
80 assert!(t.get_test());
81
82 let green: Color = slint::Color::from_rgb_u8(red:0, green:0xff, blue:0);
83 t.set_color_brush(green.into());
84 assert_eq!(t.get_color_brush().color(), green);
85
86 Ok(())
87}