animate/legacy/
rectangle.rs

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