libadwaita/auto/
timed_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, Animation, AnimationTarget, Easing};
7use glib::{
8    prelude::*,
9    signal::{connect_raw, SignalHandlerId},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    #[doc(alias = "AdwTimedAnimation")]
16    pub struct TimedAnimation(Object<ffi::AdwTimedAnimation, ffi::AdwTimedAnimationClass>) @extends Animation;
17
18    match fn {
19        type_ => || ffi::adw_timed_animation_get_type(),
20    }
21}
22
23impl TimedAnimation {
24    #[doc(alias = "adw_timed_animation_new")]
25    pub fn new(
26        widget: &impl IsA<gtk::Widget>,
27        from: f64,
28        to: f64,
29        duration: u32,
30        target: impl IsA<AnimationTarget>,
31    ) -> TimedAnimation {
32        skip_assert_initialized!();
33        unsafe {
34            Animation::from_glib_none(ffi::adw_timed_animation_new(
35                widget.as_ref().to_glib_none().0,
36                from,
37                to,
38                duration,
39                target.upcast().into_glib_ptr(),
40            ))
41            .unsafe_cast()
42        }
43    }
44
45    // rustdoc-stripper-ignore-next
46    /// Creates a new builder-pattern struct instance to construct [`TimedAnimation`] objects.
47    ///
48    /// This method returns an instance of [`TimedAnimationBuilder`](crate::builders::TimedAnimationBuilder) which can be used to create [`TimedAnimation`] objects.
49    pub fn builder() -> TimedAnimationBuilder {
50        TimedAnimationBuilder::new()
51    }
52
53    #[doc(alias = "adw_timed_animation_get_alternate")]
54    #[doc(alias = "get_alternate")]
55    #[doc(alias = "alternate")]
56    pub fn is_alternate(&self) -> bool {
57        unsafe {
58            from_glib(ffi::adw_timed_animation_get_alternate(
59                self.to_glib_none().0,
60            ))
61        }
62    }
63
64    #[doc(alias = "adw_timed_animation_get_duration")]
65    #[doc(alias = "get_duration")]
66    pub fn duration(&self) -> u32 {
67        unsafe { ffi::adw_timed_animation_get_duration(self.to_glib_none().0) }
68    }
69
70    #[doc(alias = "adw_timed_animation_get_easing")]
71    #[doc(alias = "get_easing")]
72    pub fn easing(&self) -> Easing {
73        unsafe { from_glib(ffi::adw_timed_animation_get_easing(self.to_glib_none().0)) }
74    }
75
76    #[doc(alias = "adw_timed_animation_get_repeat_count")]
77    #[doc(alias = "get_repeat_count")]
78    #[doc(alias = "repeat-count")]
79    pub fn repeat_count(&self) -> u32 {
80        unsafe { ffi::adw_timed_animation_get_repeat_count(self.to_glib_none().0) }
81    }
82
83    #[doc(alias = "adw_timed_animation_get_reverse")]
84    #[doc(alias = "get_reverse")]
85    #[doc(alias = "reverse")]
86    pub fn is_reverse(&self) -> bool {
87        unsafe { from_glib(ffi::adw_timed_animation_get_reverse(self.to_glib_none().0)) }
88    }
89
90    #[doc(alias = "adw_timed_animation_get_value_from")]
91    #[doc(alias = "get_value_from")]
92    #[doc(alias = "value-from")]
93    pub fn value_from(&self) -> f64 {
94        unsafe { ffi::adw_timed_animation_get_value_from(self.to_glib_none().0) }
95    }
96
97    #[doc(alias = "adw_timed_animation_get_value_to")]
98    #[doc(alias = "get_value_to")]
99    #[doc(alias = "value-to")]
100    pub fn value_to(&self) -> f64 {
101        unsafe { ffi::adw_timed_animation_get_value_to(self.to_glib_none().0) }
102    }
103
104    #[doc(alias = "adw_timed_animation_set_alternate")]
105    #[doc(alias = "alternate")]
106    pub fn set_alternate(&self, alternate: bool) {
107        unsafe {
108            ffi::adw_timed_animation_set_alternate(self.to_glib_none().0, alternate.into_glib());
109        }
110    }
111
112    #[doc(alias = "adw_timed_animation_set_duration")]
113    #[doc(alias = "duration")]
114    pub fn set_duration(&self, duration: u32) {
115        unsafe {
116            ffi::adw_timed_animation_set_duration(self.to_glib_none().0, duration);
117        }
118    }
119
120    #[doc(alias = "adw_timed_animation_set_easing")]
121    #[doc(alias = "easing")]
122    pub fn set_easing(&self, easing: Easing) {
123        unsafe {
124            ffi::adw_timed_animation_set_easing(self.to_glib_none().0, easing.into_glib());
125        }
126    }
127
128    #[doc(alias = "adw_timed_animation_set_repeat_count")]
129    #[doc(alias = "repeat-count")]
130    pub fn set_repeat_count(&self, repeat_count: u32) {
131        unsafe {
132            ffi::adw_timed_animation_set_repeat_count(self.to_glib_none().0, repeat_count);
133        }
134    }
135
136    #[doc(alias = "adw_timed_animation_set_reverse")]
137    #[doc(alias = "reverse")]
138    pub fn set_reverse(&self, reverse: bool) {
139        unsafe {
140            ffi::adw_timed_animation_set_reverse(self.to_glib_none().0, reverse.into_glib());
141        }
142    }
143
144    #[doc(alias = "adw_timed_animation_set_value_from")]
145    #[doc(alias = "value-from")]
146    pub fn set_value_from(&self, value: f64) {
147        unsafe {
148            ffi::adw_timed_animation_set_value_from(self.to_glib_none().0, value);
149        }
150    }
151
152    #[doc(alias = "adw_timed_animation_set_value_to")]
153    #[doc(alias = "value-to")]
154    pub fn set_value_to(&self, value: f64) {
155        unsafe {
156            ffi::adw_timed_animation_set_value_to(self.to_glib_none().0, value);
157        }
158    }
159
160    #[doc(alias = "alternate")]
161    pub fn connect_alternate_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
162        unsafe extern "C" fn notify_alternate_trampoline<F: Fn(&TimedAnimation) + 'static>(
163            this: *mut ffi::AdwTimedAnimation,
164            _param_spec: glib::ffi::gpointer,
165            f: glib::ffi::gpointer,
166        ) {
167            let f: &F = &*(f as *const F);
168            f(&from_glib_borrow(this))
169        }
170        unsafe {
171            let f: Box_<F> = Box_::new(f);
172            connect_raw(
173                self.as_ptr() as *mut _,
174                c"notify::alternate".as_ptr() as *const _,
175                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
176                    notify_alternate_trampoline::<F> as *const (),
177                )),
178                Box_::into_raw(f),
179            )
180        }
181    }
182
183    #[doc(alias = "duration")]
184    pub fn connect_duration_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
185        unsafe extern "C" fn notify_duration_trampoline<F: Fn(&TimedAnimation) + 'static>(
186            this: *mut ffi::AdwTimedAnimation,
187            _param_spec: glib::ffi::gpointer,
188            f: glib::ffi::gpointer,
189        ) {
190            let f: &F = &*(f as *const F);
191            f(&from_glib_borrow(this))
192        }
193        unsafe {
194            let f: Box_<F> = Box_::new(f);
195            connect_raw(
196                self.as_ptr() as *mut _,
197                c"notify::duration".as_ptr() as *const _,
198                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
199                    notify_duration_trampoline::<F> as *const (),
200                )),
201                Box_::into_raw(f),
202            )
203        }
204    }
205
206    #[doc(alias = "easing")]
207    pub fn connect_easing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
208        unsafe extern "C" fn notify_easing_trampoline<F: Fn(&TimedAnimation) + 'static>(
209            this: *mut ffi::AdwTimedAnimation,
210            _param_spec: glib::ffi::gpointer,
211            f: glib::ffi::gpointer,
212        ) {
213            let f: &F = &*(f as *const F);
214            f(&from_glib_borrow(this))
215        }
216        unsafe {
217            let f: Box_<F> = Box_::new(f);
218            connect_raw(
219                self.as_ptr() as *mut _,
220                c"notify::easing".as_ptr() as *const _,
221                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
222                    notify_easing_trampoline::<F> as *const (),
223                )),
224                Box_::into_raw(f),
225            )
226        }
227    }
228
229    #[doc(alias = "repeat-count")]
230    pub fn connect_repeat_count_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
231        unsafe extern "C" fn notify_repeat_count_trampoline<F: Fn(&TimedAnimation) + 'static>(
232            this: *mut ffi::AdwTimedAnimation,
233            _param_spec: glib::ffi::gpointer,
234            f: glib::ffi::gpointer,
235        ) {
236            let f: &F = &*(f as *const F);
237            f(&from_glib_borrow(this))
238        }
239        unsafe {
240            let f: Box_<F> = Box_::new(f);
241            connect_raw(
242                self.as_ptr() as *mut _,
243                c"notify::repeat-count".as_ptr() as *const _,
244                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
245                    notify_repeat_count_trampoline::<F> as *const (),
246                )),
247                Box_::into_raw(f),
248            )
249        }
250    }
251
252    #[doc(alias = "reverse")]
253    pub fn connect_reverse_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
254        unsafe extern "C" fn notify_reverse_trampoline<F: Fn(&TimedAnimation) + 'static>(
255            this: *mut ffi::AdwTimedAnimation,
256            _param_spec: glib::ffi::gpointer,
257            f: glib::ffi::gpointer,
258        ) {
259            let f: &F = &*(f as *const F);
260            f(&from_glib_borrow(this))
261        }
262        unsafe {
263            let f: Box_<F> = Box_::new(f);
264            connect_raw(
265                self.as_ptr() as *mut _,
266                c"notify::reverse".as_ptr() as *const _,
267                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
268                    notify_reverse_trampoline::<F> as *const (),
269                )),
270                Box_::into_raw(f),
271            )
272        }
273    }
274
275    #[doc(alias = "value-from")]
276    pub fn connect_value_from_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
277        unsafe extern "C" fn notify_value_from_trampoline<F: Fn(&TimedAnimation) + 'static>(
278            this: *mut ffi::AdwTimedAnimation,
279            _param_spec: glib::ffi::gpointer,
280            f: glib::ffi::gpointer,
281        ) {
282            let f: &F = &*(f as *const F);
283            f(&from_glib_borrow(this))
284        }
285        unsafe {
286            let f: Box_<F> = Box_::new(f);
287            connect_raw(
288                self.as_ptr() as *mut _,
289                c"notify::value-from".as_ptr() as *const _,
290                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
291                    notify_value_from_trampoline::<F> as *const (),
292                )),
293                Box_::into_raw(f),
294            )
295        }
296    }
297
298    #[doc(alias = "value-to")]
299    pub fn connect_value_to_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
300        unsafe extern "C" fn notify_value_to_trampoline<F: Fn(&TimedAnimation) + 'static>(
301            this: *mut ffi::AdwTimedAnimation,
302            _param_spec: glib::ffi::gpointer,
303            f: glib::ffi::gpointer,
304        ) {
305            let f: &F = &*(f as *const F);
306            f(&from_glib_borrow(this))
307        }
308        unsafe {
309            let f: Box_<F> = Box_::new(f);
310            connect_raw(
311                self.as_ptr() as *mut _,
312                c"notify::value-to".as_ptr() as *const _,
313                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
314                    notify_value_to_trampoline::<F> as *const (),
315                )),
316                Box_::into_raw(f),
317            )
318        }
319    }
320}
321
322impl Default for TimedAnimation {
323    fn default() -> Self {
324        glib::object::Object::new::<Self>()
325    }
326}
327
328// rustdoc-stripper-ignore-next
329/// A [builder-pattern] type to construct [`TimedAnimation`] objects.
330///
331/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
332#[must_use = "The builder must be built to be used"]
333pub struct TimedAnimationBuilder {
334    builder: glib::object::ObjectBuilder<'static, TimedAnimation>,
335}
336
337impl TimedAnimationBuilder {
338    fn new() -> Self {
339        Self {
340            builder: glib::object::Object::builder(),
341        }
342    }
343
344    pub fn alternate(self, alternate: bool) -> Self {
345        Self {
346            builder: self.builder.property("alternate", alternate),
347        }
348    }
349
350    pub fn duration(self, duration: u32) -> Self {
351        Self {
352            builder: self.builder.property("duration", duration),
353        }
354    }
355
356    pub fn easing(self, easing: Easing) -> Self {
357        Self {
358            builder: self.builder.property("easing", easing),
359        }
360    }
361
362    pub fn repeat_count(self, repeat_count: u32) -> Self {
363        Self {
364            builder: self.builder.property("repeat-count", repeat_count),
365        }
366    }
367
368    pub fn reverse(self, reverse: bool) -> Self {
369        Self {
370            builder: self.builder.property("reverse", reverse),
371        }
372    }
373
374    pub fn value_from(self, value_from: f64) -> Self {
375        Self {
376            builder: self.builder.property("value-from", value_from),
377        }
378    }
379
380    pub fn value_to(self, value_to: f64) -> Self {
381        Self {
382            builder: self.builder.property("value-to", value_to),
383        }
384    }
385
386    #[cfg(feature = "v1_3")]
387    #[cfg_attr(docsrs, doc(cfg(feature = "v1_3")))]
388    pub fn follow_enable_animations_setting(self, follow_enable_animations_setting: bool) -> Self {
389        Self {
390            builder: self.builder.property(
391                "follow-enable-animations-setting",
392                follow_enable_animations_setting,
393            ),
394        }
395    }
396
397    pub fn target(self, target: &impl IsA<AnimationTarget>) -> Self {
398        Self {
399            builder: self.builder.property("target", target.clone().upcast()),
400        }
401    }
402
403    pub fn widget(self, widget: &impl IsA<gtk::Widget>) -> Self {
404        Self {
405            builder: self.builder.property("widget", widget.clone().upcast()),
406        }
407    }
408
409    // rustdoc-stripper-ignore-next
410    /// Build the [`TimedAnimation`].
411    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
412    pub fn build(self) -> TimedAnimation {
413        assert_initialized_main_thread!();
414        self.builder.build()
415    }
416}