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 | //include_path: ../../helper_components |
5 | |
6 | global MyGlobal := { |
7 | property <int> hello: 42; |
8 | } |
9 | |
10 | export { MyGlobal } |
11 | export { MyGlobal as GlobalAlias } |
12 | |
13 | TestCase := Rectangle { |
14 | property <bool> test_global_prop_value: MyGlobal.hello == 100; |
15 | } |
16 | |
17 | /* |
18 | ```rust |
19 | let instance = TestCase::new().unwrap(); |
20 | assert!(!instance.get_test_global_prop_value()); |
21 | assert_eq!(MyGlobal::get(&instance).get_hello(), 42); |
22 | assert_eq!(GlobalAlias::get(&instance).get_hello(), 42); |
23 | instance.global::<MyGlobal<'_>>().set_hello(100); |
24 | assert!(instance.get_test_global_prop_value()); |
25 | assert_eq!(MyGlobal::get(&instance).get_hello(), 100); |
26 | assert_eq!(GlobalAlias::get(&instance).get_hello(), 100); |
27 | ``` |
28 | |
29 | ```cpp |
30 | auto handle = TestCase::create(); |
31 | const TestCase &instance = *handle; |
32 | assert(!instance.get_test_global_prop_value()); |
33 | assert_eq(instance.global<MyGlobal>().get_hello(), 42); |
34 | assert_eq(instance.global<GlobalAlias>().get_hello(), 42); |
35 | instance.global<MyGlobal>().set_hello(100); |
36 | assert(instance.get_test_global_prop_value()); |
37 | assert_eq(instance.global<MyGlobal>().get_hello(), 100); |
38 | assert_eq(instance.global<GlobalAlias>().get_hello(), 100); |
39 | |
40 | ``` |
41 | |
42 | ```js |
43 | let instance = new slint.TestCase({}); |
44 | assert(!instance.test_global_prop_value); |
45 | assert.equal(instance.MyGlobal.hello, 42);; |
46 | assert.equal(instance.GlobalAlias.hello, 42);; |
47 | instance.MyGlobal.hello = 100; |
48 | assert(instance.test_global_prop_value); |
49 | assert.equal(instance.MyGlobal.hello, 100); |
50 | assert.equal(instance.GlobalAlias.hello, 100); |
51 | ``` |
52 | |
53 | */ |
54 | |