1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
use glib::translate::*;
use graphene::{Point, Rect, Size};
use std::mem;
glib::wrapper! {
#[doc(alias = "GskRoundedRect")]
pub struct RoundedRect(BoxedInline<ffi::GskRoundedRect>);
}
impl RoundedRect {
#[doc(alias = "gsk_rounded_rect_init")]
pub fn new(
bounds: Rect,
top_left: Size,
top_right: Size,
bottom_right: Size,
bottom_left: Size,
) -> Self {
assert_initialized_main_thread!();
unsafe {
let mut rounded_rect = mem::MaybeUninit::uninit();
ffi::gsk_rounded_rect_init(
rounded_rect.as_mut_ptr(),
bounds.to_glib_none().0,
top_left.to_glib_none().0,
top_right.to_glib_none().0,
bottom_right.to_glib_none().0,
bottom_left.to_glib_none().0,
);
Self::unsafe_from(rounded_rect.assume_init())
}
}
#[doc(alias = "gsk_rounded_rect_init_from_rect")]
#[doc(alias = "init_from_rect")]
pub fn from_rect(bounds: Rect, radius: f32) -> Self {
assert_initialized_main_thread!();
unsafe {
let mut rounded_rect = mem::MaybeUninit::uninit();
ffi::gsk_rounded_rect_init_from_rect(
rounded_rect.as_mut_ptr(),
bounds.to_glib_none().0,
radius,
);
Self::unsafe_from(rounded_rect.assume_init())
}
}
#[doc(alias = "gsk_rounded_rect_normalize")]
pub fn normalize(&mut self) {
unsafe {
ffi::gsk_rounded_rect_normalize(&mut self.inner);
}
}
#[doc(alias = "gsk_rounded_rect_offset")]
pub fn offset(&mut self, dx: f32, dy: f32) {
unsafe {
ffi::gsk_rounded_rect_offset(&mut self.inner, dx, dy);
}
}
#[doc(alias = "gsk_rounded_rect_shrink")]
pub fn shrink(&mut self, top: f32, right: f32, bottom: f32, left: f32) {
unsafe {
ffi::gsk_rounded_rect_shrink(&mut self.inner, top, right, bottom, left);
}
}
#[doc(alias = "gsk_rounded_rect_is_rectilinear")]
pub fn is_rectilinear(&self) -> bool {
unsafe { from_glib(ffi::gsk_rounded_rect_is_rectilinear(&self.inner)) }
}
#[doc(alias = "gsk_rounded_rect_contains_point")]
pub fn contains_point(&self, point: Point) -> bool {
unsafe {
from_glib(ffi::gsk_rounded_rect_contains_point(
&self.inner,
point.to_glib_none().0,
))
}
}
#[doc(alias = "gsk_rounded_rect_contains_rect")]
pub fn contains_rect(&self, rect: Rect) -> bool {
unsafe {
from_glib(ffi::gsk_rounded_rect_contains_rect(
&self.inner,
rect.to_glib_none().0,
))
}
}
#[doc(alias = "gsk_rounded_rect_intersects_rect")]
pub fn intersects_rect(&self, rect: Rect) -> bool {
unsafe {
from_glib(ffi::gsk_rounded_rect_intersects_rect(
&self.inner,
rect.to_glib_none().0,
))
}
}
pub fn bounds(&self) -> &graphene::Rect {
unsafe {
&*(&self.inner.bounds as *const graphene::ffi::graphene_rect_t as *const graphene::Rect)
}
}
pub fn corner(&self) -> &[graphene::Size; 4] {
unsafe {
&*(&self.inner.corner as *const [graphene::ffi::graphene_size_t; 4]
as *const [graphene::Size; 4])
}
}
}
impl std::fmt::Debug for RoundedRect {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.debug_struct("RoundedRect")
.field("is_rectilinear", &self.is_rectilinear())
.field("bounds", &self.bounds())
.field("corner", &self.corner())
.finish()
}
}