3
3
// rustdoc-stripper-ignore-next
4
4
//! Traits intended for subclassing [`PixbufAnimationIter`](crate::PixbufAnimationIter).
5
5
6
- use std:: time:: Duration ;
6
+ use std:: time:: { Duration , SystemTime } ;
7
7
8
8
use glib:: { subclass:: prelude:: * , translate:: * , Cast } ;
9
9
@@ -24,16 +24,16 @@ pub trait PixbufAnimationIterImpl: ObjectImpl {
24
24
self . parent_on_currently_loading_frame ( )
25
25
}
26
26
27
- fn advance ( & self , time : Duration ) -> bool {
28
- self . parent_advance ( time )
27
+ fn advance ( & self , current_time : SystemTime ) -> bool {
28
+ self . parent_advance ( current_time )
29
29
}
30
30
}
31
31
32
32
pub trait PixbufAnimationIterImplExt : ObjectSubclass {
33
33
fn parent_delay_time ( & self ) -> Option < Duration > ;
34
34
fn parent_pixbuf ( & self ) -> Pixbuf ;
35
35
fn parent_on_currently_loading_frame ( & self ) -> bool ;
36
- fn parent_advance ( & self , time : Duration ) -> bool ;
36
+ fn parent_advance ( & self , current_time : SystemTime ) -> bool ;
37
37
}
38
38
39
39
impl < T : PixbufAnimationIterImpl > PixbufAnimationIterImplExt for T {
@@ -51,10 +51,10 @@ impl<T: PixbufAnimationIterImpl> PixbufAnimationIterImplExt for T {
51
51
. unsafe_cast_ref :: < PixbufAnimationIter > ( )
52
52
. to_glib_none ( )
53
53
. 0 ) ;
54
- if time == - 1 {
54
+ if time < 0 {
55
55
None
56
56
} else {
57
- Some ( Duration :: from_millis ( time. try_into ( ) . unwrap ( ) ) )
57
+ Some ( Duration :: from_millis ( time as u64 ) )
58
58
}
59
59
}
60
60
}
@@ -93,7 +93,7 @@ impl<T: PixbufAnimationIterImpl> PixbufAnimationIterImplExt for T {
93
93
}
94
94
}
95
95
96
- fn parent_advance ( & self , time : Duration ) -> bool {
96
+ fn parent_advance ( & self , current_time : SystemTime ) -> bool {
97
97
unsafe {
98
98
let data = T :: type_data ( ) ;
99
99
let parent_class =
@@ -102,16 +102,19 @@ impl<T: PixbufAnimationIterImpl> PixbufAnimationIterImplExt for T {
102
102
. advance
103
103
. expect ( "No parent class implementation for \" advance\" " ) ;
104
104
105
+ let diff = current_time
106
+ . duration_since ( SystemTime :: UNIX_EPOCH )
107
+ . expect ( "failed to convert time" ) ;
105
108
let time = glib:: ffi:: GTimeVal {
106
- tv_sec : time . as_secs ( ) as _ ,
107
- tv_usec : time . subsec_micros ( ) as _ ,
109
+ tv_sec : diff . as_secs ( ) as _ ,
110
+ tv_usec : diff . subsec_micros ( ) as _ ,
108
111
} ;
109
112
from_glib ( f (
110
113
self . obj ( )
111
114
. unsafe_cast_ref :: < PixbufAnimationIter > ( )
112
115
. to_glib_none ( )
113
116
. 0 ,
114
- & time as * const _ ,
117
+ & time,
115
118
) )
116
119
}
117
120
}
@@ -158,13 +161,14 @@ unsafe extern "C" fn animation_iter_on_currently_loading_frame<T: PixbufAnimatio
158
161
159
162
unsafe extern "C" fn animation_iter_advance < T : PixbufAnimationIterImpl > (
160
163
ptr : * mut ffi:: GdkPixbufAnimationIter ,
161
- time_ptr : * const glib:: ffi:: GTimeVal ,
164
+ current_time_ptr : * const glib:: ffi:: GTimeVal ,
162
165
) -> glib:: ffi:: gboolean {
163
166
let instance = & * ( ptr as * mut T :: Instance ) ;
164
167
let imp = instance. imp ( ) ;
165
168
166
- let total = Duration :: from_secs ( ( * time_ptr) . tv_sec . try_into ( ) . unwrap ( ) )
167
- + Duration :: from_micros ( ( * time_ptr) . tv_usec . try_into ( ) . unwrap ( ) ) ;
169
+ let current_time = SystemTime :: UNIX_EPOCH
170
+ + Duration :: from_secs ( ( * current_time_ptr) . tv_sec . try_into ( ) . unwrap ( ) )
171
+ + Duration :: from_micros ( ( * current_time_ptr) . tv_usec . try_into ( ) . unwrap ( ) ) ;
168
172
169
- imp. advance ( total ) . into_glib ( )
173
+ imp. advance ( current_time ) . into_glib ( )
170
174
}
0 commit comments