gdk/
rectangle.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use crate::Rectangle;
4use cairo::RectangleInt;
5use glib::translate::*;
6use std::convert::{AsRef, From};
7use std::fmt;
8
9impl Rectangle {
10    pub fn new(x: i32, y: i32, width: i32, height: i32) -> Rectangle {
11        skip_assert_initialized!();
12        unsafe {
13            Rectangle::unsafe_from(ffi::GdkRectangle {
14                x,
15                y,
16                width,
17                height,
18            })
19        }
20    }
21
22    pub fn x(&self) -> i32 {
23        self.inner.x
24    }
25
26    pub fn y(&self) -> i32 {
27        self.inner.y
28    }
29
30    pub fn width(&self) -> i32 {
31        self.inner.width
32    }
33
34    pub fn height(&self) -> i32 {
35        self.inner.height
36    }
37}
38
39impl fmt::Debug for Rectangle {
40    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
41        f.debug_struct("Rectangle")
42            .field("x", &self.x())
43            .field("y", &self.y())
44            .field("width", &self.width())
45            .field("height", &self.height())
46            .finish()
47    }
48}
49
50impl AsRef<RectangleInt> for Rectangle {
51    fn as_ref(&self) -> &RectangleInt {
52        unsafe { &*(self as *const _ as *const _) }
53    }
54}
55
56impl From<RectangleInt> for Rectangle {
57    fn from(r: RectangleInt) -> Rectangle {
58        skip_assert_initialized!();
59        unsafe { *(&r as *const _ as *const _) }
60    }
61}