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