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:: { prelude:: * , subclass:: prelude:: * , translate:: * } ;
9
9
use once_cell:: sync:: Lazy ;
@@ -25,16 +25,16 @@ pub trait PixbufAnimationIterImpl: ObjectImpl {
25
25
self . parent_on_currently_loading_frame ( )
26
26
}
27
27
28
- fn advance ( & self , time : Duration ) -> bool {
29
- self . parent_advance ( time )
28
+ fn advance ( & self , current_time : SystemTime ) -> bool {
29
+ self . parent_advance ( current_time )
30
30
}
31
31
}
32
32
33
33
pub trait PixbufAnimationIterImplExt : ObjectSubclass {
34
34
fn parent_delay_time ( & self ) -> Option < Duration > ;
35
35
fn parent_pixbuf ( & self ) -> Pixbuf ;
36
36
fn parent_on_currently_loading_frame ( & self ) -> bool ;
37
- fn parent_advance ( & self , time : Duration ) -> bool ;
37
+ fn parent_advance ( & self , current_time : SystemTime ) -> bool ;
38
38
}
39
39
40
40
impl < T : PixbufAnimationIterImpl > PixbufAnimationIterImplExt for T {
@@ -52,10 +52,10 @@ impl<T: PixbufAnimationIterImpl> PixbufAnimationIterImplExt for T {
52
52
. unsafe_cast_ref :: < PixbufAnimationIter > ( )
53
53
. to_glib_none ( )
54
54
. 0 ) ;
55
- if time == - 1 {
55
+ if time < 0 {
56
56
None
57
57
} else {
58
- Some ( Duration :: from_millis ( time. try_into ( ) . unwrap ( ) ) )
58
+ Some ( Duration :: from_millis ( time as u64 ) )
59
59
}
60
60
}
61
61
}
@@ -94,7 +94,7 @@ impl<T: PixbufAnimationIterImpl> PixbufAnimationIterImplExt for T {
94
94
}
95
95
}
96
96
97
- fn parent_advance ( & self , time : Duration ) -> bool {
97
+ fn parent_advance ( & self , current_time : SystemTime ) -> bool {
98
98
unsafe {
99
99
let data = T :: type_data ( ) ;
100
100
let parent_class =
@@ -103,16 +103,19 @@ impl<T: PixbufAnimationIterImpl> PixbufAnimationIterImplExt for T {
103
103
. advance
104
104
. expect ( "No parent class implementation for \" advance\" " ) ;
105
105
106
+ let diff = current_time
107
+ . duration_since ( SystemTime :: UNIX_EPOCH )
108
+ . expect ( "failed to convert time" ) ;
106
109
let time = glib:: ffi:: GTimeVal {
107
- tv_sec : time . as_secs ( ) as _ ,
108
- tv_usec : time . subsec_micros ( ) as _ ,
110
+ tv_sec : diff . as_secs ( ) as _ ,
111
+ tv_usec : diff . subsec_micros ( ) as _ ,
109
112
} ;
110
113
from_glib ( f (
111
114
self . obj ( )
112
115
. unsafe_cast_ref :: < PixbufAnimationIter > ( )
113
116
. to_glib_none ( )
114
117
. 0 ,
115
- & time as * const _ ,
118
+ & time,
116
119
) )
117
120
}
118
121
}
@@ -165,13 +168,14 @@ unsafe extern "C" fn animation_iter_on_currently_loading_frame<T: PixbufAnimatio
165
168
166
169
unsafe extern "C" fn animation_iter_advance < T : PixbufAnimationIterImpl > (
167
170
ptr : * mut ffi:: GdkPixbufAnimationIter ,
168
- time_ptr : * const glib:: ffi:: GTimeVal ,
171
+ current_time_ptr : * const glib:: ffi:: GTimeVal ,
169
172
) -> glib:: ffi:: gboolean {
170
173
let instance = & * ( ptr as * mut T :: Instance ) ;
171
174
let imp = instance. imp ( ) ;
172
175
173
- let total = Duration :: from_secs ( ( * time_ptr) . tv_sec . try_into ( ) . unwrap ( ) )
174
- + Duration :: from_micros ( ( * time_ptr) . tv_usec . try_into ( ) . unwrap ( ) ) ;
176
+ let current_time = SystemTime :: UNIX_EPOCH
177
+ + Duration :: from_secs ( ( * current_time_ptr) . tv_sec . try_into ( ) . unwrap ( ) )
178
+ + Duration :: from_micros ( ( * current_time_ptr) . tv_usec . try_into ( ) . unwrap ( ) ) ;
175
179
176
- imp. advance ( total ) . into_glib ( )
180
+ imp. advance ( current_time ) . into_glib ( )
177
181
}
0 commit comments