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 | import { StyleMetrics } from "std-widgets.slint" ; |
5 | |
6 | global Glop := { |
7 | property <int> hello: 42; |
8 | property <int> second: 88; |
9 | property <int> third: 102; |
10 | } |
11 | |
12 | global DualBindingGlop := { |
13 | property third <=> Glop.third; |
14 | } |
15 | |
16 | Widget := Rectangle { |
17 | property second <=> Glop.second; |
18 | } |
19 | |
20 | TestCase := Rectangle { |
21 | // This is meant to test an alias to a native global. |
22 | // Unfortunately, this is only a native global with the Qt backend and not with the Test backend |
23 | property <length> alias_to_native <=> StyleMetrics.text_cursor_width; |
24 | property <int> alias_to_global <=> Glop.hello; |
25 | property <bool> test: alias_to_native == StyleMetrics.text_cursor_width && alias_to_global == 42 && indirect == 88; |
26 | property <int> indirect <=> widget.second; |
27 | property <int> direct: Glop.second; |
28 | property <int> dual <=> DualBindingGlop.third; |
29 | |
30 | widget := Widget { } |
31 | } |
32 | |
33 | /* |
34 | ```rust |
35 | let instance = TestCase::new().unwrap(); |
36 | assert!(instance.get_test()); |
37 | assert_eq!(instance.get_alias_to_global(), 42); |
38 | instance.set_alias_to_global(123); |
39 | assert_eq!(instance.get_alias_to_global(), 123); |
40 | assert_eq!(instance.get_indirect(), 88); |
41 | instance.set_indirect(99); |
42 | assert_eq!(instance.get_direct(), 99); |
43 | assert_eq!(instance.get_dual(), 102); |
44 | |
45 | ``` |
46 | |
47 | ```cpp |
48 | auto handle = TestCase::create(); |
49 | const TestCase &instance = *handle; |
50 | assert(instance.get_test()); |
51 | assert_eq(instance.get_dual(), 102); |
52 | ``` |
53 | |
54 | ```js |
55 | let instance = new slint.TestCase({}); |
56 | assert(instance.test); |
57 | assert.equal(instance.alias_to_global, 42); |
58 | instance.alias_to_global = 123; |
59 | assert.equal(instance.alias_to_global, 123); |
60 | assert.equal(instance.indirect, 88); |
61 | instance.indirect = 99; |
62 | assert.equal(instance.direct, 99); |
63 | assert.equal(instance.dual, 102); |
64 | ``` |
65 | |
66 | */ |
67 | |