| 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 | OtherComp := Rectangle { |
| 5 | property <string> t <=> text.text; |
| 6 | property <string> get_text <=> text.text; |
| 7 | text := Text { |
| 8 | text: "to be overridden" ; |
| 9 | } |
| 10 | property <int> some_value: 42; |
| 11 | property <int> some_value_alias <=> some_value; |
| 12 | } |
| 13 | |
| 14 | TestCase := Rectangle { |
| 15 | |
| 16 | property <string> text1: "Hello" ; |
| 17 | property <string> text2: "Blah" ; |
| 18 | property <string> ti1_text: ti1.text; |
| 19 | property <string> ti2_text: ti2.text; |
| 20 | property <string> text_item_text: text_item.text; |
| 21 | property <string> othercomp_t: "real value" ; |
| 22 | property <string> othercomp_get_text: other_comp.get_text; |
| 23 | property <int> othercomp_some_value; |
| 24 | property <int> othercomp_some_value_alias <=> other_comp.some_value_alias; |
| 25 | property <int> othercomp_some_value_alias2; |
| 26 | |
| 27 | ti1 := TextInput { |
| 28 | text <=> text1; |
| 29 | } |
| 30 | |
| 31 | ti2 := TextInput { |
| 32 | text <=> text_item.text; |
| 33 | } |
| 34 | |
| 35 | text_item := Text { |
| 36 | text: text2; |
| 37 | } |
| 38 | |
| 39 | Text { |
| 40 | text <=> text1; |
| 41 | } |
| 42 | |
| 43 | other_comp := OtherComp { |
| 44 | t <=> root.othercomp_t; |
| 45 | some_value <=> othercomp_some_value; |
| 46 | some_value_alias <=> othercomp_some_value_alias2; |
| 47 | } |
| 48 | |
| 49 | callback set_ti1(string); |
| 50 | set_ti1(a) => { ti1.text = a; } |
| 51 | callback set_ti2(string); |
| 52 | set_ti2(a) => { ti2.text = a; } |
| 53 | } |
| 54 | |
| 55 | |
| 56 | /* |
| 57 | |
| 58 | ```rust |
| 59 | let instance = TestCase::new().unwrap(); |
| 60 | assert_eq!(instance.get_text1(), slint::SharedString::from("Hello")); |
| 61 | assert_eq!(instance.get_text2(), slint::SharedString::from("Blah")); |
| 62 | assert_eq!(instance.get_ti1_text(), slint::SharedString::from("Hello")); |
| 63 | assert_eq!(instance.get_ti2_text(), slint::SharedString::from("Blah")); |
| 64 | assert_eq!(instance.get_text_item_text(), slint::SharedString::from("Blah")); |
| 65 | assert_eq!(instance.get_othercomp_t(), instance.get_othercomp_get_text()); |
| 66 | assert_eq!(instance.get_othercomp_t(), slint::SharedString::from("real value")); |
| 67 | assert_eq!(instance.get_othercomp_get_text(), slint::SharedString::from("real value")); |
| 68 | |
| 69 | instance.set_text1(slint::SharedString::from("Text1New")); |
| 70 | instance.set_text2(slint::SharedString::from("Text2New")); |
| 71 | assert_eq!(instance.get_text1(), slint::SharedString::from("Text1New")); |
| 72 | assert_eq!(instance.get_text2(), slint::SharedString::from("Text2New")); |
| 73 | assert_eq!(instance.get_ti1_text(), slint::SharedString::from("Text1New")); |
| 74 | assert_eq!(instance.get_ti2_text(), slint::SharedString::from("Text2New")); |
| 75 | assert_eq!(instance.get_text_item_text(), slint::SharedString::from("Text2New")); |
| 76 | |
| 77 | instance.invoke_set_ti1(slint::SharedString::from("Hallo")); |
| 78 | instance.invoke_set_ti2(slint::SharedString::from("Bonjour")); |
| 79 | assert_eq!(instance.get_text1(), slint::SharedString::from("Hallo")); |
| 80 | assert_eq!(instance.get_text2(), slint::SharedString::from("Text2New")); |
| 81 | assert_eq!(instance.get_ti1_text(), slint::SharedString::from("Hallo")); |
| 82 | assert_eq!(instance.get_ti2_text(), slint::SharedString::from("Bonjour")); |
| 83 | assert_eq!(instance.get_text_item_text(), slint::SharedString::from("Bonjour")); |
| 84 | |
| 85 | assert_eq!(instance.get_othercomp_some_value(), 0); |
| 86 | assert_eq!(instance.get_othercomp_some_value_alias(), 0); |
| 87 | assert_eq!(instance.get_othercomp_some_value_alias2(), 0); |
| 88 | instance.set_othercomp_some_value(88); |
| 89 | assert_eq!(instance.get_othercomp_some_value(), 88); |
| 90 | assert_eq!(instance.get_othercomp_some_value_alias(), 88); |
| 91 | assert_eq!(instance.get_othercomp_some_value_alias2(), 88); |
| 92 | instance.set_othercomp_some_value_alias(81); |
| 93 | assert_eq!(instance.get_othercomp_some_value(), 81); |
| 94 | assert_eq!(instance.get_othercomp_some_value_alias(), 81); |
| 95 | assert_eq!(instance.get_othercomp_some_value_alias2(), 81); |
| 96 | instance.set_othercomp_some_value_alias2(1); |
| 97 | assert_eq!(instance.get_othercomp_some_value(), 1); |
| 98 | assert_eq!(instance.get_othercomp_some_value_alias(), 1); |
| 99 | assert_eq!(instance.get_othercomp_some_value_alias2(), 1); |
| 100 | |
| 101 | ``` |
| 102 | |
| 103 | |
| 104 | |
| 105 | ```cpp |
| 106 | auto handle = TestCase::create(); |
| 107 | const TestCase &instance = *handle; |
| 108 | assert_eq(instance.get_text1(), slint::SharedString("Hello")); |
| 109 | assert_eq(instance.get_text2(), slint::SharedString("Blah")); |
| 110 | assert_eq(instance.get_ti1_text(), slint::SharedString("Hello")); |
| 111 | assert_eq(instance.get_ti2_text(), slint::SharedString("Blah")); |
| 112 | assert_eq(instance.get_text_item_text(), slint::SharedString("Blah")); |
| 113 | assert_eq(instance.get_othercomp_t(), instance.get_othercomp_get_text()); |
| 114 | assert_eq(instance.get_othercomp_t(), slint::SharedString("real value")); |
| 115 | assert_eq(instance.get_othercomp_get_text(), slint::SharedString("real value")); |
| 116 | |
| 117 | |
| 118 | instance.set_text1(slint::SharedString("Text1New")); |
| 119 | instance.set_text2(slint::SharedString("Text2New")); |
| 120 | assert_eq(instance.get_text1(), slint::SharedString("Text1New")); |
| 121 | assert_eq(instance.get_text2(), slint::SharedString("Text2New")); |
| 122 | assert_eq(instance.get_ti1_text(), slint::SharedString("Text1New")); |
| 123 | assert_eq(instance.get_ti2_text(), slint::SharedString("Text2New")); |
| 124 | assert_eq(instance.get_text_item_text(), slint::SharedString("Text2New")); |
| 125 | |
| 126 | instance.invoke_set_ti1(slint::SharedString("Hallo")); |
| 127 | instance.invoke_set_ti2(slint::SharedString("Bonjour")); |
| 128 | assert_eq(instance.get_text1(), slint::SharedString("Hallo")); |
| 129 | assert_eq(instance.get_text2(), slint::SharedString("Text2New")); |
| 130 | assert_eq(instance.get_ti1_text(), slint::SharedString("Hallo")); |
| 131 | assert_eq(instance.get_ti2_text(), slint::SharedString("Bonjour")); |
| 132 | assert_eq(instance.get_text_item_text(), slint::SharedString("Bonjour")); |
| 133 | |
| 134 | assert_eq(instance.get_othercomp_some_value(), 0); |
| 135 | assert_eq(instance.get_othercomp_some_value_alias(), 0); |
| 136 | assert_eq(instance.get_othercomp_some_value_alias2(), 0); |
| 137 | instance.set_othercomp_some_value(88); |
| 138 | assert_eq(instance.get_othercomp_some_value(), 88); |
| 139 | assert_eq(instance.get_othercomp_some_value_alias(), 88); |
| 140 | assert_eq(instance.get_othercomp_some_value_alias2(), 88); |
| 141 | instance.set_othercomp_some_value_alias(81); |
| 142 | assert_eq(instance.get_othercomp_some_value(), 81); |
| 143 | assert_eq(instance.get_othercomp_some_value_alias(), 81); |
| 144 | assert_eq(instance.get_othercomp_some_value_alias2(), 81); |
| 145 | instance.set_othercomp_some_value_alias2(1); |
| 146 | assert_eq(instance.get_othercomp_some_value(), 1); |
| 147 | assert_eq(instance.get_othercomp_some_value_alias(), 1); |
| 148 | assert_eq(instance.get_othercomp_some_value_alias2(), 1); |
| 149 | ``` |
| 150 | |
| 151 | |
| 152 | ```js |
| 153 | let instance = new slint.TestCase({}); |
| 154 | assert.equal(instance.text1, "Hello"); |
| 155 | assert.equal(instance.text2, "Blah"); |
| 156 | assert.equal(instance.ti1_text, "Hello"); |
| 157 | assert.equal(instance.ti2_text, "Blah"); |
| 158 | assert.equal(instance.text_item_text, "Blah"); |
| 159 | assert.equal(instance.othercomp_t, instance.othercomp_get_text); |
| 160 | assert.equal(instance.othercomp_t, "real value"); |
| 161 | assert.equal(instance.othercomp_get_text, "real value"); |
| 162 | |
| 163 | instance.text1 = "Text1New"; |
| 164 | instance.text2 = "Text2New"; |
| 165 | assert.equal(instance.text1, "Text1New"); |
| 166 | assert.equal(instance.text2, "Text2New"); |
| 167 | assert.equal(instance.ti1_text, "Text1New"); |
| 168 | assert.equal(instance.ti2_text, "Text2New"); |
| 169 | assert.equal(instance.text_item_text, "Text2New"); |
| 170 | |
| 171 | instance.set_ti1("Hallo"); |
| 172 | instance.set_ti2("Bonjour"); |
| 173 | assert.equal(instance.text1, "Hallo"); |
| 174 | assert.equal(instance.text2, "Text2New"); |
| 175 | assert.equal(instance.ti1_text, "Hallo"); |
| 176 | assert.equal(instance.ti2_text, "Bonjour"); |
| 177 | assert.equal(instance.text_item_text, "Bonjour"); |
| 178 | |
| 179 | assert.equal(instance.othercomp_some_value, 0); |
| 180 | assert.equal(instance.othercomp_some_value_alias, 0); |
| 181 | assert.equal(instance.othercomp_some_value_alias2, 0); |
| 182 | instance.othercomp_some_value = 88; |
| 183 | assert.equal(instance.othercomp_some_value, 88); |
| 184 | assert.equal(instance.othercomp_some_value_alias, 88); |
| 185 | assert.equal(instance.othercomp_some_value_alias2, 88); |
| 186 | instance.othercomp_some_value_alias = 81; |
| 187 | assert.equal(instance.othercomp_some_value, 81); |
| 188 | assert.equal(instance.othercomp_some_value_alias, 81); |
| 189 | assert.equal(instance.othercomp_some_value_alias2, 81); |
| 190 | instance.othercomp_some_value_alias2 = 1; |
| 191 | assert.equal(instance.othercomp_some_value, 1); |
| 192 | assert.equal(instance.othercomp_some_value_alias, 1); |
| 193 | assert.equal(instance.othercomp_some_value_alias2, 1); |
| 194 | ``` |
| 195 | |
| 196 | */ |
| 197 | |