1 // This file was generated by gir (https://github.com/gtk-rs/gir)
2 // from gir-files (https://github.com/gtk-rs/gir-files)
3 // DO NOT EDIT
4 
5 use crate::Pixbuf;
6 use glib::object::IsA;
7 use glib::translate::*;
8 use std::boxed::Box as Box_;
9 use std::fmt;
10 use std::pin::Pin;
11 use std::ptr;
12 
13 glib::wrapper! {
14     #[doc(alias = "GdkPixbufAnimation")]
15     pub struct PixbufAnimation(Object<ffi::GdkPixbufAnimation, ffi::GdkPixbufAnimationClass>);
16 
17     match fn {
18         type_ => || ffi::gdk_pixbuf_animation_get_type(),
19     }
20 }
21 
22 impl PixbufAnimation {
23     #[doc(alias = "gdk_pixbuf_animation_new_from_file")]
24     #[doc(alias = "new_from_file")]
from_file<P: AsRef<std::path::Path>>( filename: P, ) -> Result<PixbufAnimation, glib::Error>25     pub fn from_file<P: AsRef<std::path::Path>>(
26         filename: P,
27     ) -> Result<PixbufAnimation, glib::Error> {
28         unsafe {
29             let mut error = ptr::null_mut();
30             let ret = ffi::gdk_pixbuf_animation_new_from_file(
31                 filename.as_ref().to_glib_none().0,
32                 &mut error,
33             );
34             if error.is_null() {
35                 Ok(from_glib_full(ret))
36             } else {
37                 Err(from_glib_full(error))
38             }
39         }
40     }
41 
42     #[doc(alias = "gdk_pixbuf_animation_new_from_resource")]
43     #[doc(alias = "new_from_resource")]
from_resource(resource_path: &str) -> Result<PixbufAnimation, glib::Error>44     pub fn from_resource(resource_path: &str) -> Result<PixbufAnimation, glib::Error> {
45         unsafe {
46             let mut error = ptr::null_mut();
47             let ret = ffi::gdk_pixbuf_animation_new_from_resource(
48                 resource_path.to_glib_none().0,
49                 &mut error,
50             );
51             if error.is_null() {
52                 Ok(from_glib_full(ret))
53             } else {
54                 Err(from_glib_full(error))
55             }
56         }
57     }
58 
59     #[doc(alias = "gdk_pixbuf_animation_new_from_stream")]
60     #[doc(alias = "new_from_stream")]
from_stream<P: IsA<gio::InputStream>, Q: IsA<gio::Cancellable>>( stream: &P, cancellable: Option<&Q>, ) -> Result<PixbufAnimation, glib::Error>61     pub fn from_stream<P: IsA<gio::InputStream>, Q: IsA<gio::Cancellable>>(
62         stream: &P,
63         cancellable: Option<&Q>,
64     ) -> Result<PixbufAnimation, glib::Error> {
65         unsafe {
66             let mut error = ptr::null_mut();
67             let ret = ffi::gdk_pixbuf_animation_new_from_stream(
68                 stream.as_ref().to_glib_none().0,
69                 cancellable.map(|p| p.as_ref()).to_glib_none().0,
70                 &mut error,
71             );
72             if error.is_null() {
73                 Ok(from_glib_full(ret))
74             } else {
75                 Err(from_glib_full(error))
76             }
77         }
78     }
79 
80     #[doc(alias = "gdk_pixbuf_animation_new_from_stream_async")]
81     #[doc(alias = "new_from_stream_async")]
from_stream_async< P: IsA<gio::InputStream>, Q: IsA<gio::Cancellable>, R: FnOnce(Result<PixbufAnimation, glib::Error>) + Send + 'static, >( stream: &P, cancellable: Option<&Q>, callback: R, )82     pub fn from_stream_async<
83         P: IsA<gio::InputStream>,
84         Q: IsA<gio::Cancellable>,
85         R: FnOnce(Result<PixbufAnimation, glib::Error>) + Send + 'static,
86     >(
87         stream: &P,
88         cancellable: Option<&Q>,
89         callback: R,
90     ) {
91         let user_data: Box_<R> = Box_::new(callback);
92         unsafe extern "C" fn from_stream_async_trampoline<
93             R: FnOnce(Result<PixbufAnimation, glib::Error>) + Send + 'static,
94         >(
95             _source_object: *mut glib::gobject_ffi::GObject,
96             res: *mut gio::ffi::GAsyncResult,
97             user_data: glib::ffi::gpointer,
98         ) {
99             let mut error = ptr::null_mut();
100             let ret = ffi::gdk_pixbuf_animation_new_from_stream_finish(res, &mut error);
101             let result = if error.is_null() {
102                 Ok(from_glib_full(ret))
103             } else {
104                 Err(from_glib_full(error))
105             };
106             let callback: Box_<R> = Box_::from_raw(user_data as *mut _);
107             callback(result);
108         }
109         let callback = from_stream_async_trampoline::<R>;
110         unsafe {
111             ffi::gdk_pixbuf_animation_new_from_stream_async(
112                 stream.as_ref().to_glib_none().0,
113                 cancellable.map(|p| p.as_ref()).to_glib_none().0,
114                 Some(callback),
115                 Box_::into_raw(user_data) as *mut _,
116             );
117         }
118     }
119 
from_stream_async_future<P: IsA<gio::InputStream> + Clone + 'static>( stream: &P, ) -> Pin<Box_<dyn std::future::Future<Output = Result<PixbufAnimation, glib::Error>> + 'static>>120     pub fn from_stream_async_future<P: IsA<gio::InputStream> + Clone + 'static>(
121         stream: &P,
122     ) -> Pin<Box_<dyn std::future::Future<Output = Result<PixbufAnimation, glib::Error>> + 'static>>
123     {
124         let stream = stream.clone();
125         Box_::pin(gio::GioFuture::new(&(), move |_obj, cancellable, send| {
126             Self::from_stream_async(&stream, Some(cancellable), move |res| {
127                 send.resolve(res);
128             });
129         }))
130     }
131 }
132 
133 pub const NONE_PIXBUF_ANIMATION: Option<&PixbufAnimation> = None;
134 
135 pub trait PixbufAnimationExt: 'static {
136     #[doc(alias = "gdk_pixbuf_animation_get_height")]
137     #[doc(alias = "get_height")]
height(&self) -> i32138     fn height(&self) -> i32;
139 
140     #[doc(alias = "gdk_pixbuf_animation_get_static_image")]
141     #[doc(alias = "get_static_image")]
static_image(&self) -> Option<Pixbuf>142     fn static_image(&self) -> Option<Pixbuf>;
143 
144     #[doc(alias = "gdk_pixbuf_animation_get_width")]
145     #[doc(alias = "get_width")]
width(&self) -> i32146     fn width(&self) -> i32;
147 
148     #[doc(alias = "gdk_pixbuf_animation_is_static_image")]
is_static_image(&self) -> bool149     fn is_static_image(&self) -> bool;
150 }
151 
152 impl<O: IsA<PixbufAnimation>> PixbufAnimationExt for O {
height(&self) -> i32153     fn height(&self) -> i32 {
154         unsafe { ffi::gdk_pixbuf_animation_get_height(self.as_ref().to_glib_none().0) }
155     }
156 
static_image(&self) -> Option<Pixbuf>157     fn static_image(&self) -> Option<Pixbuf> {
158         unsafe {
159             from_glib_none(ffi::gdk_pixbuf_animation_get_static_image(
160                 self.as_ref().to_glib_none().0,
161             ))
162         }
163     }
164 
width(&self) -> i32165     fn width(&self) -> i32 {
166         unsafe { ffi::gdk_pixbuf_animation_get_width(self.as_ref().to_glib_none().0) }
167     }
168 
is_static_image(&self) -> bool169     fn is_static_image(&self) -> bool {
170         unsafe {
171             from_glib(ffi::gdk_pixbuf_animation_is_static_image(
172                 self.as_ref().to_glib_none().0,
173             ))
174         }
175     }
176 }
177 
178 impl fmt::Display for PixbufAnimation {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result179     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
180         f.write_str("PixbufAnimation")
181     }
182 }
183