1 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
2 | // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial |
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 | } |
26 | |
27 | /* |
28 | |
29 | ```rust |
30 | let instance = TestCase::new().unwrap(); |
31 | assert_eq!(instance.get_hello(), 40); |
32 | assert_eq!(instance.get_binding_dep(), 100); |
33 | instance.set_condition(false); |
34 | instance.set_hello(60); |
35 | // no time has elapsed yet |
36 | assert_eq!(instance.get_hello(), 40); |
37 | assert_eq!(instance.get_binding_dep(), 100); |
38 | |
39 | // Half the animation |
40 | slint_testing::mock_elapsed_time(600); |
41 | assert_eq!(instance.get_hello(), 50); |
42 | assert_eq!(instance.get_binding_dep(), 125); |
43 | |
44 | |
45 | // Remaining half |
46 | slint_testing::mock_elapsed_time(600); |
47 | assert_eq!(instance.get_hello(), 60); |
48 | assert_eq!(instance.get_binding_dep(), 150); |
49 | |
50 | slint_testing::mock_elapsed_time(100); |
51 | assert_eq!(instance.get_hello(), 60); |
52 | assert_eq!(instance.get_binding_dep(), 150); |
53 | |
54 | // Changing the value and waiting should have effect without |
55 | // querying the value (because te dirty event should cause the animation to start) |
56 | instance.set_condition(true); |
57 | instance.set_hello(30); |
58 | slint_testing::mock_elapsed_time(600); |
59 | assert_eq!(instance.get_hello(), 45); |
60 | assert_eq!(instance.get_binding_dep(), 125); |
61 | |
62 | ``` |
63 | |
64 | |
65 | ```cpp |
66 | auto handle = TestCase::create(); |
67 | const TestCase &instance = *handle; |
68 | assert_eq(instance.get_hello(), 40); |
69 | assert_eq(instance.get_binding_dep(), 100); |
70 | instance.set_condition(false); |
71 | instance.set_hello(60); |
72 | // no time has elapsed yet |
73 | assert_eq(instance.get_hello(), 40); |
74 | assert_eq(instance.get_binding_dep(), 100); |
75 | |
76 | // Half the animation |
77 | slint_testing::mock_elapsed_time(600); |
78 | assert_eq(instance.get_hello(), 50); |
79 | assert_eq(instance.get_binding_dep(), 125); |
80 | |
81 | |
82 | // Remaining half |
83 | slint_testing::mock_elapsed_time(600); |
84 | assert_eq(instance.get_hello(), 60); |
85 | assert_eq(instance.get_binding_dep(), 150); |
86 | |
87 | slint_testing::mock_elapsed_time(100); |
88 | assert_eq(instance.get_hello(), 60); |
89 | assert_eq(instance.get_binding_dep(), 150); |
90 | |
91 | // Changing the value and waiting should have effect without |
92 | // querying the value (because te dirty event should cause the animation to start) |
93 | instance.set_condition(true); |
94 | instance.set_hello(30); |
95 | slint_testing::mock_elapsed_time(600); |
96 | assert_eq(instance.get_hello(), 45); |
97 | assert_eq(instance.get_binding_dep(), 125); |
98 | ``` |
99 | |
100 | ```js |
101 | var instance = new slint.TestCase({}); |
102 | assert.equal(instance.hello, 40); |
103 | assert.equal(instance.binding_dep, 100); |
104 | instance.condition = false; |
105 | instance.hello = 60; |
106 | // no time has elapsed yet |
107 | assert.equal(instance.hello, 40); |
108 | assert.equal(instance.binding_dep, 100); |
109 | |
110 | // Half the animation |
111 | slintlib.private_api.mock_elapsed_time(600); |
112 | assert.equal(instance.hello, 50); |
113 | assert.equal(instance.binding_dep, 125); |
114 | // Remaining half |
115 | slintlib.private_api.mock_elapsed_time(600); |
116 | assert.equal(instance.hello, 60); |
117 | assert.equal(instance.binding_dep, 150); |
118 | slintlib.private_api.mock_elapsed_time(100); |
119 | assert.equal(instance.hello, 60); |
120 | assert.equal(instance.binding_dep, 150); |
121 | |
122 | // Changing the value and waiting should have effect without |
123 | // querying the value (because te dirty event should cause the animation to start) |
124 | instance.condition = true; |
125 | instance.hello = 30; |
126 | slintlib.private_api.mock_elapsed_time(600); |
127 | assert.equal(instance.hello, 45); |
128 | assert.equal(instance.binding_dep, 125); |
129 | |
130 | ``` |
131 | */ |
132 | |