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
5export 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
33auto handle = TestCase::create();
34const TestCase &instance = *handle;
35assert_eq(instance.get_ta_width(), 100);
36assert(instance.get_test());
37instance.set_flag(true);
38assert_eq(instance.get_ta_width(), 100);
39// Half the animation
40slint_testing::mock_elapsed_time(100);
41assert_eq(instance.get_ta_width(), 150);
42// finish animation, and more
43slint_testing::mock_elapsed_time(200);
44assert_eq(instance.get_ta_width(), 200);
45
46```
47
48
49```rust
50let instance = TestCase::new().unwrap();
51assert_eq!(instance.get_ta_width(), 100);
52assert!(instance.get_test());
53instance.set_flag(true);
54assert_eq!(instance.get_ta_width(), 100);
55// Half the animation
56slint_testing::mock_elapsed_time(100);
57assert_eq!(instance.get_ta_width(), 150);
58// finish animation, and more
59slint_testing::mock_elapsed_time(200);
60assert_eq!(instance.get_ta_width(), 200);
61```
62
63```js
64var instance = new slint.TestCase({});
65assert.equal(instance.ta_width, 100);
66assert(instance.test);
67instance.flag = true;
68assert.equal(instance.ta_width, 100);
69// Half the animation
70slintlib.private_api.mock_elapsed_time(100);
71assert.equal(instance.ta_width, 150);
72// finish animation, and more
73slintlib.private_api.mock_elapsed_time(200);
74assert.equal(instance.ta_width, 200);
75```
76
77
78*/
79