gdk_pixbuf/pixbuf_animation.rs
1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::{ptr, time::SystemTime};
4
5use glib::{prelude::*, translate::*};
6
7use crate::{ffi, PixbufAnimation, PixbufAnimationIter};
8
9mod sealed {
10 pub trait Sealed {}
11 impl<T: super::IsA<super::PixbufAnimation>> Sealed for T {}
12}
13
14pub trait PixbufAnimationExtManual: sealed::Sealed + IsA<PixbufAnimation> + 'static {
15 #[doc(alias = "gdk_pixbuf_animation_get_iter")]
16 #[doc(alias = "get_iter")]
17 fn iter(&self, start_time: Option<SystemTime>) -> PixbufAnimationIter {
18 let start_time = start_time.map(|s| {
19 let diff = s
20 .duration_since(SystemTime::UNIX_EPOCH)
21 .expect("failed to convert time");
22 glib::ffi::GTimeVal {
23 tv_sec: diff.as_secs() as _,
24 tv_usec: diff.subsec_micros() as _,
25 }
26 });
27
28 unsafe {
29 from_glib_full(ffi::gdk_pixbuf_animation_get_iter(
30 self.as_ref().to_glib_none().0,
31 start_time
32 .as_ref()
33 .map(|t| t as *const glib::ffi::GTimeVal)
34 .unwrap_or(ptr::null()),
35 ))
36 }
37 }
38}
39
40impl<O: IsA<PixbufAnimation>> PixbufAnimationExtManual for O {}