Skip to main content

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::{AnimationState, AnimationTarget, ffi};
7use glib::{
8    object::ObjectType as _,
9    prelude::*,
10    signal::{SignalHandlerId, connect_raw},
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 | Writable
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 | Writable | 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 | Writable | 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
229    /// [enum@Adw.AnimationState.playing].
230    ///
231    /// Sets [`state`][struct@crate::Animation#state] to [enum@Adw.AnimationState.paused].
232    #[doc(alias = "adw_animation_pause")]
233    fn pause(&self) {
234        unsafe {
235            ffi::adw_animation_pause(self.as_ref().to_glib_none().0);
236        }
237    }
238
239    /// Starts the animation for @self.
240    ///
241    /// If the animation is playing, paused or has been completed, restarts it from
242    /// the beginning. This allows to easily play an animation regardless of whether
243    /// it's already playing or not.
244    ///
245    /// Sets [`state`][struct@crate::Animation#state] to [enum@Adw.AnimationState.playing].
246    ///
247    /// The animation will be automatically skipped if [`widget`][struct@crate::Animation#widget] is
248    /// unmapped, or if [`gtk-enable-animations`][struct@crate::gtk::Settings#gtk-enable-animations] is `FALSE`.
249    ///
250    /// As such, it's not guaranteed that the animation will actually run. For
251    /// example, when using `idle_add()` and starting an animation
252    /// immediately afterwards, it's entirely possible that the idle callback will
253    /// run after the animation has already finished, and not while it's playing.
254    #[doc(alias = "adw_animation_play")]
255    fn play(&self) {
256        unsafe {
257            ffi::adw_animation_play(self.as_ref().to_glib_none().0);
258        }
259    }
260
261    /// Resets the animation for @self.
262    ///
263    /// Sets [`state`][struct@crate::Animation#state] to [enum@Adw.AnimationState.idle].
264    #[doc(alias = "adw_animation_reset")]
265    fn reset(&self) {
266        unsafe {
267            ffi::adw_animation_reset(self.as_ref().to_glib_none().0);
268        }
269    }
270
271    /// Resumes a paused animation for @self.
272    ///
273    /// This function must only be used if the animation has been paused with
274    /// [`pause()`][Self::pause()].
275    ///
276    /// Sets [`state`][struct@crate::Animation#state] to [enum@Adw.AnimationState.playing].
277    #[doc(alias = "adw_animation_resume")]
278    fn resume(&self) {
279        unsafe {
280            ffi::adw_animation_resume(self.as_ref().to_glib_none().0);
281        }
282    }
283
284    /// Sets whether to skip @self when animations are globally disabled.
285    ///
286    /// The default behavior is to skip the animation. Set to `FALSE` to disable this
287    /// behavior.
288    ///
289    /// This can be useful for cases where animation is essential, like spinners, or
290    /// in demo applications. Most other animations should keep it enabled.
291    ///
292    /// See [`gtk-enable-animations`][struct@crate::gtk::Settings#gtk-enable-animations].
293    /// ## `setting`
294    /// whether to follow the global setting
295    #[cfg(feature = "v1_3")]
296    #[cfg_attr(docsrs, doc(cfg(feature = "v1_3")))]
297    #[doc(alias = "adw_animation_set_follow_enable_animations_setting")]
298    #[doc(alias = "follow-enable-animations-setting")]
299    fn set_follow_enable_animations_setting(&self, setting: bool) {
300        unsafe {
301            ffi::adw_animation_set_follow_enable_animations_setting(
302                self.as_ref().to_glib_none().0,
303                setting.into_glib(),
304            );
305        }
306    }
307
308    /// Sets the target @self animates to @target.
309    /// ## `target`
310    /// an animation target
311    #[doc(alias = "adw_animation_set_target")]
312    #[doc(alias = "target")]
313    fn set_target(&self, target: &impl IsA<AnimationTarget>) {
314        unsafe {
315            ffi::adw_animation_set_target(
316                self.as_ref().to_glib_none().0,
317                target.as_ref().to_glib_none().0,
318            );
319        }
320    }
321
322    /// Skips the animation for @self.
323    ///
324    /// If the animation hasn't been started yet, is playing, or is paused, instantly
325    /// skips the animation to the end and causes [`done`][struct@crate::Animation#done] to be
326    /// emitted.
327    ///
328    /// Sets [`state`][struct@crate::Animation#state] to [enum@Adw.AnimationState.finished].
329    #[doc(alias = "adw_animation_skip")]
330    fn skip(&self) {
331        unsafe {
332            ffi::adw_animation_skip(self.as_ref().to_glib_none().0);
333        }
334    }
335
336    /// This signal is emitted when the animation has been completed, either on its
337    /// own or via calling [`skip()`][Self::skip()].
338    #[doc(alias = "done")]
339    fn connect_done<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
340        unsafe extern "C" fn done_trampoline<P: IsA<Animation>, F: Fn(&P) + 'static>(
341            this: *mut ffi::AdwAnimation,
342            f: glib::ffi::gpointer,
343        ) {
344            unsafe {
345                let f: &F = &*(f as *const F);
346                f(Animation::from_glib_borrow(this).unsafe_cast_ref())
347            }
348        }
349        unsafe {
350            let f: Box_<F> = Box_::new(f);
351            connect_raw(
352                self.as_ptr() as *mut _,
353                c"done".as_ptr(),
354                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
355                    done_trampoline::<Self, F> as *const (),
356                )),
357                Box_::into_raw(f),
358            )
359        }
360    }
361
362    #[cfg(feature = "v1_3")]
363    #[cfg_attr(docsrs, doc(cfg(feature = "v1_3")))]
364    #[doc(alias = "follow-enable-animations-setting")]
365    fn connect_follow_enable_animations_setting_notify<F: Fn(&Self) + 'static>(
366        &self,
367        f: F,
368    ) -> SignalHandlerId {
369        unsafe extern "C" fn notify_follow_enable_animations_setting_trampoline<
370            P: IsA<Animation>,
371            F: Fn(&P) + 'static,
372        >(
373            this: *mut ffi::AdwAnimation,
374            _param_spec: glib::ffi::gpointer,
375            f: glib::ffi::gpointer,
376        ) {
377            unsafe {
378                let f: &F = &*(f as *const F);
379                f(Animation::from_glib_borrow(this).unsafe_cast_ref())
380            }
381        }
382        unsafe {
383            let f: Box_<F> = Box_::new(f);
384            connect_raw(
385                self.as_ptr() as *mut _,
386                c"notify::follow-enable-animations-setting".as_ptr(),
387                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
388                    notify_follow_enable_animations_setting_trampoline::<Self, F> as *const (),
389                )),
390                Box_::into_raw(f),
391            )
392        }
393    }
394
395    #[doc(alias = "state")]
396    fn connect_state_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
397        unsafe extern "C" fn notify_state_trampoline<P: IsA<Animation>, F: Fn(&P) + 'static>(
398            this: *mut ffi::AdwAnimation,
399            _param_spec: glib::ffi::gpointer,
400            f: glib::ffi::gpointer,
401        ) {
402            unsafe {
403                let f: &F = &*(f as *const F);
404                f(Animation::from_glib_borrow(this).unsafe_cast_ref())
405            }
406        }
407        unsafe {
408            let f: Box_<F> = Box_::new(f);
409            connect_raw(
410                self.as_ptr() as *mut _,
411                c"notify::state".as_ptr(),
412                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
413                    notify_state_trampoline::<Self, F> as *const (),
414                )),
415                Box_::into_raw(f),
416            )
417        }
418    }
419
420    #[doc(alias = "target")]
421    fn connect_target_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
422        unsafe extern "C" fn notify_target_trampoline<P: IsA<Animation>, F: Fn(&P) + 'static>(
423            this: *mut ffi::AdwAnimation,
424            _param_spec: glib::ffi::gpointer,
425            f: glib::ffi::gpointer,
426        ) {
427            unsafe {
428                let f: &F = &*(f as *const F);
429                f(Animation::from_glib_borrow(this).unsafe_cast_ref())
430            }
431        }
432        unsafe {
433            let f: Box_<F> = Box_::new(f);
434            connect_raw(
435                self.as_ptr() as *mut _,
436                c"notify::target".as_ptr(),
437                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
438                    notify_target_trampoline::<Self, F> as *const (),
439                )),
440                Box_::into_raw(f),
441            )
442        }
443    }
444
445    #[doc(alias = "value")]
446    fn connect_value_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
447        unsafe extern "C" fn notify_value_trampoline<P: IsA<Animation>, F: Fn(&P) + 'static>(
448            this: *mut ffi::AdwAnimation,
449            _param_spec: glib::ffi::gpointer,
450            f: glib::ffi::gpointer,
451        ) {
452            unsafe {
453                let f: &F = &*(f as *const F);
454                f(Animation::from_glib_borrow(this).unsafe_cast_ref())
455            }
456        }
457        unsafe {
458            let f: Box_<F> = Box_::new(f);
459            connect_raw(
460                self.as_ptr() as *mut _,
461                c"notify::value".as_ptr(),
462                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
463                    notify_value_trampoline::<Self, F> as *const (),
464                )),
465                Box_::into_raw(f),
466            )
467        }
468    }
469}
470
471impl<O: IsA<Animation>> AnimationExt for O {}