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
9pub trait PixbufAnimationExtManual: IsA<PixbufAnimation> + 'static {
10 #[doc(alias = "gdk_pixbuf_animation_get_iter")]
11 #[doc(alias = "get_iter")]
12 fn iter(&self, start_time: Option<SystemTime>) -> PixbufAnimationIter {
13 let start_time = start_time.map(|s| {
14 let diff = s
15 .duration_since(SystemTime::UNIX_EPOCH)
16 .expect("failed to convert time");
17 glib::ffi::GTimeVal {
18 tv_sec: diff.as_secs() as _,
19 tv_usec: diff.subsec_micros() as _,
20 }
21 });
22
23 unsafe {
24 from_glib_full(ffi::gdk_pixbuf_animation_get_iter(
25 self.as_ref().to_glib_none().0,
26 start_time
27 .as_ref()
28 .map(|t| t as *const glib::ffi::GTimeVal)
29 .unwrap_or(ptr::null()),
30 ))
31 }
32 }
33}
34
35impl<O: IsA<PixbufAnimation>> PixbufAnimationExtManual for O {}