Skip to content

Commit ea68a23

Browse files
gdk: implement conversions for Rectangle
From cairo::Rectangle and pango::Rectangle
1 parent eda342b commit ea68a23

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

gdk4/src/rectangle.rs

+44-1
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,51 @@ impl AsRef<RectangleInt> for Rectangle {
5454
}
5555

5656
impl From<RectangleInt> for Rectangle {
57-
fn from(r: RectangleInt) -> Rectangle {
57+
fn from(r: RectangleInt) -> Self {
5858
skip_assert_initialized!();
5959
unsafe { *(&r as *const _ as *const _) }
6060
}
6161
}
62+
63+
impl From<Rectangle> for RectangleInt {
64+
fn from(r: Rectangle) -> Self {
65+
skip_assert_initialized!();
66+
unsafe { *(&r as *const _ as *const _) }
67+
}
68+
}
69+
70+
impl From<cairo::Rectangle> for Rectangle {
71+
// rustdoc-stripper-ignore-next
72+
/// Note that converting between a [`cairo::Rectangle`] and [`Rectangle`]
73+
/// will probably lead to precisison errors. Use cautiously.
74+
fn from(r: cairo::Rectangle) -> Self {
75+
skip_assert_initialized!();
76+
Self::new(r.x as i32, r.y as i32, r.width as i32, r.height as i32)
77+
}
78+
}
79+
80+
impl From<Rectangle> for cairo::Rectangle {
81+
fn from(r: Rectangle) -> Self {
82+
skip_assert_initialized!();
83+
Self {
84+
x: r.x() as f64,
85+
y: r.y() as f64,
86+
width: r.width() as f64,
87+
height: r.height() as f64,
88+
}
89+
}
90+
}
91+
92+
impl From<pango::Rectangle> for Rectangle {
93+
fn from(r: pango::Rectangle) -> Self {
94+
skip_assert_initialized!();
95+
Self::new(r.x(), r.y(), r.width(), r.height())
96+
}
97+
}
98+
99+
impl From<Rectangle> for pango::Rectangle {
100+
fn from(r: Rectangle) -> Self {
101+
skip_assert_initialized!();
102+
Self::new(r.x(), r.y(), r.width(), r.height())
103+
}
104+
}

0 commit comments

Comments
 (0)