libadwaita/auto/
animation.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from
3// from gir-files (https://github.com/gtk-rs/gir-files.git)
4// DO NOT EDIT
5
6use crate::{ffi, AnimationState, AnimationTarget};
7use glib::{
8    object::ObjectType as _,
9    prelude::*,
10    signal::{connect_raw, SignalHandlerId},
11    translate::*,
12};
13use std::boxed::Box as Box_;
14
15glib::wrapper! {
16    /// A base class for animations.
17    ///
18    /// [`Animation`][crate::Animation] represents an animation on a widget. It has a target that
19    /// provides a value to animate, and a state indicating whether the
20    /// animation hasn't been started yet, is playing, paused or finished.
21    ///
22    /// Currently there are two concrete animation types:
23    /// [`TimedAnimation`][crate::TimedAnimation] and [`SpringAnimation`][crate::SpringAnimation].
24    ///
25    /// [`Animation`][crate::Animation] will automatically skip the animation if
26    /// [`widget`][struct@crate::Animation#widget] is unmapped, or if
27    /// [`gtk-enable-animations`][struct@crate::gtk::Settings#gtk-enable-animations] is `FALSE`.
28    ///
29    /// The [`done`][struct@crate::Animation#done] signal can be used to perform an action after
30    /// the animation ends, for example hiding a widget after animating its
31    /// [`opacity`][struct@crate::gtk::Widget#opacity] to 0.
32    ///
33    /// [`Animation`][crate::Animation] will be kept alive while the animation is playing. As such,
34    /// it's safe to create an animation, start it and immediately unref it:
35    /// A fire-and-forget animation:
36    ///
37    /// **⚠️ The following code is in c ⚠️**
38    ///
39    /// ```c
40    /// static void
41    /// animation_cb (double    value,
42    ///               MyObject *self)
43    /// {
44    ///   // Do something with @value
45    /// }
46    ///
47    /// static void
48    /// my_object_animate (MyObject *self)
49    /// {
50    ///   AdwAnimationTarget *target =
51    ///     adw_callback_animation_target_new ((AdwAnimationTargetFunc) animation_cb,
52    ///                                        self, NULL);
53    ///   g_autoptr (AdwAnimation) animation =
54    ///     adw_timed_animation_new (widget, 0, 1, 250, target);
55    ///
56    ///   adw_animation_play (animation);
57    /// }
58    /// ```
59    ///
60    /// If there's a chance the previous animation for the same target hasn't yet
61    /// finished, the previous animation should be stopped first, or the existing
62    /// [`Animation`][crate::Animation] object can be reused.
63    ///
64    /// This is an Abstract Base Class, you cannot instantiate it.
65    ///
66    /// ## Properties
67    ///
68    ///
69    /// #### `follow-enable-animations-setting`
70    ///  Whether to skip the animation when animations are globally disabled.
71    ///
72    /// The default behavior is to skip the animation. Set to `FALSE` to disable
73    /// this behavior.
74    ///
75    /// This can be useful for cases where animation is essential, like spinners,
76    /// or in demo applications. Most other animations should keep it enabled.
77    ///
78    /// See [`gtk-enable-animations`][struct@crate::gtk::Settings#gtk-enable-animations].
79    ///
80    /// Readable | Writeable
81    ///
82    ///
83    /// #### `state`
84    ///  The animation state.
85    ///
86    /// The state indicates whether the animation is currently playing, paused,
87    /// finished or hasn't been started yet.
88    ///
89    /// Readable
90    ///
91    ///
92    /// #### `target`
93    ///  The target to animate.
94    ///
95    /// Readable | Writeable | Construct
96    ///
97    ///
98    /// #### `value`
99    ///  The current value of the animation.
100    ///
101    /// Readable
102    ///
103    ///
104    /// #### `widget`
105    ///  The animation widget.
106    ///
107    /// It provides the frame clock for the animation. It's not strictly necessary
108    /// for this widget to be same as the one being animated.
109    ///
110    /// The widget must be mapped in order for the animation to work. If it's not
111    /// mapped, or if it gets unmapped during an ongoing animation, the animation
112    /// will be automatically skipped.
113    ///
114    /// Readable | Writeable | Construct Only
115    ///
116    /// ## Signals
117    ///
118    ///
119    /// #### `done`
120    ///  This signal is emitted when the animation has been completed, either on its
121    /// own or via calling [`AnimationExt::skip()`][crate::prelude::AnimationExt::skip()].
122    ///
123    ///
124    ///
125    /// # Implements
126    ///
127    /// [`AnimationExt`][trait@crate::prelude::AnimationExt], [`trait@glib::ObjectExt`]
128    #[doc(alias = "AdwAnimation")]
129    pub struct Animation(Object<ffi::AdwAnimation, ffi::AdwAnimationClass>);
130
131    match fn {
132        type_ => || ffi::adw_animation_get_type(),
133    }
134}
135
136impl Animation {
137    pub const NONE: Option<&'static Animation> = None;
138}
139
140/// Trait containing all [`struct@Animation`] methods.
141///
142/// # Implementors
143///
144/// [`Animation`][struct@crate::Animation], [`SpringAnimation`][struct@crate::SpringAnimation], [`TimedAnimation`][struct@crate::TimedAnimation]
145pub trait AnimationExt: IsA<Animation> + 'static {
146    /// Gets whether @self should be skipped when animations are globally disabled.
147    ///
148    /// # Returns
149    ///
150    /// whether to follow the global setting
151    #[cfg(feature = "v1_3")]
152    #[cfg_attr(docsrs, doc(cfg(feature = "v1_3")))]
153    #[doc(alias = "adw_animation_get_follow_enable_animations_setting")]
154    #[doc(alias = "get_follow_enable_animations_setting")]
155    #[doc(alias = "follow-enable-animations-setting")]
156    fn follows_enable_animations_setting(&self) -> bool {
157        unsafe {
158            from_glib(ffi::adw_animation_get_follow_enable_animations_setting(
159                self.as_ref().to_glib_none().0,
160            ))
161        }
162    }
163
164    /// Gets the current value of @self.
165    ///
166    /// The state indicates whether @self is currently playing, paused, finished or
167    /// hasn't been started yet.
168    ///
169    /// # Returns
170    ///
171    /// the animation value
172    #[doc(alias = "adw_animation_get_state")]
173    #[doc(alias = "get_state")]
174    fn state(&self) -> AnimationState {
175        unsafe { from_glib(ffi::adw_animation_get_state(self.as_ref().to_glib_none().0)) }
176    }
177
178    /// Gets the target @self animates.
179    ///
180    /// # Returns
181    ///
182    /// the animation target
183    #[doc(alias = "adw_animation_get_target")]
184    #[doc(alias = "get_target")]
185    fn target(&self) -> AnimationTarget {
186        unsafe {
187            from_glib_none(ffi::adw_animation_get_target(
188                self.as_ref().to_glib_none().0,
189            ))
190        }
191    }
192
193    /// Gets the current value of @self.
194    ///
195    /// # Returns
196    ///
197    /// the current value
198    #[doc(alias = "adw_animation_get_value")]
199    #[doc(alias = "get_value")]
200    fn value(&self) -> f64 {
201        unsafe { ffi::adw_animation_get_value(self.as_ref().to_glib_none().0) }
202    }
203
204    /// Gets the widget @self was created for.
205    ///
206    /// It provides the frame clock for the animation. It's not strictly necessary
207    /// for this widget to be same as the one being animated.
208    ///
209    /// The widget must be mapped in order for the animation to work. If it's not
210    /// mapped, or if it gets unmapped during an ongoing animation, the animation
211    /// will be automatically skipped.
212    ///
213    /// # Returns
214    ///
215    /// the animation widget
216    #[doc(alias = "adw_animation_get_widget")]
217    #[doc(alias = "get_widget")]
218    fn widget(&self) -> gtk::Widget {
219        unsafe {
220            from_glib_none(ffi::adw_animation_get_widget(
221                self.as_ref().to_glib_none().0,
222            ))
223        }
224    }
225
226    /// Pauses a playing animation for @self.
227    ///
228    /// Does nothing if the current state of @self isn't `ADW_ANIMATION_PLAYING`.
229    ///
230    /// Sets [`state`][struct@crate::Animation#state] to `ADW_ANIMATION_PAUSED`.
231    #[doc(alias = "adw_animation_pause")]
232    fn pause(&self) {
233        unsafe {
234            ffi::adw_animation_pause(self.as_ref().to_glib_none().0);
235        }
236    }
237
238    /// Starts the animation for @self.
239    ///
240    /// If the animation is playing, paused or has been completed, restarts it from
241    /// the beginning. This allows to easily play an animation regardless of whether
242    /// it's already playing or not.
243    ///
244    /// Sets [`state`][struct@crate::Animation#state] to `ADW_ANIMATION_PLAYING`.
245    ///
246    /// The animation will be automatically skipped if [`widget`][struct@crate::Animation#widget] is
247    /// unmapped, or if [`gtk-enable-animations`][struct@crate::gtk::Settings#gtk-enable-animations] is `FALSE`.
248    ///
249    /// As such, it's not guaranteed that the animation will actually run. For
250    /// example, when using `idle_add()` and starting an animation
251    /// immediately afterwards, it's entirely possible that the idle callback will
252    /// run after the animation has already finished, and not while it's playing.
253    #[doc(alias = "adw_animation_play")]
254    fn play(&self) {
255        unsafe {
256            ffi::adw_animation_play(self.as_ref().to_glib_none().0);
257        }
258    }
259
260    /// Resets the animation for @self.
261    ///
262    /// Sets [`state`][struct@crate::Animation#state] to `ADW_ANIMATION_IDLE`.
263    #[doc(alias = "adw_animation_reset")]
264    fn reset(&self) {
265        unsafe {
266            ffi::adw_animation_reset(self.as_ref().to_glib_none().0);
267        }
268    }
269
270    /// Resumes a paused animation for @self.
271    ///
272    /// This function must only be used if the animation has been paused with
273    /// [`pause()`][Self::pause()].
274    ///
275    /// Sets [`state`][struct@crate::Animation#state] to `ADW_ANIMATION_PLAYING`.
276    #[doc(alias = "adw_animation_resume")]
277    fn resume(&self) {
278        unsafe {
279            ffi::adw_animation_resume(self.as_ref().to_glib_none().0);
280        }
281    }
282
283    /// Sets whether to skip @self when animations are globally disabled.
284    ///
285    /// The default behavior is to skip the animation. Set to `FALSE` to disable this
286    /// behavior.
287    ///
288    /// This can be useful for cases where animation is essential, like spinners, or
289    /// in demo applications. Most other animations should keep it enabled.
290    ///
291    /// See [`gtk-enable-animations`][struct@crate::gtk::Settings#gtk-enable-animations].
292    /// ## `setting`
293    /// whether to follow the global setting
294    #[cfg(feature = "v1_3")]
295    #[cfg_attr(docsrs, doc(cfg(feature = "v1_3")))]
296    #[doc(alias = "adw_animation_set_follow_enable_animations_setting")]
297    #[doc(alias = "follow-enable-animations-setting")]
298    fn set_follow_enable_animations_setting(&self, setting: bool) {
299        unsafe {
300            ffi::adw_animation_set_follow_enable_animations_setting(
301                self.as_ref().to_glib_none().0,
302                setting.into_glib(),
303            );
304        }
305    }
306
307    /// Sets the target @self animates to @target.
308    /// ## `target`
309    /// an animation target
310    #[doc(alias = "adw_animation_set_target")]
311    #[doc(alias = "target")]
312    fn set_target(&self, target: &impl IsA<AnimationTarget>) {
313        unsafe {
314            ffi::adw_animation_set_target(
315                self.as_ref().to_glib_none().0,
316                target.as_ref().to_glib_none().0,
317            );
318        }
319    }
320
321    /// Skips the animation for @self.
322    ///
323    /// If the animation hasn't been started yet, is playing, or is paused, instantly
324    /// skips the animation to the end and causes [`done`][struct@crate::Animation#done] to be
325    /// emitted.
326    ///
327    /// Sets [`state`][struct@crate::Animation#state] to `ADW_ANIMATION_FINISHED`.
328    #[doc(alias = "adw_animation_skip")]
329    fn skip(&self) {
330        unsafe {
331            ffi::adw_animation_skip(self.as_ref().to_glib_none().0);
332        }
333    }
334
335    /// This signal is emitted when the animation has been completed, either on its
336    /// own or via calling [`skip()`][Self::skip()].
337    #[doc(alias = "done")]
338    fn connect_done<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
339        unsafe extern "C" fn done_trampoline<P: IsA<Animation>, F: Fn(&P) + 'static>(
340            this: *mut ffi::AdwAnimation,
341            f: glib::ffi::gpointer,
342        ) {
343            let f: &F = &*(f as *const F);
344            f(Animation::from_glib_borrow(this).unsafe_cast_ref())
345        }
346        unsafe {
347            let f: Box_<F> = Box_::new(f);
348            connect_raw(
349                self.as_ptr() as *mut _,
350                c"done".as_ptr() as *const _,
351                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
352                    done_trampoline::<Self, F> as *const (),
353                )),
354                Box_::into_raw(f),
355            )
356        }
357    }
358
359    #[cfg(feature = "v1_3")]
360    #[cfg_attr(docsrs, doc(cfg(feature = "v1_3")))]
361    #[doc(alias = "follow-enable-animations-setting")]
362    fn connect_follow_enable_animations_setting_notify<F: Fn(&Self) + 'static>(
363        &self,
364        f: F,
365    ) -> SignalHandlerId {
366        unsafe extern "C" fn notify_follow_enable_animations_setting_trampoline<
367            P: IsA<Animation>,
368            F: Fn(&P) + 'static,
369        >(
370            this: *mut ffi::AdwAnimation,
371            _param_spec: glib::ffi::gpointer,
372            f: glib::ffi::gpointer,
373        ) {
374            let f: &F = &*(f as *const F);
375            f(Animation::from_glib_borrow(this).unsafe_cast_ref())
376        }
377        unsafe {
378            let f: Box_<F> = Box_::new(f);
379            connect_raw(
380                self.as_ptr() as *mut _,
381                c"notify::follow-enable-animations-setting".as_ptr() as *const _,
382                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
383                    notify_follow_enable_animations_setting_trampoline::<Self, F> as *const (),
384                )),
385                Box_::into_raw(f),
386            )
387        }
388    }
389
390    #[doc(alias = "state")]
391    fn connect_state_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
392        unsafe extern "C" fn notify_state_trampoline<P: IsA<Animation>, F: Fn(&P) + 'static>(
393            this: *mut ffi::AdwAnimation,
394            _param_spec: glib::ffi::gpointer,
395            f: glib::ffi::gpointer,
396        ) {
397            let f: &F = &*(f as *const F);
398            f(Animation::from_glib_borrow(this).unsafe_cast_ref())
399        }
400        unsafe {
401            let f: Box_<F> = Box_::new(f);
402            connect_raw(
403                self.as_ptr() as *mut _,
404                c"notify::state".as_ptr() as *const _,
405                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
406                    notify_state_trampoline::<Self, F> as *const (),
407                )),
408                Box_::into_raw(f),
409            )
410        }
411    }
412
413    #[doc(alias = "target")]
414    fn connect_target_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
415        unsafe extern "C" fn notify_target_trampoline<P: IsA<Animation>, F: Fn(&P) + 'static>(
416            this: *mut ffi::AdwAnimation,
417            _param_spec: glib::ffi::gpointer,
418            f: glib::ffi::gpointer,
419        ) {
420            let f: &F = &*(f as *const F);
421            f(Animation::from_glib_borrow(this).unsafe_cast_ref())
422        }
423        unsafe {
424            let f: Box_<F> = Box_::new(f);
425            connect_raw(
426                self.as_ptr() as *mut _,
427                c"notify::target".as_ptr() as *const _,
428                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
429                    notify_target_trampoline::<Self, F> as *const (),
430                )),
431                Box_::into_raw(f),
432            )
433        }
434    }
435
436    #[doc(alias = "value")]
437    fn connect_value_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
438        unsafe extern "C" fn notify_value_trampoline<P: IsA<Animation>, F: Fn(&P) + 'static>(
439            this: *mut ffi::AdwAnimation,
440            _param_spec: glib::ffi::gpointer,
441            f: glib::ffi::gpointer,
442        ) {
443            let f: &F = &*(f as *const F);
444            f(Animation::from_glib_borrow(this).unsafe_cast_ref())
445        }
446        unsafe {
447            let f: Box_<F> = Box_::new(f);
448            connect_raw(
449                self.as_ptr() as *mut _,
450                c"notify::value".as_ptr() as *const _,
451                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
452                    notify_value_trampoline::<Self, F> as *const (),
453                )),
454                Box_::into_raw(f),
455            )
456        }
457    }
458}
459
460impl<O: IsA<Animation>> AnimationExt for O {}