| 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 | property <int> xx : 1000; |
| 6 | |
| 7 | property <easing> ea: ease; |
| 8 | |
| 9 | animate x { |
| 10 | duration: xx * 1ms; |
| 11 | easing: ea; |
| 12 | } |
| 13 | |
| 14 | property<int> hello: 40; |
| 15 | animate hello { |
| 16 | duration: 1200ms; |
| 17 | } |
| 18 | |
| 19 | property<bool> condition: true; |
| 20 | property<int> binding_dep: condition ? 100 : 150; |
| 21 | animate binding_dep { |
| 22 | duration: 1200ms; |
| 23 | } |
| 24 | |
| 25 | property<int> direction: 100; |
| 26 | animate direction { |
| 27 | duration: 600ms; |
| 28 | direction: alternate-reverse; |
| 29 | iteration-count: 2; |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | /* |
| 34 | |
| 35 | ```rust |
| 36 | let instance = TestCase::new().unwrap(); |
| 37 | assert_eq!(instance.get_hello(), 40); |
| 38 | assert_eq!(instance.get_binding_dep(), 100); |
| 39 | assert_eq!(instance.get_direction(), 100); |
| 40 | instance.set_condition(false); |
| 41 | instance.set_hello(60); |
| 42 | instance.set_direction(200); |
| 43 | // no time has elapsed yet |
| 44 | assert_eq!(instance.get_hello(), 40); |
| 45 | assert_eq!(instance.get_binding_dep(), 100); |
| 46 | assert_eq!(instance.get_direction(), 200); |
| 47 | |
| 48 | // Half the animation |
| 49 | slint_testing::mock_elapsed_time(600); |
| 50 | assert_eq!(instance.get_hello(), 50); |
| 51 | assert_eq!(instance.get_binding_dep(), 125); |
| 52 | assert_eq!(instance.get_direction(), 100); |
| 53 | |
| 54 | |
| 55 | // Remaining half |
| 56 | slint_testing::mock_elapsed_time(600); |
| 57 | assert_eq!(instance.get_hello(), 60); |
| 58 | assert_eq!(instance.get_binding_dep(), 150); |
| 59 | assert_eq!(instance.get_direction(), 200); |
| 60 | |
| 61 | slint_testing::mock_elapsed_time(100); |
| 62 | assert_eq!(instance.get_hello(), 60); |
| 63 | assert_eq!(instance.get_binding_dep(), 150); |
| 64 | assert_eq!(instance.get_direction(), 200); |
| 65 | |
| 66 | // Changing the value and waiting should have effect without |
| 67 | // querying the value (because te dirty event should cause the animation to start) |
| 68 | instance.set_condition(true); |
| 69 | instance.set_hello(30); |
| 70 | instance.set_direction(100); |
| 71 | slint_testing::mock_elapsed_time(600); |
| 72 | assert_eq!(instance.get_hello(), 45); |
| 73 | assert_eq!(instance.get_binding_dep(), 125); |
| 74 | assert_eq!(instance.get_direction(), 200); |
| 75 | |
| 76 | ``` |
| 77 | |
| 78 | |
| 79 | ```cpp |
| 80 | auto handle = TestCase::create(); |
| 81 | const TestCase &instance = *handle; |
| 82 | assert_eq(instance.get_hello(), 40); |
| 83 | assert_eq(instance.get_binding_dep(), 100); |
| 84 | assert_eq(instance.get_direction(), 100); |
| 85 | instance.set_condition(false); |
| 86 | instance.set_hello(60); |
| 87 | instance.set_direction(200); |
| 88 | // no time has elapsed yet |
| 89 | assert_eq(instance.get_hello(), 40); |
| 90 | assert_eq(instance.get_binding_dep(), 100); |
| 91 | assert_eq(instance.get_direction(), 200); |
| 92 | |
| 93 | // Half the animation |
| 94 | slint_testing::mock_elapsed_time(600); |
| 95 | assert_eq(instance.get_hello(), 50); |
| 96 | assert_eq(instance.get_binding_dep(), 125); |
| 97 | assert_eq(instance.get_direction(), 100); |
| 98 | |
| 99 | |
| 100 | // Remaining half |
| 101 | slint_testing::mock_elapsed_time(600); |
| 102 | assert_eq(instance.get_hello(), 60); |
| 103 | assert_eq(instance.get_binding_dep(), 150); |
| 104 | assert_eq(instance.get_direction(), 200); |
| 105 | |
| 106 | slint_testing::mock_elapsed_time(100); |
| 107 | assert_eq(instance.get_hello(), 60); |
| 108 | assert_eq(instance.get_binding_dep(), 150); |
| 109 | assert_eq(instance.get_direction(), 200); |
| 110 | |
| 111 | // Changing the value and waiting should have effect without |
| 112 | // querying the value (because te dirty event should cause the animation to start) |
| 113 | instance.set_condition(true); |
| 114 | instance.set_hello(30); |
| 115 | instance.set_direction(100); |
| 116 | slint_testing::mock_elapsed_time(600); |
| 117 | assert_eq(instance.get_hello(), 45); |
| 118 | assert_eq(instance.get_binding_dep(), 125); |
| 119 | assert_eq(instance.get_direction(), 200); |
| 120 | ``` |
| 121 | |
| 122 | ```js |
| 123 | var instance = new slint.TestCase({}); |
| 124 | assert.equal(instance.hello, 40); |
| 125 | assert.equal(instance.binding_dep, 100); |
| 126 | assert.equal(instance.direction, 100); |
| 127 | instance.condition = false; |
| 128 | instance.hello = 60; |
| 129 | instance.direction = 200; |
| 130 | // no time has elapsed yet |
| 131 | assert.equal(instance.hello, 40); |
| 132 | assert.equal(instance.binding_dep, 100); |
| 133 | assert.equal(instance.direction, 200); |
| 134 | |
| 135 | // Half the animation |
| 136 | slintlib.private_api.mock_elapsed_time(600); |
| 137 | assert.equal(instance.hello, 50); |
| 138 | assert.equal(instance.binding_dep, 125); |
| 139 | assert.equal(instance.direction, 100); |
| 140 | // Remaining half |
| 141 | slintlib.private_api.mock_elapsed_time(600); |
| 142 | assert.equal(instance.hello, 60); |
| 143 | assert.equal(instance.binding_dep, 150); |
| 144 | assert.equal(instance.direction, 200); |
| 145 | slintlib.private_api.mock_elapsed_time(100); |
| 146 | assert.equal(instance.hello, 60); |
| 147 | assert.equal(instance.binding_dep, 150); |
| 148 | assert.equal(instance.direction, 200); |
| 149 | |
| 150 | // Changing the value and waiting should have effect without |
| 151 | // querying the value (because te dirty event should cause the animation to start) |
| 152 | instance.condition = true; |
| 153 | instance.hello = 30; |
| 154 | instance.direction = 100; |
| 155 | slintlib.private_api.mock_elapsed_time(600); |
| 156 | assert.equal(instance.hello, 45); |
| 157 | assert.equal(instance.binding_dep, 125); |
| 158 | assert.equal(instance.direction, 200); |
| 159 | ``` |
| 160 | */ |
| 161 | |