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 | |
6 | SubSubComp := Rectangle { |
7 | property <bool> active; |
8 | property <int> value: 10; |
9 | states [ |
10 | active when active : { |
11 | value: 150; |
12 | } |
13 | ] |
14 | } |
15 | |
16 | SubComp := SubSubComp { |
17 | states [ |
18 | foobar when active : { |
19 | r.background: red; |
20 | } |
21 | ] |
22 | |
23 | r := Rectangle {} |
24 | } |
25 | |
26 | TestCase := 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 |
67 | auto handle = TestCase::create(); |
68 | const TestCase &instance = *handle; |
69 | assert_eq(instance.get_text1_foo(), 85 + 4); |
70 | assert_eq(instance.get_some_prop(), 5); |
71 | assert_eq(instance.get_subcomp(), 10); |
72 | instance.set_active_index(1); |
73 | assert_eq(instance.get_text1_foo(), 3 + 2 * 4); |
74 | assert_eq(instance.get_some_prop(), 8); |
75 | instance.set_top_level(1); |
76 | assert_eq(instance.get_text1_foo(), 3 + 2); |
77 | assert_eq(instance.get_subcomp(), 150); |
78 | ``` |
79 | |
80 | |
81 | ```rust |
82 | let instance = TestCase::new().unwrap(); |
83 | assert_eq!(instance.get_text1_foo(), 85 + 4); |
84 | assert_eq!(instance.get_some_prop(), 5); |
85 | assert_eq!(instance.get_subcomp(), 10); |
86 | instance.set_active_index(1); |
87 | assert_eq!(instance.get_text1_foo(), 3 + 2 * 4); |
88 | assert_eq!(instance.get_some_prop(), 8); |
89 | instance.set_top_level(1); |
90 | assert_eq!(instance.get_text1_foo(), 3 + 2); |
91 | assert_eq!(instance.get_subcomp(), 150); |
92 | |
93 | ``` |
94 | |
95 | ```js |
96 | var instance = new slint.TestCase({}); |
97 | assert.equal(instance.text1_foo, 85 + 4); |
98 | assert.equal(instance.some_prop, 5); |
99 | instance.active_index = 1; |
100 | assert.equal(instance.text1_foo, 3 + 2 * 4); |
101 | assert.equal(instance.some_prop, 8); |
102 | instance.top_level = 1; |
103 | assert.equal(instance.text1_foo, 3 + 2); |
104 | ``` |
105 | */ |
106 | |