1// Copyright © SixtyFPS GmbH <info@slint.dev>
2// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
3
4export global G {
5 in property <string> global-property: "Hello";
6}
7
8struct S { val: string }
9
10component Shared {
11 in property <string> n;
12 out property <S> out: { val: G.global-property + " " + n };
13 for xx in 2 : Rectangle {}
14 out property <bool> test: false;
15}
16
17// This component is both exported and Used
18export component Used inherits Window {
19 in-out property <int> name;
20 for xx in 4 : Rectangle { }
21 out property <bool> test: true;
22}
23
24export component FirstTest inherits Window {
25
26 out property <string> global-prop: G.global-property;
27 out property <string> o: shared.out.val;
28 shared := Shared {
29 n: "Oli";
30 }
31
32 Used {}
33
34 out property <bool> test: true;
35}
36
37export component Z inherits Window {
38 out property <bool> test: true;
39}
40
41export component NotAWindow {
42 out property <bool> test: false;
43}
44
45
46
47export component SecondTest inherits Window {
48 out property <string> global-prop: G.global-property;
49 out property <string> out: shared.out.val;
50
51 shared := Shared {
52 n: "Sim";
53 }
54
55 out property <bool> test: out == "Hello Sim";
56}
57
58
59/*
60```rust
61let instance1 = FirstTest::new().unwrap();
62
63instance1.global::<G<'_>>().set_global_property("Hallo".into());
64
65let instance2 = SecondTest::new().unwrap();
66
67let instance3 = SecondTest::new().unwrap();
68
69instance3.global::<G<'_>>().set_global_property("Bonjour".into());
70
71assert_eq!(instance1.get_o(), "Hallo Oli");
72assert_eq!(instance2.get_out(), "Hello Sim");
73assert_eq!(instance3.get_out(), "Bonjour Sim");
74
75#[allow(unused)]
76pub struct Shared;
77#[allow(unused)]
78pub struct NotAWindow;
79
80```
81
82```cpp
83auto handle1 = FirstTest::create();
84const FirstTest &instance1 = *handle1;
85instance1.global<G>().set_global_property("Hallo");
86
87auto handle2 = SecondTest::create();
88const SecondTest &instance2 = *handle2;
89
90auto handle3 = SecondTest::create();
91const SecondTest &instance3 = *handle3;
92
93instance3.global<G>().set_global_property("Bonjour");
94
95assert_eq(instance1.get_o(), "Hallo Oli");
96assert_eq(instance2.get_out(), "Hello Sim");
97assert_eq(instance3.get_out(), "Bonjour Sim");
98
99struct Shared {};
100struct NotAWindow {};
101```
102
103```js
104let instance1 = new slint.FirstTest();
105instance1.G.global_property = "Hallo";
106
107let instance2 = new slint.SecondTest();
108let instance3 = new slint.SecondTest();
109instance3.G.global_property = "Bonjour";
110
111assert.equal(instance1.o, "Hallo Oli");
112assert.equal(instance2.out, "Hello Sim");
113assert.equal(instance3.out, "Bonjour Sim");
114
115assert.equal(typeof slint.Shared, "undefined");
116assert.equal(typeof slint.NotAWindow, "undefined");
117assert.equal(typeof slint.G, "undefined");
118```
119
120
121
122
123*/
124
125