gdk_pixbuf/auto/
pixbuf_simple_anim.rs

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
5use crate::{ffi, Pixbuf, PixbufAnimation};
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    /// An opaque struct representing a simple animation.
15    ///
16    /// ## Properties
17    ///
18    ///
19    /// #### `loop`
20    ///  Whether the animation should loop when it reaches the end.
21    ///
22    /// Readable | Writeable
23    ///
24    /// # Implements
25    ///
26    /// [`PixbufAnimationExt`][trait@crate::prelude::PixbufAnimationExt], [`PixbufAnimationExtManual`][trait@crate::prelude::PixbufAnimationExtManual]
27    #[doc(alias = "GdkPixbufSimpleAnim")]
28    pub struct PixbufSimpleAnim(Object<ffi::GdkPixbufSimpleAnim, ffi::GdkPixbufSimpleAnimClass>) @extends PixbufAnimation;
29
30    match fn {
31        type_ => || ffi::gdk_pixbuf_simple_anim_get_type(),
32    }
33}
34
35impl PixbufSimpleAnim {
36    /// Creates a new, empty animation.
37    /// ## `width`
38    /// the width of the animation
39    /// ## `height`
40    /// the height of the animation
41    /// ## `rate`
42    /// the speed of the animation, in frames per second
43    ///
44    /// # Returns
45    ///
46    /// a newly allocated #GdkPixbufSimpleAnim
47    #[doc(alias = "gdk_pixbuf_simple_anim_new")]
48    pub fn new(width: i32, height: i32, rate: f32) -> PixbufSimpleAnim {
49        unsafe { from_glib_full(ffi::gdk_pixbuf_simple_anim_new(width, height, rate)) }
50    }
51
52    /// Adds a new frame to @self. The @pixbuf must
53    /// have the dimensions specified when the animation
54    /// was constructed.
55    /// ## `pixbuf`
56    /// the pixbuf to add
57    #[doc(alias = "gdk_pixbuf_simple_anim_add_frame")]
58    pub fn add_frame(&self, pixbuf: &Pixbuf) {
59        unsafe {
60            ffi::gdk_pixbuf_simple_anim_add_frame(self.to_glib_none().0, pixbuf.to_glib_none().0);
61        }
62    }
63
64    /// Gets whether @self should loop indefinitely when it reaches the end.
65    ///
66    /// # Returns
67    ///
68    /// [`true`] if the animation loops forever, [`false`] otherwise
69    #[doc(alias = "gdk_pixbuf_simple_anim_get_loop")]
70    #[doc(alias = "get_loop")]
71    #[doc(alias = "loop")]
72    pub fn is_loop(&self) -> bool {
73        unsafe { from_glib(ffi::gdk_pixbuf_simple_anim_get_loop(self.to_glib_none().0)) }
74    }
75
76    /// Sets whether @self should loop indefinitely when it reaches the end.
77    /// ## `loop_`
78    /// whether to loop the animation
79    #[doc(alias = "gdk_pixbuf_simple_anim_set_loop")]
80    #[doc(alias = "loop")]
81    pub fn set_loop(&self, loop_: bool) {
82        unsafe {
83            ffi::gdk_pixbuf_simple_anim_set_loop(self.to_glib_none().0, loop_.into_glib());
84        }
85    }
86
87    #[doc(alias = "loop")]
88    pub fn connect_loop_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
89        unsafe extern "C" fn notify_loop_trampoline<F: Fn(&PixbufSimpleAnim) + 'static>(
90            this: *mut ffi::GdkPixbufSimpleAnim,
91            _param_spec: glib::ffi::gpointer,
92            f: glib::ffi::gpointer,
93        ) {
94            let f: &F = &*(f as *const F);
95            f(&from_glib_borrow(this))
96        }
97        unsafe {
98            let f: Box_<F> = Box_::new(f);
99            connect_raw(
100                self.as_ptr() as *mut _,
101                b"notify::loop\0".as_ptr() as *const _,
102                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
103                    notify_loop_trampoline::<F> as *const (),
104                )),
105                Box_::into_raw(f),
106            )
107        }
108    }
109}