gdk_pixbuf/
pixbuf_animation_iter.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::time::{Duration, SystemTime};
4
5use glib::translate::*;
6
7use super::{ffi, Pixbuf};
8
9glib::wrapper! {
10    #[doc(alias = "GdkPixbufAnimationIter")]
11    pub struct PixbufAnimationIter(Object<ffi::GdkPixbufAnimationIter, ffi::GdkPixbufAnimationIterClass>);
12
13    match fn {
14        type_ => || ffi::gdk_pixbuf_animation_iter_get_type(),
15    }
16}
17
18impl PixbufAnimationIter {
19    #[doc(alias = "gdk_pixbuf_animation_iter_advance")]
20    pub fn advance(&self, current_time: SystemTime) -> bool {
21        let diff = current_time
22            .duration_since(SystemTime::UNIX_EPOCH)
23            .expect("failed to convert time");
24
25        unsafe {
26            from_glib(ffi::gdk_pixbuf_animation_iter_advance(
27                self.to_glib_none().0,
28                &glib::ffi::GTimeVal {
29                    tv_sec: diff.as_secs() as _,
30                    tv_usec: diff.subsec_micros() as _,
31                },
32            ))
33        }
34    }
35
36    #[doc(alias = "gdk_pixbuf_animation_iter_get_pixbuf")]
37    #[doc(alias = "get_pixbuf")]
38    pub fn pixbuf(&self) -> Pixbuf {
39        unsafe {
40            from_glib_none(ffi::gdk_pixbuf_animation_iter_get_pixbuf(
41                self.to_glib_none().0,
42            ))
43        }
44    }
45
46    #[doc(alias = "gdk_pixbuf_animation_iter_get_delay_time")]
47    #[doc(alias = "get_delay_time")]
48    pub fn delay_time(&self) -> Option<Duration> {
49        unsafe {
50            let res = ffi::gdk_pixbuf_animation_iter_get_delay_time(self.to_glib_none().0);
51
52            if res < 0 {
53                None
54            } else {
55                Some(Duration::from_millis(res as u64))
56            }
57        }
58    }
59
60    #[doc(alias = "gdk_pixbuf_animation_iter_on_currently_loading_frame")]
61    pub fn on_currently_loading_frame(&self) -> bool {
62        unsafe {
63            from_glib(ffi::gdk_pixbuf_animation_iter_on_currently_loading_frame(
64                self.to_glib_none().0,
65            ))
66        }
67    }
68}