libadwaita/auto/
spring_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, SpringParams};
7use glib::{
8    prelude::*,
9    signal::{connect_raw, SignalHandlerId},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    #[doc(alias = "AdwSpringAnimation")]
16    pub struct SpringAnimation(Object<ffi::AdwSpringAnimation, ffi::AdwSpringAnimationClass>) @extends Animation;
17
18    match fn {
19        type_ => || ffi::adw_spring_animation_get_type(),
20    }
21}
22
23impl SpringAnimation {
24    #[doc(alias = "adw_spring_animation_new")]
25    pub fn new(
26        widget: &impl IsA<gtk::Widget>,
27        from: f64,
28        to: f64,
29        spring_params: SpringParams,
30        target: impl IsA<AnimationTarget>,
31    ) -> SpringAnimation {
32        skip_assert_initialized!();
33        unsafe {
34            Animation::from_glib_none(ffi::adw_spring_animation_new(
35                widget.as_ref().to_glib_none().0,
36                from,
37                to,
38                spring_params.into_glib_ptr(),
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 [`SpringAnimation`] objects.
47    ///
48    /// This method returns an instance of [`SpringAnimationBuilder`](crate::builders::SpringAnimationBuilder) which can be used to create [`SpringAnimation`] objects.
49    pub fn builder() -> SpringAnimationBuilder {
50        SpringAnimationBuilder::new()
51    }
52
53    #[cfg(feature = "v1_3")]
54    #[cfg_attr(docsrs, doc(cfg(feature = "v1_3")))]
55    #[doc(alias = "adw_spring_animation_calculate_value")]
56    pub fn calculate_value(&self, time: u32) -> f64 {
57        unsafe { ffi::adw_spring_animation_calculate_value(self.to_glib_none().0, time) }
58    }
59
60    #[cfg(feature = "v1_3")]
61    #[cfg_attr(docsrs, doc(cfg(feature = "v1_3")))]
62    #[doc(alias = "adw_spring_animation_calculate_velocity")]
63    pub fn calculate_velocity(&self, time: u32) -> f64 {
64        unsafe { ffi::adw_spring_animation_calculate_velocity(self.to_glib_none().0, time) }
65    }
66
67    #[doc(alias = "adw_spring_animation_get_clamp")]
68    #[doc(alias = "get_clamp")]
69    #[doc(alias = "clamp")]
70    pub fn is_clamp(&self) -> bool {
71        unsafe { from_glib(ffi::adw_spring_animation_get_clamp(self.to_glib_none().0)) }
72    }
73
74    #[doc(alias = "adw_spring_animation_get_epsilon")]
75    #[doc(alias = "get_epsilon")]
76    pub fn epsilon(&self) -> f64 {
77        unsafe { ffi::adw_spring_animation_get_epsilon(self.to_glib_none().0) }
78    }
79
80    #[doc(alias = "adw_spring_animation_get_estimated_duration")]
81    #[doc(alias = "get_estimated_duration")]
82    #[doc(alias = "estimated-duration")]
83    pub fn estimated_duration(&self) -> u32 {
84        unsafe { ffi::adw_spring_animation_get_estimated_duration(self.to_glib_none().0) }
85    }
86
87    #[doc(alias = "adw_spring_animation_get_initial_velocity")]
88    #[doc(alias = "get_initial_velocity")]
89    #[doc(alias = "initial-velocity")]
90    pub fn initial_velocity(&self) -> f64 {
91        unsafe { ffi::adw_spring_animation_get_initial_velocity(self.to_glib_none().0) }
92    }
93
94    #[doc(alias = "adw_spring_animation_get_spring_params")]
95    #[doc(alias = "get_spring_params")]
96    #[doc(alias = "spring-params")]
97    pub fn spring_params(&self) -> SpringParams {
98        unsafe {
99            from_glib_none(ffi::adw_spring_animation_get_spring_params(
100                self.to_glib_none().0,
101            ))
102        }
103    }
104
105    #[doc(alias = "adw_spring_animation_get_value_from")]
106    #[doc(alias = "get_value_from")]
107    #[doc(alias = "value-from")]
108    pub fn value_from(&self) -> f64 {
109        unsafe { ffi::adw_spring_animation_get_value_from(self.to_glib_none().0) }
110    }
111
112    #[doc(alias = "adw_spring_animation_get_value_to")]
113    #[doc(alias = "get_value_to")]
114    #[doc(alias = "value-to")]
115    pub fn value_to(&self) -> f64 {
116        unsafe { ffi::adw_spring_animation_get_value_to(self.to_glib_none().0) }
117    }
118
119    #[doc(alias = "adw_spring_animation_get_velocity")]
120    #[doc(alias = "get_velocity")]
121    pub fn velocity(&self) -> f64 {
122        unsafe { ffi::adw_spring_animation_get_velocity(self.to_glib_none().0) }
123    }
124
125    #[doc(alias = "adw_spring_animation_set_clamp")]
126    #[doc(alias = "clamp")]
127    pub fn set_clamp(&self, clamp: bool) {
128        unsafe {
129            ffi::adw_spring_animation_set_clamp(self.to_glib_none().0, clamp.into_glib());
130        }
131    }
132
133    #[doc(alias = "adw_spring_animation_set_epsilon")]
134    #[doc(alias = "epsilon")]
135    pub fn set_epsilon(&self, epsilon: f64) {
136        unsafe {
137            ffi::adw_spring_animation_set_epsilon(self.to_glib_none().0, epsilon);
138        }
139    }
140
141    #[doc(alias = "adw_spring_animation_set_initial_velocity")]
142    #[doc(alias = "initial-velocity")]
143    pub fn set_initial_velocity(&self, velocity: f64) {
144        unsafe {
145            ffi::adw_spring_animation_set_initial_velocity(self.to_glib_none().0, velocity);
146        }
147    }
148
149    #[doc(alias = "adw_spring_animation_set_spring_params")]
150    #[doc(alias = "spring-params")]
151    pub fn set_spring_params(&self, spring_params: &SpringParams) {
152        unsafe {
153            ffi::adw_spring_animation_set_spring_params(
154                self.to_glib_none().0,
155                spring_params.to_glib_none().0,
156            );
157        }
158    }
159
160    #[doc(alias = "adw_spring_animation_set_value_from")]
161    #[doc(alias = "value-from")]
162    pub fn set_value_from(&self, value: f64) {
163        unsafe {
164            ffi::adw_spring_animation_set_value_from(self.to_glib_none().0, value);
165        }
166    }
167
168    #[doc(alias = "adw_spring_animation_set_value_to")]
169    #[doc(alias = "value-to")]
170    pub fn set_value_to(&self, value: f64) {
171        unsafe {
172            ffi::adw_spring_animation_set_value_to(self.to_glib_none().0, value);
173        }
174    }
175
176    #[doc(alias = "clamp")]
177    pub fn connect_clamp_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
178        unsafe extern "C" fn notify_clamp_trampoline<F: Fn(&SpringAnimation) + 'static>(
179            this: *mut ffi::AdwSpringAnimation,
180            _param_spec: glib::ffi::gpointer,
181            f: glib::ffi::gpointer,
182        ) {
183            let f: &F = &*(f as *const F);
184            f(&from_glib_borrow(this))
185        }
186        unsafe {
187            let f: Box_<F> = Box_::new(f);
188            connect_raw(
189                self.as_ptr() as *mut _,
190                c"notify::clamp".as_ptr() as *const _,
191                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
192                    notify_clamp_trampoline::<F> as *const (),
193                )),
194                Box_::into_raw(f),
195            )
196        }
197    }
198
199    #[doc(alias = "epsilon")]
200    pub fn connect_epsilon_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
201        unsafe extern "C" fn notify_epsilon_trampoline<F: Fn(&SpringAnimation) + 'static>(
202            this: *mut ffi::AdwSpringAnimation,
203            _param_spec: glib::ffi::gpointer,
204            f: glib::ffi::gpointer,
205        ) {
206            let f: &F = &*(f as *const F);
207            f(&from_glib_borrow(this))
208        }
209        unsafe {
210            let f: Box_<F> = Box_::new(f);
211            connect_raw(
212                self.as_ptr() as *mut _,
213                c"notify::epsilon".as_ptr() as *const _,
214                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
215                    notify_epsilon_trampoline::<F> as *const (),
216                )),
217                Box_::into_raw(f),
218            )
219        }
220    }
221
222    #[doc(alias = "estimated-duration")]
223    pub fn connect_estimated_duration_notify<F: Fn(&Self) + 'static>(
224        &self,
225        f: F,
226    ) -> SignalHandlerId {
227        unsafe extern "C" fn notify_estimated_duration_trampoline<
228            F: Fn(&SpringAnimation) + 'static,
229        >(
230            this: *mut ffi::AdwSpringAnimation,
231            _param_spec: glib::ffi::gpointer,
232            f: glib::ffi::gpointer,
233        ) {
234            let f: &F = &*(f as *const F);
235            f(&from_glib_borrow(this))
236        }
237        unsafe {
238            let f: Box_<F> = Box_::new(f);
239            connect_raw(
240                self.as_ptr() as *mut _,
241                c"notify::estimated-duration".as_ptr() as *const _,
242                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
243                    notify_estimated_duration_trampoline::<F> as *const (),
244                )),
245                Box_::into_raw(f),
246            )
247        }
248    }
249
250    #[doc(alias = "initial-velocity")]
251    pub fn connect_initial_velocity_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
252        unsafe extern "C" fn notify_initial_velocity_trampoline<
253            F: Fn(&SpringAnimation) + 'static,
254        >(
255            this: *mut ffi::AdwSpringAnimation,
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::initial-velocity".as_ptr() as *const _,
267                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
268                    notify_initial_velocity_trampoline::<F> as *const (),
269                )),
270                Box_::into_raw(f),
271            )
272        }
273    }
274
275    #[doc(alias = "spring-params")]
276    pub fn connect_spring_params_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
277        unsafe extern "C" fn notify_spring_params_trampoline<F: Fn(&SpringAnimation) + 'static>(
278            this: *mut ffi::AdwSpringAnimation,
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::spring-params".as_ptr() as *const _,
290                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
291                    notify_spring_params_trampoline::<F> as *const (),
292                )),
293                Box_::into_raw(f),
294            )
295        }
296    }
297
298    #[doc(alias = "value-from")]
299    pub fn connect_value_from_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
300        unsafe extern "C" fn notify_value_from_trampoline<F: Fn(&SpringAnimation) + 'static>(
301            this: *mut ffi::AdwSpringAnimation,
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-from".as_ptr() as *const _,
313                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
314                    notify_value_from_trampoline::<F> as *const (),
315                )),
316                Box_::into_raw(f),
317            )
318        }
319    }
320
321    #[doc(alias = "value-to")]
322    pub fn connect_value_to_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
323        unsafe extern "C" fn notify_value_to_trampoline<F: Fn(&SpringAnimation) + 'static>(
324            this: *mut ffi::AdwSpringAnimation,
325            _param_spec: glib::ffi::gpointer,
326            f: glib::ffi::gpointer,
327        ) {
328            let f: &F = &*(f as *const F);
329            f(&from_glib_borrow(this))
330        }
331        unsafe {
332            let f: Box_<F> = Box_::new(f);
333            connect_raw(
334                self.as_ptr() as *mut _,
335                c"notify::value-to".as_ptr() as *const _,
336                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
337                    notify_value_to_trampoline::<F> as *const (),
338                )),
339                Box_::into_raw(f),
340            )
341        }
342    }
343
344    #[doc(alias = "velocity")]
345    pub fn connect_velocity_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
346        unsafe extern "C" fn notify_velocity_trampoline<F: Fn(&SpringAnimation) + 'static>(
347            this: *mut ffi::AdwSpringAnimation,
348            _param_spec: glib::ffi::gpointer,
349            f: glib::ffi::gpointer,
350        ) {
351            let f: &F = &*(f as *const F);
352            f(&from_glib_borrow(this))
353        }
354        unsafe {
355            let f: Box_<F> = Box_::new(f);
356            connect_raw(
357                self.as_ptr() as *mut _,
358                c"notify::velocity".as_ptr() as *const _,
359                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
360                    notify_velocity_trampoline::<F> as *const (),
361                )),
362                Box_::into_raw(f),
363            )
364        }
365    }
366}
367
368impl Default for SpringAnimation {
369    fn default() -> Self {
370        glib::object::Object::new::<Self>()
371    }
372}
373
374// rustdoc-stripper-ignore-next
375/// A [builder-pattern] type to construct [`SpringAnimation`] objects.
376///
377/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
378#[must_use = "The builder must be built to be used"]
379pub struct SpringAnimationBuilder {
380    builder: glib::object::ObjectBuilder<'static, SpringAnimation>,
381}
382
383impl SpringAnimationBuilder {
384    fn new() -> Self {
385        Self {
386            builder: glib::object::Object::builder(),
387        }
388    }
389
390    pub fn clamp(self, clamp: bool) -> Self {
391        Self {
392            builder: self.builder.property("clamp", clamp),
393        }
394    }
395
396    pub fn epsilon(self, epsilon: f64) -> Self {
397        Self {
398            builder: self.builder.property("epsilon", epsilon),
399        }
400    }
401
402    pub fn initial_velocity(self, initial_velocity: f64) -> Self {
403        Self {
404            builder: self.builder.property("initial-velocity", initial_velocity),
405        }
406    }
407
408    pub fn spring_params(self, spring_params: &SpringParams) -> Self {
409        Self {
410            builder: self
411                .builder
412                .property("spring-params", spring_params.clone()),
413        }
414    }
415
416    pub fn value_from(self, value_from: f64) -> Self {
417        Self {
418            builder: self.builder.property("value-from", value_from),
419        }
420    }
421
422    pub fn value_to(self, value_to: f64) -> Self {
423        Self {
424            builder: self.builder.property("value-to", value_to),
425        }
426    }
427
428    #[cfg(feature = "v1_3")]
429    #[cfg_attr(docsrs, doc(cfg(feature = "v1_3")))]
430    pub fn follow_enable_animations_setting(self, follow_enable_animations_setting: bool) -> Self {
431        Self {
432            builder: self.builder.property(
433                "follow-enable-animations-setting",
434                follow_enable_animations_setting,
435            ),
436        }
437    }
438
439    pub fn target(self, target: &impl IsA<AnimationTarget>) -> Self {
440        Self {
441            builder: self.builder.property("target", target.clone().upcast()),
442        }
443    }
444
445    pub fn widget(self, widget: &impl IsA<gtk::Widget>) -> Self {
446        Self {
447            builder: self.builder.property("widget", widget.clone().upcast()),
448        }
449    }
450
451    // rustdoc-stripper-ignore-next
452    /// Build the [`SpringAnimation`].
453    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
454    pub fn build(self) -> SpringAnimation {
455        assert_initialized_main_thread!();
456        self.builder.build()
457    }
458}