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
4import { StyleMetrics } from "std-widgets.slint";
5
6global Glop := {
7 property <int> hello: 42;
8 property <int> second: 88;
9 property <int> third: 102;
10}
11
12global DualBindingGlop := {
13 property third <=> Glop.third;
14}
15
16Widget := Rectangle {
17 property second <=> Glop.second;
18}
19
20TestCase := 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
35let instance = TestCase::new().unwrap();
36assert!(instance.get_test());
37assert_eq!(instance.get_alias_to_global(), 42);
38instance.set_alias_to_global(123);
39assert_eq!(instance.get_alias_to_global(), 123);
40assert_eq!(instance.get_indirect(), 88);
41instance.set_indirect(99);
42assert_eq!(instance.get_direct(), 99);
43assert_eq!(instance.get_dual(), 102);
44
45```
46
47```cpp
48auto handle = TestCase::create();
49const TestCase &instance = *handle;
50assert(instance.get_test());
51assert_eq(instance.get_dual(), 102);
52```
53
54```js
55let instance = new slint.TestCase({});
56assert(instance.test);
57assert.equal(instance.alias_to_global, 42);
58instance.alias_to_global = 123;
59assert.equal(instance.alias_to_global, 123);
60assert.equal(instance.indirect, 88);
61instance.indirect = 99;
62assert.equal(instance.direct, 99);
63assert.equal(instance.dual, 102);
64```
65
66*/
67