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
5
6SubSubComp := Rectangle {
7 property <bool> active;
8 property <int> value: 10;
9 states [
10 active when active : {
11 value: 150;
12 }
13 ]
14}
15
16SubComp := SubSubComp {
17 states [
18 foobar when active : {
19 r.background: red;
20 }
21 ]
22
23 r := Rectangle {}
24}
25
26TestCase := Rectangle {
27 property<int> top_level: 4;
28 property<int> active_index: 0;
29 property<int> some_prop: 5;
30 text1 := Text {
31 text: "hello";
32 property<int> foo: 85 + top_level;
33 }
34
35 states [
36 xxx when active_index == 1 : {
37 text1.text: "world";
38 text1.foo: 3 + 2 * top_level;
39 some_prop: 8;
40 }
41 yyy when active_index == 2 : {
42 text1.foo: 9;
43 }
44 ]
45
46 property<int> text1_foo: text1.foo;
47
48 for xx in [1, 2] : Rectangle {
49 states [
50 foo when xx == 1 : {
51 height: top_level * 1phx;
52 }
53 ]
54
55 }
56
57 sc := SubComp {
58 active: active_index == 1;
59 }
60 property <int> subcomp: sc.value;
61
62}
63
64
65/*
66```cpp
67auto handle = TestCase::create();
68const TestCase &instance = *handle;
69assert_eq(instance.get_text1_foo(), 85 + 4);
70assert_eq(instance.get_some_prop(), 5);
71assert_eq(instance.get_subcomp(), 10);
72instance.set_active_index(1);
73assert_eq(instance.get_text1_foo(), 3 + 2 * 4);
74assert_eq(instance.get_some_prop(), 8);
75instance.set_top_level(1);
76assert_eq(instance.get_text1_foo(), 3 + 2);
77assert_eq(instance.get_subcomp(), 150);
78```
79
80
81```rust
82let instance = TestCase::new().unwrap();
83assert_eq!(instance.get_text1_foo(), 85 + 4);
84assert_eq!(instance.get_some_prop(), 5);
85assert_eq!(instance.get_subcomp(), 10);
86instance.set_active_index(1);
87assert_eq!(instance.get_text1_foo(), 3 + 2 * 4);
88assert_eq!(instance.get_some_prop(), 8);
89instance.set_top_level(1);
90assert_eq!(instance.get_text1_foo(), 3 + 2);
91assert_eq!(instance.get_subcomp(), 150);
92
93```
94
95```js
96var instance = new slint.TestCase({});
97assert.equal(instance.text1_foo, 85 + 4);
98assert.equal(instance.some_prop, 5);
99instance.active_index = 1;
100assert.equal(instance.text1_foo, 3 + 2 * 4);
101assert.equal(instance.some_prop, 8);
102instance.top_level = 1;
103assert.equal(instance.text1_foo, 3 + 2);
104```
105*/
106