| 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 | |
| 4 | export global G { |
| 5 | in property <string> global-property: "Hello" ; |
| 6 | } |
| 7 | |
| 8 | struct S { val: string } |
| 9 | |
| 10 | component 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 |
| 18 | export component Used inherits Window { |
| 19 | in-out property <int> name; |
| 20 | for xx in 4 : Rectangle { } |
| 21 | out property <bool> test: true; |
| 22 | } |
| 23 | |
| 24 | export 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 | |
| 37 | export component Z inherits Window { |
| 38 | out property <bool> test: true; |
| 39 | } |
| 40 | |
| 41 | export component NotAWindow { |
| 42 | out property <bool> test: false; |
| 43 | } |
| 44 | |
| 45 | |
| 46 | |
| 47 | export 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 |
| 61 | let instance1 = FirstTest::new().unwrap(); |
| 62 | |
| 63 | instance1.global::<G<'_>>().set_global_property("Hallo".into()); |
| 64 | |
| 65 | let instance2 = SecondTest::new().unwrap(); |
| 66 | |
| 67 | let instance3 = SecondTest::new().unwrap(); |
| 68 | |
| 69 | instance3.global::<G<'_>>().set_global_property("Bonjour".into()); |
| 70 | |
| 71 | assert_eq!(instance1.get_o(), "Hallo Oli"); |
| 72 | assert_eq!(instance2.get_out(), "Hello Sim"); |
| 73 | assert_eq!(instance3.get_out(), "Bonjour Sim"); |
| 74 | |
| 75 | #[allow(unused)] |
| 76 | pub struct Shared; |
| 77 | #[allow(unused)] |
| 78 | pub struct NotAWindow; |
| 79 | |
| 80 | ``` |
| 81 | |
| 82 | ```cpp |
| 83 | auto handle1 = FirstTest::create(); |
| 84 | const FirstTest &instance1 = *handle1; |
| 85 | instance1.global<G>().set_global_property("Hallo"); |
| 86 | |
| 87 | auto handle2 = SecondTest::create(); |
| 88 | const SecondTest &instance2 = *handle2; |
| 89 | |
| 90 | auto handle3 = SecondTest::create(); |
| 91 | const SecondTest &instance3 = *handle3; |
| 92 | |
| 93 | instance3.global<G>().set_global_property("Bonjour"); |
| 94 | |
| 95 | assert_eq(instance1.get_o(), "Hallo Oli"); |
| 96 | assert_eq(instance2.get_out(), "Hello Sim"); |
| 97 | assert_eq(instance3.get_out(), "Bonjour Sim"); |
| 98 | |
| 99 | struct Shared {}; |
| 100 | struct NotAWindow {}; |
| 101 | ``` |
| 102 | |
| 103 | ```js |
| 104 | let instance1 = new slint.FirstTest(); |
| 105 | instance1.G.global_property = "Hallo"; |
| 106 | |
| 107 | let instance2 = new slint.SecondTest(); |
| 108 | let instance3 = new slint.SecondTest(); |
| 109 | instance3.G.global_property = "Bonjour"; |
| 110 | |
| 111 | assert.equal(instance1.o, "Hallo Oli"); |
| 112 | assert.equal(instance2.out, "Hello Sim"); |
| 113 | assert.equal(instance3.out, "Bonjour Sim"); |
| 114 | |
| 115 | assert.equal(typeof slint.Shared, "undefined"); |
| 116 | assert.equal(typeof slint.NotAWindow, "undefined"); |
| 117 | assert.equal(typeof slint.G, "undefined"); |
| 118 | ``` |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | */ |
| 124 | |
| 125 | |