1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Take a look at the license at the top of the repository in the LICENSE file.

use std::{ptr, time::SystemTime};

use glib::{object::IsA, translate::*};

use crate::{PixbufAnimation, PixbufAnimationIter};

mod sealed {
    pub trait Sealed {}
    impl<T: super::IsA<super::PixbufAnimation>> Sealed for T {}
}

pub trait PixbufAnimationExtManual: sealed::Sealed + IsA<PixbufAnimation> + 'static {
    #[doc(alias = "gdk_pixbuf_animation_get_iter")]
    #[doc(alias = "get_iter")]
    fn iter(&self, start_time: Option<SystemTime>) -> PixbufAnimationIter {
        let start_time = start_time.map(|s| {
            let diff = s
                .duration_since(SystemTime::UNIX_EPOCH)
                .expect("failed to convert time");
            glib::ffi::GTimeVal {
                tv_sec: diff.as_secs() as _,
                tv_usec: diff.subsec_micros() as _,
            }
        });

        unsafe {
            from_glib_full(ffi::gdk_pixbuf_animation_get_iter(
                self.as_ref().to_glib_none().0,
                start_time
                    .as_ref()
                    .map(|t| t as *const glib::ffi::GTimeVal)
                    .unwrap_or(ptr::null()),
            ))
        }
    }
}

impl<O: IsA<PixbufAnimation>> PixbufAnimationExtManual for O {}