| 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 | export component TestCase { |
| 6 | width: 200px; |
| 7 | height: 300px; |
| 8 | in-out property <bool> flag; |
| 9 | |
| 10 | HorizontalLayout { |
| 11 | r1 := Rectangle { |
| 12 | width: root.flag ? 0% : 50%; |
| 13 | animate width { duration: 200ms; } |
| 14 | background: red; |
| 15 | } |
| 16 | |
| 17 | ta := TouchArea { |
| 18 | clicked => { |
| 19 | root.flag = !root.flag; |
| 20 | } |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | out property <int> ta-width: ta.width / 1px; |
| 25 | out property <bool> test: ta-width == 100; |
| 26 | } |
| 27 | |
| 28 | |
| 29 | |
| 30 | /* |
| 31 | |
| 32 | ```cpp |
| 33 | auto handle = TestCase::create(); |
| 34 | const TestCase &instance = *handle; |
| 35 | assert_eq(instance.get_ta_width(), 100); |
| 36 | assert(instance.get_test()); |
| 37 | instance.set_flag(true); |
| 38 | assert_eq(instance.get_ta_width(), 100); |
| 39 | // Half the animation |
| 40 | slint_testing::mock_elapsed_time(100); |
| 41 | assert_eq(instance.get_ta_width(), 150); |
| 42 | // finish animation, and more |
| 43 | slint_testing::mock_elapsed_time(200); |
| 44 | assert_eq(instance.get_ta_width(), 200); |
| 45 | |
| 46 | ``` |
| 47 | |
| 48 | |
| 49 | ```rust |
| 50 | let instance = TestCase::new().unwrap(); |
| 51 | assert_eq!(instance.get_ta_width(), 100); |
| 52 | assert!(instance.get_test()); |
| 53 | instance.set_flag(true); |
| 54 | assert_eq!(instance.get_ta_width(), 100); |
| 55 | // Half the animation |
| 56 | slint_testing::mock_elapsed_time(100); |
| 57 | assert_eq!(instance.get_ta_width(), 150); |
| 58 | // finish animation, and more |
| 59 | slint_testing::mock_elapsed_time(200); |
| 60 | assert_eq!(instance.get_ta_width(), 200); |
| 61 | ``` |
| 62 | |
| 63 | ```js |
| 64 | var instance = new slint.TestCase({}); |
| 65 | assert.equal(instance.ta_width, 100); |
| 66 | assert(instance.test); |
| 67 | instance.flag = true; |
| 68 | assert.equal(instance.ta_width, 100); |
| 69 | // Half the animation |
| 70 | slintlib.private_api.mock_elapsed_time(100); |
| 71 | assert.equal(instance.ta_width, 150); |
| 72 | // finish animation, and more |
| 73 | slintlib.private_api.mock_elapsed_time(200); |
| 74 | assert.equal(instance.ta_width, 200); |
| 75 | ``` |
| 76 | |
| 77 | |
| 78 | */ |
| 79 | |