gdk4/
rectangle.rs
1use std::fmt;
4
5use cairo::RectangleInt;
6use glib::translate::*;
7
8use crate::Rectangle;
9
10impl Rectangle {
11 #[inline]
12 pub fn new(x: i32, y: i32, width: i32, height: i32) -> Self {
13 skip_assert_initialized!();
14 unsafe {
15 Self::unsafe_from(crate::ffi::GdkRectangle {
16 x,
17 y,
18 width,
19 height,
20 })
21 }
22 }
23
24 #[inline]
25 pub fn x(&self) -> i32 {
26 self.inner.x
27 }
28
29 #[inline]
30 pub fn set_x(&mut self, x: i32) {
31 self.inner.x = x;
32 }
33
34 #[inline]
35 pub fn y(&self) -> i32 {
36 self.inner.y
37 }
38
39 #[inline]
40 pub fn set_y(&mut self, y: i32) {
41 self.inner.y = y;
42 }
43
44 #[inline]
45 pub fn width(&self) -> i32 {
46 self.inner.width
47 }
48
49 #[inline]
50 pub fn set_width(&mut self, width: i32) {
51 self.inner.width = width;
52 }
53
54 #[inline]
55 pub fn height(&self) -> i32 {
56 self.inner.height
57 }
58
59 #[inline]
60 pub fn set_height(&mut self, height: i32) {
61 self.inner.height = height;
62 }
63}
64
65impl fmt::Debug for Rectangle {
66 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
67 f.debug_struct("Rectangle")
68 .field("x", &self.x())
69 .field("y", &self.y())
70 .field("width", &self.width())
71 .field("height", &self.height())
72 .finish()
73 }
74}
75
76impl AsRef<RectangleInt> for Rectangle {
77 #[inline]
78 fn as_ref(&self) -> &RectangleInt {
79 unsafe { &*(self as *const _ as *const _) }
80 }
81}
82
83impl From<RectangleInt> for Rectangle {
84 #[inline]
85 fn from(r: RectangleInt) -> Self {
86 skip_assert_initialized!();
87 unsafe { *(&r as *const _ as *const _) }
88 }
89}
90
91impl From<Rectangle> for RectangleInt {
92 #[inline]
93 fn from(r: Rectangle) -> Self {
94 skip_assert_initialized!();
95 unsafe { *(&r as *const _ as *const _) }
96 }
97}
98
99impl From<cairo::Rectangle> for Rectangle {
100 #[inline]
104 fn from(r: cairo::Rectangle) -> Self {
105 skip_assert_initialized!();
106 Self::new(
107 r.x() as i32,
108 r.y() as i32,
109 r.width() as i32,
110 r.height() as i32,
111 )
112 }
113}
114
115impl From<Rectangle> for cairo::Rectangle {
116 #[inline]
117 fn from(r: Rectangle) -> Self {
118 skip_assert_initialized!();
119 cairo::Rectangle::new(
120 r.x() as f64,
121 r.y() as f64,
122 r.width() as f64,
123 r.height() as f64,
124 )
125 }
126}
127
128impl From<pango::Rectangle> for Rectangle {
129 #[inline]
130 fn from(r: pango::Rectangle) -> Self {
131 skip_assert_initialized!();
132 Self::new(r.x(), r.y(), r.width(), r.height())
133 }
134}
135
136impl From<Rectangle> for pango::Rectangle {
137 #[inline]
138 fn from(r: Rectangle) -> Self {
139 skip_assert_initialized!();
140 Self::new(r.x(), r.y(), r.width(), r.height())
141 }
142}