1use crate::{Actor, Animatable, Color, Container};
3use glib::{
4 object as gobject,
5 object::{Cast, IsA},
6 signal::{connect_raw, SignalHandlerId},
7 translate::*,
8 StaticType, Value,
9};
10use std::boxed::Box as Box_;
11use std::{fmt, mem::transmute};
12
13glib_wrapper! {
15 pub struct Rectangle(Object<ffi::ClutterRectangle, ffi::ClutterRectangleClass, RectangleClass>) @extends Actor, gobject::InitiallyUnowned, @implements Animatable, Container;
16
17 match fn {
18 get_type => || ffi::clutter_rectangle_get_type(),
19 }
20}
21
22pub const NONE_RECTANGLE: Option<&Rectangle> = None;
23
24pub trait RectangleExt: 'static {
30 fn get_property_border_color(&self) -> Option<Color>;
32
33 fn set_property_border_color(&self, border_color: Option<&Color>);
35
36 fn get_property_border_width(&self) -> u32;
38
39 fn set_property_border_width(&self, border_width: u32);
41
42 fn get_property_color(&self) -> Option<Color>;
44
45 fn set_property_color(&self, color: Option<&Color>);
47
48 fn get_property_has_border(&self) -> bool;
50
51 fn set_property_has_border(&self, has_border: bool);
53
54 fn connect_property_border_color_notify<F: Fn(&Self) + 'static>(&self, f: F)
55 -> SignalHandlerId;
56
57 fn connect_property_border_width_notify<F: Fn(&Self) + 'static>(&self, f: F)
58 -> SignalHandlerId;
59
60 fn connect_property_color_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
61
62 fn connect_property_has_border_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
63}
64
65impl<O: IsA<Rectangle>> RectangleExt for O {
66 fn get_property_border_color(&self) -> Option<Color> {
67 unsafe {
68 let mut value = Value::from_type(<Color as StaticType>::static_type());
69 gobject_sys::g_object_get_property(
70 self.to_glib_none().0 as *mut gobject_sys::GObject,
71 b"border-color\0".as_ptr() as *const _,
72 value.to_glib_none_mut().0,
73 );
74 value
75 .get()
76 .expect("Return Value for property `border-color` getter")
77 }
78 }
79
80 fn set_property_border_color(&self, border_color: Option<&Color>) {
81 unsafe {
82 gobject_sys::g_object_set_property(
83 self.to_glib_none().0 as *mut gobject_sys::GObject,
84 b"border-color\0".as_ptr() as *const _,
85 Value::from(border_color).to_glib_none().0,
86 );
87 }
88 }
89
90 fn get_property_border_width(&self) -> u32 {
91 unsafe {
92 let mut value = Value::from_type(<u32 as StaticType>::static_type());
93 gobject_sys::g_object_get_property(
94 self.to_glib_none().0 as *mut gobject_sys::GObject,
95 b"border-width\0".as_ptr() as *const _,
96 value.to_glib_none_mut().0,
97 );
98 value
99 .get()
100 .expect("Return Value for property `border-width` getter")
101 .unwrap()
102 }
103 }
104
105 fn set_property_border_width(&self, border_width: u32) {
106 unsafe {
107 gobject_sys::g_object_set_property(
108 self.to_glib_none().0 as *mut gobject_sys::GObject,
109 b"border-width\0".as_ptr() as *const _,
110 Value::from(&border_width).to_glib_none().0,
111 );
112 }
113 }
114
115 fn get_property_color(&self) -> Option<Color> {
116 unsafe {
117 let mut value = Value::from_type(<Color as StaticType>::static_type());
118 gobject_sys::g_object_get_property(
119 self.to_glib_none().0 as *mut gobject_sys::GObject,
120 b"color\0".as_ptr() as *const _,
121 value.to_glib_none_mut().0,
122 );
123 value
124 .get()
125 .expect("Return Value for property `color` getter")
126 }
127 }
128
129 fn set_property_color(&self, color: Option<&Color>) {
130 unsafe {
131 gobject_sys::g_object_set_property(
132 self.to_glib_none().0 as *mut gobject_sys::GObject,
133 b"color\0".as_ptr() as *const _,
134 Value::from(color).to_glib_none().0,
135 );
136 }
137 }
138
139 fn get_property_has_border(&self) -> bool {
140 unsafe {
141 let mut value = Value::from_type(<bool as StaticType>::static_type());
142 gobject_sys::g_object_get_property(
143 self.to_glib_none().0 as *mut gobject_sys::GObject,
144 b"has-border\0".as_ptr() as *const _,
145 value.to_glib_none_mut().0,
146 );
147 value
148 .get()
149 .expect("Return Value for property `has-border` getter")
150 .unwrap()
151 }
152 }
153
154 fn set_property_has_border(&self, has_border: bool) {
155 unsafe {
156 gobject_sys::g_object_set_property(
157 self.to_glib_none().0 as *mut gobject_sys::GObject,
158 b"has-border\0".as_ptr() as *const _,
159 Value::from(&has_border).to_glib_none().0,
160 );
161 }
162 }
163
164 fn connect_property_border_color_notify<F: Fn(&Self) + 'static>(
165 &self,
166 f: F,
167 ) -> SignalHandlerId {
168 unsafe extern "C" fn notify_border_color_trampoline<P, F: Fn(&P) + 'static>(
169 this: *mut ffi::ClutterRectangle,
170 _param_spec: glib_sys::gpointer,
171 f: glib_sys::gpointer,
172 ) where
173 P: IsA<Rectangle>,
174 {
175 let f: &F = &*(f as *const F);
176 f(&Rectangle::from_glib_borrow(this).unsafe_cast_ref())
177 }
178 unsafe {
179 let f: Box_<F> = Box_::new(f);
180 connect_raw(
181 self.as_ptr() as *mut _,
182 b"notify::border-color\0".as_ptr() as *const _,
183 Some(transmute::<_, unsafe extern "C" fn()>(
184 notify_border_color_trampoline::<Self, F> as *const (),
185 )),
186 Box_::into_raw(f),
187 )
188 }
189 }
190
191 fn connect_property_border_width_notify<F: Fn(&Self) + 'static>(
192 &self,
193 f: F,
194 ) -> SignalHandlerId {
195 unsafe extern "C" fn notify_border_width_trampoline<P, F: Fn(&P) + 'static>(
196 this: *mut ffi::ClutterRectangle,
197 _param_spec: glib_sys::gpointer,
198 f: glib_sys::gpointer,
199 ) where
200 P: IsA<Rectangle>,
201 {
202 let f: &F = &*(f as *const F);
203 f(&Rectangle::from_glib_borrow(this).unsafe_cast_ref())
204 }
205 unsafe {
206 let f: Box_<F> = Box_::new(f);
207 connect_raw(
208 self.as_ptr() as *mut _,
209 b"notify::border-width\0".as_ptr() as *const _,
210 Some(transmute::<_, unsafe extern "C" fn()>(
211 notify_border_width_trampoline::<Self, F> as *const (),
212 )),
213 Box_::into_raw(f),
214 )
215 }
216 }
217
218 fn connect_property_color_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
219 unsafe extern "C" fn notify_color_trampoline<P, F: Fn(&P) + 'static>(
220 this: *mut ffi::ClutterRectangle,
221 _param_spec: glib_sys::gpointer,
222 f: glib_sys::gpointer,
223 ) where
224 P: IsA<Rectangle>,
225 {
226 let f: &F = &*(f as *const F);
227 f(&Rectangle::from_glib_borrow(this).unsafe_cast_ref())
228 }
229 unsafe {
230 let f: Box_<F> = Box_::new(f);
231 connect_raw(
232 self.as_ptr() as *mut _,
233 b"notify::color\0".as_ptr() as *const _,
234 Some(transmute::<_, unsafe extern "C" fn()>(
235 notify_color_trampoline::<Self, F> as *const (),
236 )),
237 Box_::into_raw(f),
238 )
239 }
240 }
241
242 fn connect_property_has_border_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
243 unsafe extern "C" fn notify_has_border_trampoline<P, F: Fn(&P) + 'static>(
244 this: *mut ffi::ClutterRectangle,
245 _param_spec: glib_sys::gpointer,
246 f: glib_sys::gpointer,
247 ) where
248 P: IsA<Rectangle>,
249 {
250 let f: &F = &*(f as *const F);
251 f(&Rectangle::from_glib_borrow(this).unsafe_cast_ref())
252 }
253 unsafe {
254 let f: Box_<F> = Box_::new(f);
255 connect_raw(
256 self.as_ptr() as *mut _,
257 b"notify::has-border\0".as_ptr() as *const _,
258 Some(transmute::<_, unsafe extern "C" fn()>(
259 notify_has_border_trampoline::<Self, F> as *const (),
260 )),
261 Box_::into_raw(f),
262 )
263 }
264 }
265}
266
267impl fmt::Display for Rectangle {
268 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
269 write!(f, "Rectangle")
270 }
271}