Skip to main content

cairo/
rectangle.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3#[cfg(feature = "use_glib")]
4use glib::translate::*;
5use std::fmt;
6#[cfg(feature = "use_glib")]
7use std::mem;
8
9#[derive(Clone, Copy, Debug, PartialEq)]
10#[repr(C)]
11#[doc(alias = "cairo_rectangle_t")]
12pub struct Rectangle {
13    pub x: f64,
14    pub y: f64,
15    pub width: f64,
16    pub height: f64,
17}
18
19#[cfg(feature = "use_glib")]
20#[doc(hidden)]
21impl Uninitialized for Rectangle {
22    #[inline]
23    unsafe fn uninitialized() -> Self {
24        mem::zeroed()
25    }
26}
27
28#[cfg(feature = "use_glib")]
29#[doc(hidden)]
30impl<'a> ToGlibPtr<'a, *const ffi::cairo_rectangle_t> for Rectangle {
31    type Storage = &'a Self;
32
33    #[inline]
34    fn to_glib_none(&'a self) -> Stash<'a, *const ffi::cairo_rectangle_t, Self> {
35        let ptr: *const Rectangle = &*self;
36        Stash(ptr as *const ffi::cairo_rectangle_t, self)
37    }
38}
39
40#[cfg(feature = "use_glib")]
41#[doc(hidden)]
42impl<'a> ToGlibPtrMut<'a, *mut ffi::cairo_rectangle_t> for Rectangle {
43    type Storage = &'a mut Self;
44
45    #[inline]
46    fn to_glib_none_mut(&'a mut self) -> StashMut<'a, *mut ffi::cairo_rectangle_t, Self> {
47        let ptr: *mut Rectangle = &mut *self;
48        StashMut(ptr as *mut ffi::cairo_rectangle_t, self)
49    }
50}
51
52#[cfg(feature = "use_glib")]
53#[doc(hidden)]
54impl FromGlibPtrNone<*const ffi::cairo_rectangle_t> for Rectangle {
55    unsafe fn from_glib_none(ptr: *const ffi::cairo_rectangle_t) -> Self {
56        *(ptr as *const Rectangle)
57    }
58}
59
60#[cfg(feature = "use_glib")]
61#[doc(hidden)]
62impl FromGlibPtrBorrow<*mut ffi::cairo_rectangle_t> for Rectangle {
63    unsafe fn from_glib_borrow(ptr: *mut ffi::cairo_rectangle_t) -> crate::Borrowed<Self> {
64        crate::Borrowed::new(*(ptr as *mut Rectangle))
65    }
66}
67
68#[cfg(feature = "use_glib")]
69#[doc(hidden)]
70impl FromGlibPtrNone<*mut ffi::cairo_rectangle_t> for Rectangle {
71    unsafe fn from_glib_none(ptr: *mut ffi::cairo_rectangle_t) -> Self {
72        *(ptr as *mut Rectangle)
73    }
74}
75
76#[cfg(feature = "use_glib")]
77gvalue_impl!(
78    Rectangle,
79    ffi::cairo_rectangle_t,
80    ffi::gobject::cairo_gobject_rectangle_get_type
81);
82
83impl Rectangle {
84    pub fn to_raw_none(&self) -> *mut ffi::cairo_rectangle_t {
85        let ptr = &*self as *const Rectangle as usize;
86        ptr as *mut ffi::cairo_rectangle_t
87    }
88}
89
90impl fmt::Display for Rectangle {
91    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
92        write!(f, "Rectangle")
93    }
94}