| 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 | |
| 5 | component BackgroundExpr inherits Rectangle { |
| 6 | in property <bool> cond; |
| 7 | // conversion from color to brush do a Cast expression and this should work even when there is a return |
| 8 | background: { |
| 9 | if (cond) { |
| 10 | return blue; |
| 11 | } |
| 12 | red |
| 13 | } |
| 14 | } |
| 15 | component BackgroundExpr2 inherits Rectangle { |
| 16 | in property <int> val; |
| 17 | in property <bool> cond1; |
| 18 | pure callback foo(); |
| 19 | background: { |
| 20 | if (val > 20) { |
| 21 | if (val > 50) { |
| 22 | return green; |
| 23 | } else if val > 40 { |
| 24 | return yellow; |
| 25 | } else { |
| 26 | return blue; |
| 27 | }; |
| 28 | return black; |
| 29 | } |
| 30 | if val > 10 { |
| 31 | return pink; |
| 32 | } else { |
| 33 | foo(); |
| 34 | } |
| 35 | if val > 1 { |
| 36 | red |
| 37 | } else { |
| 38 | orange |
| 39 | } |
| 40 | |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | export component TestCase { |
| 45 | |
| 46 | bkg1 := BackgroundExpr { cond: true; } |
| 47 | bkg2 := BackgroundExpr { cond: false; } |
| 48 | bkg3 := BackgroundExpr2 { val: 0; } |
| 49 | bkg4 := BackgroundExpr2 { val: 11; } |
| 50 | bkg5 := BackgroundExpr2 { val: 21; } |
| 51 | |
| 52 | |
| 53 | out property <bool> test: |
| 54 | { |
| 55 | return bkg1.background == Colors.blue && bkg2.background == Colors.red |
| 56 | && bkg3.background == Colors.orange && bkg4.background == Colors.pink && bkg5.background == Colors.blue; |
| 57 | } |
| 58 | |
| 59 | |
| 60 | } |
| 61 | |
| 62 | |
| 63 | /* |
| 64 | ```cpp |
| 65 | auto handle = TestCase::create(); |
| 66 | const TestCase &instance = *handle; |
| 67 | assert(instance.get_test()); |
| 68 | ``` |
| 69 | |
| 70 | ```rust |
| 71 | let instance = TestCase::new().unwrap(); |
| 72 | assert!(instance.get_test()); |
| 73 | ``` |
| 74 | |
| 75 | */ |
| 76 | |