| 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 | TestCase := Rectangle { |
| 5 | pure callback test_func(int) -> int; |
| 6 | pure callback test_func2(string, int) -> string; |
| 7 | test_func2(str, val) => { str + "=" + (val + some_value) } |
| 8 | |
| 9 | property <int> test_prop: 4 + test_func(2); |
| 10 | property <string> test_prop2: test_func2("hello" , 42); |
| 11 | property <int> some_value: 8; |
| 12 | |
| 13 | callback dummy() -> int; |
| 14 | dummy => { 4.4 } |
| 15 | callback returns_void; |
| 16 | returns_void => { test_func2("haha" , 8) } |
| 17 | |
| 18 | property <bool> test: test_prop == 4 && test_prop2 == "hello=50" ; |
| 19 | } |
| 20 | |
| 21 | /* |
| 22 | ```rust |
| 23 | let instance = TestCase::new().unwrap(); |
| 24 | instance.on_test_func({ |
| 25 | let weak = instance.as_weak(); |
| 26 | move |a| weak.upgrade().unwrap().get_some_value() * a |
| 27 | }); |
| 28 | assert_eq!(instance.get_test_prop(), 4 + 16); |
| 29 | assert_eq!(instance.get_test_prop2(), slint::SharedString::from("hello=50")); |
| 30 | instance.set_some_value(2); |
| 31 | assert_eq!(instance.get_test_prop(), 4 + 4); |
| 32 | assert_eq!(instance.get_test_prop2(), slint::SharedString::from("hello=44")); |
| 33 | |
| 34 | assert_eq!(instance.invoke_test_func2("xxx".into(), 1), slint::SharedString::from("xxx=3")); |
| 35 | ``` |
| 36 | |
| 37 | ```cpp |
| 38 | auto handle = TestCase::create(); |
| 39 | const TestCase &instance = *handle; |
| 40 | instance.on_test_func([weak = slint::ComponentWeakHandle(handle)](int a) { |
| 41 | return (*weak.lock())->get_some_value() * a; |
| 42 | }); |
| 43 | assert_eq(instance.get_test_prop(), 4 + 16); |
| 44 | assert_eq(instance.get_test_prop2(), slint::SharedString("hello=50")); |
| 45 | instance.set_some_value(2); |
| 46 | assert_eq(instance.get_test_prop(), 4 + 4); |
| 47 | assert_eq(instance.get_test_prop2(), slint::SharedString("hello=44")); |
| 48 | |
| 49 | assert_eq(instance.invoke_test_func2("xxx", 1), slint::SharedString("xxx=3")); |
| 50 | ``` |
| 51 | |
| 52 | |
| 53 | ```js |
| 54 | var instance = new slint.TestCase({ |
| 55 | test_func: function(a) { return instance.some_value * a; } |
| 56 | }); |
| 57 | assert.equal(instance.test_prop, 4 + 16); |
| 58 | assert.equal(instance.test_prop2, "hello=50"); |
| 59 | instance.some_value = 2; |
| 60 | assert.equal(instance.test_prop, 4 + 4); |
| 61 | assert.equal(instance.test_prop2, "hello=44"); |
| 62 | |
| 63 | assert.equal(instance.test_func2("xxx", 1), "xxx=3"); |
| 64 | ``` |
| 65 | */ |
| 66 | |