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 | |
5 | AnimatedObject := Rectangle { |
6 | property <int> animated_prop; |
7 | animate animated_prop { duration: aa_duration; } |
8 | property <duration> aa_duration: 1s; |
9 | } |
10 | |
11 | NotAnimatedObject := Rectangle { |
12 | property <int> value; |
13 | property <int> animated_prop: value; |
14 | } |
15 | |
16 | TestCase := Rectangle { |
17 | property <int> value : 1000; |
18 | property <int> o1_val: o1.animated_prop; |
19 | property <int> o2_val: o2.animated_prop; |
20 | property <int> o3_val: o3.animated_prop; |
21 | property <int> o4_val: o4.animated_prop; |
22 | o1 := AnimatedObject { |
23 | animated_prop: value; |
24 | } |
25 | o2 := AnimatedObject { |
26 | aa_duration: 2s; |
27 | animated_prop: value; |
28 | } |
29 | o3 := AnimatedObject { |
30 | animate animated_prop { duration: 3s; } |
31 | animated_prop: value; |
32 | } |
33 | o4 := NotAnimatedObject { |
34 | value: root.value; |
35 | animate animated_prop { duration: 4s; } |
36 | } |
37 | } |
38 | |
39 | |
40 | /* |
41 | |
42 | ```rust |
43 | let instance = TestCase::new().unwrap(); |
44 | assert_eq!(instance.get_o1_val(), 1000, "o1"); |
45 | assert_eq!(instance.get_o2_val(), 1000, "o2"); |
46 | assert_eq!(instance.get_o3_val(), 1000, "o3"); |
47 | assert_eq!(instance.get_o4_val(), 1000, "o4"); |
48 | instance.set_value(1600); |
49 | // animation not started |
50 | assert_eq!(instance.get_o1_val(), 1000, "o1 - 0"); |
51 | assert_eq!(instance.get_o2_val(), 1000, "o2 - 0"); |
52 | assert_eq!(instance.get_o3_val(), 1000, "o3 - 0"); |
53 | assert_eq!(instance.get_o4_val(), 1000, "o4 - 0"); |
54 | |
55 | |
56 | slint_testing::mock_elapsed_time(1000); // 1s |
57 | assert_eq!(instance.get_o1_val(), 1000 + 600, "o1 - 1"); // done |
58 | assert_eq!(instance.get_o2_val(), 1000 + 600/2, "o2 - 1"); // ½ |
59 | assert_eq!(instance.get_o3_val(), 1000 + 600/3, "o3 - 1"); // ⅓ |
60 | assert_eq!(instance.get_o4_val(), 1000 + 600/4, "o4 - 1"); // ¼ |
61 | |
62 | slint_testing::mock_elapsed_time(1000); |
63 | assert_eq!(instance.get_o1_val(), 1600, "o1 - 2"); |
64 | assert_eq!(instance.get_o2_val(), 1600, "o2 - 2"); |
65 | assert_eq!(instance.get_o3_val(), 1000 + 2*600/3, "o3 - 2"); |
66 | assert_eq!(instance.get_o4_val(), 1000 + 600/2, "o4 - 2"); |
67 | |
68 | slint_testing::mock_elapsed_time(1000); |
69 | assert_eq!(instance.get_o1_val(), 1600, "o1 - 3"); |
70 | assert_eq!(instance.get_o2_val(), 1600, "o2 - 3"); |
71 | assert_eq!(instance.get_o3_val(), 1600, "o3 - 3"); |
72 | assert_eq!(instance.get_o4_val(), 1000 + 3*600/4, "o4 - 3"); |
73 | |
74 | |
75 | slint_testing::mock_elapsed_time(1000); |
76 | assert_eq!(instance.get_o1_val(), 1600, "o1 - 4"); |
77 | assert_eq!(instance.get_o2_val(), 1600, "o2 - 4"); |
78 | assert_eq!(instance.get_o3_val(), 1600, "o3 - 4"); |
79 | assert_eq!(instance.get_o4_val(), 1600, "o4 - 4"); |
80 | |
81 | ``` |
82 | |
83 | */ |
84 | |