libadwaita/auto/spring_params.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;
7use glib::translate::*;
8
9glib::wrapper! {
10 /// Physical parameters of a spring for [`SpringAnimation`][crate::SpringAnimation].
11 ///
12 /// Any spring can be described by three parameters: mass, stiffness and damping.
13 ///
14 /// An undamped spring will produce an oscillatory motion which will go on
15 /// forever.
16 ///
17 /// The frequency and amplitude of the oscillations will be determined by the
18 /// stiffness (how "strong" the spring is) and its mass (how much "inertia" it
19 /// has).
20 ///
21 /// If damping is larger than 0, the amplitude of that oscillating motion will
22 /// exponientally decrease over time. If that damping is strong enough that the
23 /// spring can't complete a full oscillation, it's called an overdamped spring.
24 ///
25 /// If we the spring can oscillate, it's called an underdamped spring.
26 ///
27 /// The value between these two behaviors is called critical damping; a
28 /// critically damped spring will comes to rest in the minimum possible time
29 /// without producing oscillations.
30 ///
31 /// The damping can be replaced by damping ratio, which produces the following
32 /// springs:
33 ///
34 /// * 0: an undamped spring.
35 /// * Between 0 and 1: an underdamped spring.
36 /// * 1: a critically damped spring.
37 /// * Larger than 1: an overdamped spring.
38 ///
39 /// As such
40 #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
41 pub struct SpringParams(Shared<ffi::AdwSpringParams>);
42
43 match fn {
44 ref => |ptr| ffi::adw_spring_params_ref(ptr),
45 unref => |ptr| ffi::adw_spring_params_unref(ptr),
46 type_ => || ffi::adw_spring_params_get_type(),
47 }
48}
49
50impl SpringParams {
51 /// Creates a new [`SpringParams`][crate::SpringParams] from @mass, @stiffness and @damping_ratio.
52 ///
53 /// The damping value is calculated from @damping_ratio and the other two
54 /// parameters.
55 ///
56 /// * If @damping_ratio is 0, the spring will not be damped and will oscillate
57 /// endlessly.
58 /// * If @damping_ratio is between 0 and 1, the spring is underdamped and will
59 /// always overshoot.
60 /// * If @damping_ratio is 1, the spring is critically damped and will reach its
61 /// resting position the quickest way possible.
62 /// * If @damping_ratio is larger than 1, the spring is overdamped and will reach
63 /// its resting position faster than it can complete an oscillation.
64 ///
65 /// `SpringParams::new_full()` allows to pass a raw damping value instead.
66 /// ## `damping_ratio`
67 /// the damping ratio of the spring
68 /// ## `mass`
69 /// the mass of the spring
70 /// ## `stiffness`
71 /// the stiffness of the spring
72 ///
73 /// # Returns
74 ///
75 /// the newly created spring parameters
76 #[doc(alias = "adw_spring_params_new")]
77 pub fn new(damping_ratio: f64, mass: f64, stiffness: f64) -> SpringParams {
78 assert_initialized_main_thread!();
79 unsafe { from_glib_full(ffi::adw_spring_params_new(damping_ratio, mass, stiffness)) }
80 }
81
82 /// Creates a new [`SpringParams`][crate::SpringParams] from @mass, @stiffness and @damping.
83 ///
84 /// See `SpringParams::new()` for a simplified constructor using damping ratio
85 /// instead of @damping.
86 /// ## `damping`
87 /// the damping of the spring
88 /// ## `mass`
89 /// the mass of the spring
90 /// ## `stiffness`
91 /// the stiffness of the spring
92 ///
93 /// # Returns
94 ///
95 /// the newly created spring parameters
96 #[doc(alias = "adw_spring_params_new_full")]
97 pub fn new_full(damping: f64, mass: f64, stiffness: f64) -> SpringParams {
98 assert_initialized_main_thread!();
99 unsafe { from_glib_full(ffi::adw_spring_params_new_full(damping, mass, stiffness)) }
100 }
101
102 /// Gets the damping of @self.
103 ///
104 /// # Returns
105 ///
106 /// the damping
107 #[doc(alias = "adw_spring_params_get_damping")]
108 #[doc(alias = "get_damping")]
109 pub fn damping(&self) -> f64 {
110 unsafe { ffi::adw_spring_params_get_damping(self.to_glib_none().0) }
111 }
112
113 /// Gets the damping ratio of @self.
114 ///
115 /// # Returns
116 ///
117 /// the damping ratio
118 #[doc(alias = "adw_spring_params_get_damping_ratio")]
119 #[doc(alias = "get_damping_ratio")]
120 pub fn damping_ratio(&self) -> f64 {
121 unsafe { ffi::adw_spring_params_get_damping_ratio(self.to_glib_none().0) }
122 }
123
124 /// Gets the mass of @self.
125 ///
126 /// # Returns
127 ///
128 /// the mass
129 #[doc(alias = "adw_spring_params_get_mass")]
130 #[doc(alias = "get_mass")]
131 pub fn mass(&self) -> f64 {
132 unsafe { ffi::adw_spring_params_get_mass(self.to_glib_none().0) }
133 }
134
135 /// Gets the stiffness of @self.
136 ///
137 /// # Returns
138 ///
139 /// the stiffness
140 #[doc(alias = "adw_spring_params_get_stiffness")]
141 #[doc(alias = "get_stiffness")]
142 pub fn stiffness(&self) -> f64 {
143 unsafe { ffi::adw_spring_params_get_stiffness(self.to_glib_none().0) }
144 }
145}