cairo/
rectangle_int.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use crate::ffi;
4use std::fmt;
5
6#[cfg(feature = "use_glib")]
7use std::{marker::PhantomData, mem};
8
9#[cfg(feature = "use_glib")]
10use glib::translate::*;
11
12#[derive(Clone, Copy, PartialEq, Eq)]
13#[repr(transparent)]
14#[doc(alias = "cairo_rectangle_int_t")]
15pub struct RectangleInt(ffi::cairo_rectangle_int_t);
16
17impl RectangleInt {
18    #[inline]
19    pub fn new(x: i32, y: i32, width: i32, height: i32) -> Self {
20        Self(ffi::cairo_rectangle_int_t {
21            x,
22            y,
23            width,
24            height,
25        })
26    }
27    #[inline]
28    pub fn x(&self) -> i32 {
29        self.0.x
30    }
31    #[inline]
32    pub fn set_x(&mut self, x: i32) {
33        self.0.x = x;
34    }
35    #[inline]
36    pub fn y(&self) -> i32 {
37        self.0.y
38    }
39    #[inline]
40    pub fn set_y(&mut self, y: i32) {
41        self.0.y = y;
42    }
43    #[inline]
44    pub fn width(&self) -> i32 {
45        self.0.width
46    }
47    #[inline]
48    pub fn set_width(&mut self, width: i32) {
49        self.0.width = width;
50    }
51    #[inline]
52    pub fn height(&self) -> i32 {
53        self.0.height
54    }
55    #[inline]
56    pub fn set_height(&mut self, height: i32) {
57        self.0.height = height;
58    }
59}
60
61impl fmt::Debug for RectangleInt {
62    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
63        f.debug_struct("RectangleInt")
64            .field("x", &self.x())
65            .field("y", &self.y())
66            .field("width", &self.width())
67            .field("height", &self.height())
68            .finish()
69    }
70}
71
72#[cfg(feature = "use_glib")]
73#[doc(hidden)]
74impl Uninitialized for RectangleInt {
75    #[inline]
76    unsafe fn uninitialized() -> Self {
77        mem::zeroed()
78    }
79}
80
81#[cfg(feature = "use_glib")]
82#[doc(hidden)]
83impl<'a> ToGlibPtr<'a, *const ffi::cairo_rectangle_int_t> for RectangleInt {
84    type Storage = PhantomData<&'a Self>;
85
86    #[inline]
87    fn to_glib_none(&'a self) -> Stash<'a, *const ffi::cairo_rectangle_int_t, Self> {
88        Stash(
89            self as *const RectangleInt as *const ffi::cairo_rectangle_int_t,
90            PhantomData,
91        )
92    }
93}
94
95#[cfg(feature = "use_glib")]
96#[doc(hidden)]
97impl<'a> ToGlibPtrMut<'a, *mut ffi::cairo_rectangle_int_t> for RectangleInt {
98    type Storage = PhantomData<&'a mut Self>;
99
100    #[inline]
101    fn to_glib_none_mut(&'a mut self) -> StashMut<'a, *mut ffi::cairo_rectangle_int_t, Self> {
102        StashMut(
103            self as *mut RectangleInt as *mut ffi::cairo_rectangle_int_t,
104            PhantomData,
105        )
106    }
107}
108
109#[cfg(feature = "use_glib")]
110#[doc(hidden)]
111impl FromGlibPtrNone<*const ffi::cairo_rectangle_int_t> for RectangleInt {
112    #[inline]
113    unsafe fn from_glib_none(ptr: *const ffi::cairo_rectangle_int_t) -> Self {
114        *(ptr as *const RectangleInt)
115    }
116}
117
118#[cfg(feature = "use_glib")]
119#[doc(hidden)]
120impl FromGlibPtrBorrow<*mut ffi::cairo_rectangle_int_t> for RectangleInt {
121    #[inline]
122    unsafe fn from_glib_borrow(ptr: *mut ffi::cairo_rectangle_int_t) -> crate::Borrowed<Self> {
123        crate::Borrowed::new(*(ptr as *mut RectangleInt))
124    }
125}
126
127#[cfg(feature = "use_glib")]
128#[doc(hidden)]
129impl FromGlibPtrNone<*mut ffi::cairo_rectangle_int_t> for RectangleInt {
130    #[inline]
131    unsafe fn from_glib_none(ptr: *mut ffi::cairo_rectangle_int_t) -> Self {
132        *(ptr as *mut RectangleInt)
133    }
134}
135
136#[cfg(feature = "use_glib")]
137gvalue_impl_inline!(
138    RectangleInt,
139    ffi::cairo_rectangle_int_t,
140    ffi::gobject::cairo_gobject_rectangle_int_get_type
141);
142
143impl RectangleInt {
144    #[inline]
145    pub fn to_raw_none(&self) -> *mut ffi::cairo_rectangle_int_t {
146        &self.0 as *const ffi::cairo_rectangle_int_t as *mut ffi::cairo_rectangle_int_t
147    }
148}