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
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use glib::translate::*;

glib::wrapper! {
    /// A size.
    #[derive(Debug, PartialOrd, Ord, Hash)]
    pub struct Size(Boxed<ffi::graphene_size_t>);

    match fn {
        copy => |ptr| glib::gobject_ffi::g_boxed_copy(ffi::graphene_size_get_type(), ptr as *mut _) as *mut ffi::graphene_size_t,
        free => |ptr| glib::gobject_ffi::g_boxed_free(ffi::graphene_size_get_type(), ptr as *mut _),
        init => |_ptr| (),
        clear => |_ptr| (),
        type_ => || ffi::graphene_size_get_type(),
    }
}

impl Size {
    /// Checks whether the two give [`Size`][crate::Size] are equal.
    /// ## `b`
    /// a [`Size`][crate::Size]
    ///
    /// # Returns
    ///
    /// `true` if the sizes are equal
    #[doc(alias = "graphene_size_equal")]
    fn equal(&self, b: &Size) -> bool {
        unsafe {
            from_glib(ffi::graphene_size_equal(
                self.to_glib_none().0,
                b.to_glib_none().0,
            ))
        }
    }

    /// Initializes a [`Size`][crate::Size] using the given `width` and `height`.
    /// ## `width`
    /// the width
    /// ## `height`
    /// the height
    ///
    /// # Returns
    ///
    /// the initialized [`Size`][crate::Size]
    #[doc(alias = "graphene_size_init")]
    pub fn init(&mut self, width: f32, height: f32) {
        unsafe {
            ffi::graphene_size_init(self.to_glib_none_mut().0, width, height);
        }
    }

    /// Initializes a [`Size`][crate::Size] using the width and height of
    /// the given `src`.
    /// ## `src`
    /// a [`Size`][crate::Size]
    ///
    /// # Returns
    ///
    /// the initialized [`Size`][crate::Size]
    #[doc(alias = "graphene_size_init_from_size")]
    pub fn init_from_size(&mut self, src: &Size) {
        unsafe {
            ffi::graphene_size_init_from_size(self.to_glib_none_mut().0, src.to_glib_none().0);
        }
    }

    /// Linearly interpolates the two given [`Size`][crate::Size] using the given
    /// interpolation `factor`.
    /// ## `b`
    /// a [`Size`][crate::Size]
    /// ## `factor`
    /// the linear interpolation factor
    ///
    /// # Returns
    ///
    ///
    /// ## `res`
    /// return location for the interpolated size
    #[doc(alias = "graphene_size_interpolate")]
    pub fn interpolate(&self, b: &Size, factor: f64) -> Size {
        unsafe {
            let mut res = Size::uninitialized();
            ffi::graphene_size_interpolate(
                self.to_glib_none().0,
                b.to_glib_none().0,
                factor,
                res.to_glib_none_mut().0,
            );
            res
        }
    }

    /// Scales the components of a [`Size`][crate::Size] using the given `factor`.
    /// ## `factor`
    /// the scaling factor
    ///
    /// # Returns
    ///
    ///
    /// ## `res`
    /// return location for the scaled size
    #[doc(alias = "graphene_size_scale")]
    pub fn scale(&self, factor: f32) -> Size {
        unsafe {
            let mut res = Size::uninitialized();
            ffi::graphene_size_scale(self.to_glib_none().0, factor, res.to_glib_none_mut().0);
            res
        }
    }

    /// A constant pointer to a zero [`Size`][crate::Size], useful for
    /// equality checks and interpolations.
    ///
    /// # Returns
    ///
    /// a constant size
    #[doc(alias = "graphene_size_zero")]
    pub fn zero() -> Size {
        assert_initialized_main_thread!();
        unsafe { from_glib_none(ffi::graphene_size_zero()) }
    }
}

impl PartialEq for Size {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        self.equal(other)
    }
}

impl Eq for Size {}