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 | // Test that structs work if they are only referenced by callbacks |
5 | |
6 | struct Foo1 { member: int, } |
7 | struct Foo2 { a: Foo1 } |
8 | struct Foo3 { b: int } |
9 | |
10 | struct DeleteMe { c: color } |
11 | |
12 | struct Palette { |
13 | menuBar : brush, |
14 | mainContent : brush, |
15 | box : brush, |
16 | } |
17 | |
18 | export component TestCase inherits Rectangle { |
19 | pure callback cb1(Foo2) -> Foo3; |
20 | cb1(foo) => { return { b: foo.a.member+1 }; } |
21 | |
22 | in-out property<Foo2> xx; |
23 | pure callback cb2(Foo2, Foo2)->Foo2; |
24 | in-out property<Foo2> xx2: root.cb2(root.xx, root.xx); |
25 | |
26 | |
27 | // Based on Issue #1733 |
28 | Rectangle { |
29 | property<[DeleteMe]> data; |
30 | for d[i] in self.data: Rectangle { } |
31 | } |
32 | |
33 | // Bug #2765 |
34 | out property<Palette> palette : xx.a.member > 32 ? { |
35 | menuBar : #6D7BFB, |
36 | mainContent : #fbfbfb, |
37 | box : #ffffff, |
38 | } : { |
39 | menuBar : #2937A7, |
40 | mainContent : #040404, |
41 | box : #000000, |
42 | }; |
43 | |
44 | } |
45 | |
46 | |
47 | /* |
48 | ```rust |
49 | let instance = TestCase::new().unwrap(); |
50 | |
51 | assert_eq!(instance.invoke_cb1(Foo2{ a: Foo1{ member: 123 } }).b, 124); |
52 | ``` |
53 | |
54 | ```cpp |
55 | auto handle = TestCase::create(); |
56 | const TestCase &instance = *handle; |
57 | |
58 | assert_eq(instance.invoke_cb1(Foo2{ Foo1{ 123 } }).b, 124); |
59 | ``` |
60 | |
61 | ```js |
62 | var instance = new slint.TestCase(); |
63 | assert.equal(instance.cb1({a: {member: 123}}).b, 124); |
64 | ``` |
65 | |
66 | */ |
67 | |