@@ -14,6 +14,8 @@ pub enum AnimationTimeMode {
14
14
#[ derive( Debug , Default ) ]
15
15
pub struct AnimationMessageHandler {
16
16
live_preview : bool ,
17
+ /// Used to re-send the UI on the next frame after playback starts
18
+ live_preview_recently_zero : bool ,
17
19
timestamp : f64 ,
18
20
frame_index : f64 ,
19
21
animation_start : Option < f64 > ,
@@ -29,6 +31,10 @@ impl AnimationMessageHandler {
29
31
} ;
30
32
TimingInformation { time : self . timestamp , animation_time }
31
33
}
34
+
35
+ pub fn is_playing ( & self ) -> bool {
36
+ self . live_preview
37
+ }
32
38
}
33
39
34
40
impl MessageHandler < AnimationMessage , ( ) > for AnimationMessageHandler {
@@ -38,23 +44,37 @@ impl MessageHandler<AnimationMessage, ()> for AnimationMessageHandler {
38
44
if self . animation_start . is_none ( ) {
39
45
self . animation_start = Some ( self . timestamp ) ;
40
46
}
41
- self . live_preview = !self . live_preview
47
+ self . live_preview = !self . live_preview ;
48
+
49
+ // Update the restart and pause/play buttons
50
+ responses. add ( PortfolioMessage :: UpdateDocumentWidgets ) ;
42
51
}
43
52
AnimationMessage :: EnableLivePreview => {
44
53
if self . animation_start . is_none ( ) {
45
54
self . animation_start = Some ( self . timestamp ) ;
46
55
}
47
- self . live_preview = true
56
+ self . live_preview = true ;
57
+
58
+ // Update the restart and pause/play buttons
59
+ responses. add ( PortfolioMessage :: UpdateDocumentWidgets ) ;
60
+ }
61
+ AnimationMessage :: DisableLivePreview => {
62
+ self . live_preview = false ;
63
+
64
+ // Update the restart and pause/play buttons
65
+ responses. add ( PortfolioMessage :: UpdateDocumentWidgets ) ;
48
66
}
49
- AnimationMessage :: DisableLivePreview => self . live_preview = false ,
50
67
AnimationMessage :: SetFrameIndex ( frame) => {
51
68
self . frame_index = frame;
52
- log:: debug!( "set frame index to {}" , frame) ;
53
- responses. add ( PortfolioMessage :: SubmitActiveGraphRender )
69
+ responses. add ( PortfolioMessage :: SubmitActiveGraphRender ) ;
70
+ // Update the restart and pause/play buttons
71
+ responses. add ( PortfolioMessage :: UpdateDocumentWidgets ) ;
54
72
}
55
73
AnimationMessage :: SetTime ( time) => {
56
74
self . timestamp = time;
57
- responses. add ( AnimationMessage :: UpdateTime ) ;
75
+ if self . live_preview {
76
+ responses. add ( AnimationMessage :: UpdateTime ) ;
77
+ }
58
78
}
59
79
AnimationMessage :: IncrementFrameCounter => {
60
80
if self . live_preview {
@@ -64,21 +84,32 @@ impl MessageHandler<AnimationMessage, ()> for AnimationMessageHandler {
64
84
}
65
85
AnimationMessage :: UpdateTime => {
66
86
if self . live_preview {
67
- responses. add ( PortfolioMessage :: SubmitActiveGraphRender )
87
+ responses. add ( PortfolioMessage :: SubmitActiveGraphRender ) ;
88
+
89
+ if self . live_preview_recently_zero {
90
+ // Update the restart and pause/play buttons
91
+ responses. add ( PortfolioMessage :: UpdateDocumentWidgets ) ;
92
+ self . live_preview_recently_zero = false ;
93
+ }
68
94
}
69
95
}
70
- AnimationMessage :: ResetAnimation => {
96
+ AnimationMessage :: RestartAnimation => {
71
97
self . frame_index = 0. ;
72
98
self . animation_start = None ;
73
- responses. add ( PortfolioMessage :: SubmitActiveGraphRender )
99
+ self . live_preview_recently_zero = true ;
100
+ responses. add ( PortfolioMessage :: SubmitActiveGraphRender ) ;
101
+ // Update the restart and pause/play buttons
102
+ responses. add ( PortfolioMessage :: UpdateDocumentWidgets ) ;
103
+ }
104
+ AnimationMessage :: SetAnimationTimeMode ( animation_time_mode) => {
105
+ self . animation_time_mode = animation_time_mode;
74
106
}
75
- AnimationMessage :: SetAnimationTimeMode ( animation_time_mode) => self . animation_time_mode = animation_time_mode,
76
107
}
77
108
}
78
109
79
110
advertise_actions ! ( AnimationMessageDiscriminant ;
80
111
ToggleLivePreview ,
81
112
SetFrameIndex ,
82
- ResetAnimation ,
113
+ RestartAnimation ,
83
114
) ;
84
115
}
0 commit comments