clutter/auto/
actor_box.rs

1use glib::translate::*;
2use std::mem;
3
4glib_wrapper! {
5    #[derive(Debug, PartialOrd, Ord)] // Hash
6    pub struct ActorBox(Boxed<ffi::ClutterActorBox>);
7
8    match fn {
9        copy => |ptr| ffi::clutter_actor_box_copy(mut_override(ptr)),
10        free => |ptr| ffi::clutter_actor_box_free(ptr),
11        get_type => || ffi::clutter_actor_box_get_type(),
12    }
13}
14
15impl ActorBox {
16    /// Allocates a new `ActorBox` using the passed coordinates
17    /// for the top left and bottom right points.
18    ///
19    /// This function is the logical equivalent of:
20    ///
21    ///
22    /// ```text
23    ///   clutter_actor_box_init (clutter_actor_box_alloc (),
24    ///                           x_1, y_1,
25    ///                           x_2, y_2);
26    /// ```
27    /// ## `x_1`
28    /// X coordinate of the top left point
29    /// ## `y_1`
30    /// Y coordinate of the top left point
31    /// ## `x_2`
32    /// X coordinate of the bottom right point
33    /// ## `y_2`
34    /// Y coordinate of the bottom right point
35    ///
36    /// # Returns
37    ///
38    /// the newly allocated `ActorBox`.
39    ///  Use `ActorBox::free` to free the resources
40    pub fn new(x_1: f32, y_1: f32, x_2: f32, y_2: f32) -> ActorBox {
41        unsafe { from_glib_full(ffi::clutter_actor_box_new(x_1, y_1, x_2, y_2)) }
42    }
43
44    //pub fn clamp_to_pixel(&self) {
45    //    unsafe { TODO: call clutter_sys:clutter_actor_box_clamp_to_pixel() }
46    //}
47
48    /// Checks whether a point with `x`, `y` coordinates is contained
49    /// withing `self`
50    /// ## `x`
51    /// X coordinate of the point
52    /// ## `y`
53    /// Y coordinate of the point
54    ///
55    /// # Returns
56    ///
57    /// `true` if the point is contained by the `ActorBox`
58    pub fn contains(&self, x: f32, y: f32) -> bool {
59        unsafe { from_glib(ffi::clutter_actor_box_contains(self.to_glib_none().0, x, y)) }
60    }
61
62    /// Checks `self` and `box_b` for equality
63    /// ## `box_b`
64    /// a `ActorBox`
65    ///
66    /// # Returns
67    ///
68    /// `true` if the passed `ActorBox` are equal
69    fn equal(&self, box_b: &ActorBox) -> bool {
70        unsafe {
71            from_glib(ffi::clutter_actor_box_equal(
72                self.to_glib_none().0,
73                box_b.to_glib_none().0,
74            ))
75        }
76    }
77
78    //pub fn from_vertices(&mut self, verts: /*Unimplemented*/FixedArray TypeId { ns_id: 1, id: 16 }; 4) {
79    //    unsafe { TODO: call clutter_sys:clutter_actor_box_from_vertices() }
80    //}
81
82    /// Retrieves the area of `self`
83    ///
84    /// # Returns
85    ///
86    /// the area of a `ActorBox`, in pixels
87    pub fn get_area(&self) -> f32 {
88        unsafe { ffi::clutter_actor_box_get_area(self.to_glib_none().0) }
89    }
90
91    /// Retrieves the height of the `self`
92    ///
93    /// # Returns
94    ///
95    /// the height of the box
96    pub fn get_height(&self) -> f32 {
97        unsafe { ffi::clutter_actor_box_get_height(self.to_glib_none().0) }
98    }
99
100    /// Retrieves the origin of `self`
101    /// ## `x`
102    /// return location for the X coordinate, or `None`
103    /// ## `y`
104    /// return location for the Y coordinate, or `None`
105    pub fn get_origin(&self) -> (f32, f32) {
106        unsafe {
107            let mut x = mem::MaybeUninit::uninit();
108            let mut y = mem::MaybeUninit::uninit();
109            ffi::clutter_actor_box_get_origin(
110                self.to_glib_none().0,
111                x.as_mut_ptr(),
112                y.as_mut_ptr(),
113            );
114            let x = x.assume_init();
115            let y = y.assume_init();
116            (x, y)
117        }
118    }
119
120    /// Retrieves the size of `self`
121    /// ## `width`
122    /// return location for the width, or `None`
123    /// ## `height`
124    /// return location for the height, or `None`
125    pub fn get_size(&self) -> (f32, f32) {
126        unsafe {
127            let mut width = mem::MaybeUninit::uninit();
128            let mut height = mem::MaybeUninit::uninit();
129            ffi::clutter_actor_box_get_size(
130                self.to_glib_none().0,
131                width.as_mut_ptr(),
132                height.as_mut_ptr(),
133            );
134            let width = width.assume_init();
135            let height = height.assume_init();
136            (width, height)
137        }
138    }
139
140    /// Retrieves the width of the `self`
141    ///
142    /// # Returns
143    ///
144    /// the width of the box
145    pub fn get_width(&self) -> f32 {
146        unsafe { ffi::clutter_actor_box_get_width(self.to_glib_none().0) }
147    }
148
149    /// Retrieves the X coordinate of the origin of `self`
150    ///
151    /// # Returns
152    ///
153    /// the X coordinate of the origin
154    pub fn get_x(&self) -> f32 {
155        unsafe { ffi::clutter_actor_box_get_x(self.to_glib_none().0) }
156    }
157
158    /// Retrieves the Y coordinate of the origin of `self`
159    ///
160    /// # Returns
161    ///
162    /// the Y coordinate of the origin
163    pub fn get_y(&self) -> f32 {
164        unsafe { ffi::clutter_actor_box_get_y(self.to_glib_none().0) }
165    }
166
167    /// Initializes `self` with the given coordinates.
168    /// ## `x_1`
169    /// X coordinate of the top left point
170    /// ## `y_1`
171    /// Y coordinate of the top left point
172    /// ## `x_2`
173    /// X coordinate of the bottom right point
174    /// ## `y_2`
175    /// Y coordinate of the bottom right point
176    ///
177    /// # Returns
178    ///
179    /// the initialized `ActorBox`
180    pub fn init(&mut self, x_1: f32, y_1: f32, x_2: f32, y_2: f32) -> Option<ActorBox> {
181        unsafe {
182            from_glib_none(ffi::clutter_actor_box_init(
183                self.to_glib_none_mut().0,
184                x_1,
185                y_1,
186                x_2,
187                y_2,
188            ))
189        }
190    }
191
192    /// Initializes `self` with the given origin and size.
193    /// ## `x`
194    /// X coordinate of the origin
195    /// ## `y`
196    /// Y coordinate of the origin
197    /// ## `width`
198    /// width of the box
199    /// ## `height`
200    /// height of the box
201    pub fn init_rect(&mut self, x: f32, y: f32, width: f32, height: f32) {
202        unsafe {
203            ffi::clutter_actor_box_init_rect(self.to_glib_none_mut().0, x, y, width, height);
204        }
205    }
206
207    /// Interpolates between `self` and `final_` `ActorBox`<!-- -->es
208    /// using `progress`
209    /// ## `final_`
210    /// the final `ActorBox`
211    /// ## `progress`
212    /// the interpolation progress
213    /// ## `result`
214    /// return location for the interpolation
215    pub fn interpolate(&self, final_: &ActorBox, progress: f64) -> ActorBox {
216        unsafe {
217            let mut result = ActorBox::uninitialized();
218            ffi::clutter_actor_box_interpolate(
219                self.to_glib_none().0,
220                final_.to_glib_none().0,
221                progress,
222                result.to_glib_none_mut().0,
223            );
224            result
225        }
226    }
227
228    /// Changes the origin of `self`, maintaining the size of the `ActorBox`.
229    /// ## `x`
230    /// the X coordinate of the new origin
231    /// ## `y`
232    /// the Y coordinate of the new origin
233    pub fn set_origin(&mut self, x: f32, y: f32) {
234        unsafe {
235            ffi::clutter_actor_box_set_origin(self.to_glib_none_mut().0, x, y);
236        }
237    }
238
239    /// Sets the size of `self`, maintaining the origin of the `ActorBox`.
240    /// ## `width`
241    /// the new width
242    /// ## `height`
243    /// the new height
244    pub fn set_size(&mut self, width: f32, height: f32) {
245        unsafe {
246            ffi::clutter_actor_box_set_size(self.to_glib_none_mut().0, width, height);
247        }
248    }
249
250    /// Unions the two boxes `self` and `b` and stores the result in `result`.
251    /// ## `b`
252    /// the second `ActorBox`
253    /// ## `result`
254    /// the `ActorBox` representing a union
255    ///  of `self` and `b`
256    pub fn union(&self, b: &ActorBox) -> ActorBox {
257        unsafe {
258            let mut result = ActorBox::uninitialized();
259            ffi::clutter_actor_box_union(
260                self.to_glib_none().0,
261                b.to_glib_none().0,
262                result.to_glib_none_mut().0,
263            );
264            result
265        }
266    }
267
268    /// Allocates a new `ActorBox`.
269    ///
270    /// # Returns
271    ///
272    /// the newly allocated `ActorBox`.
273    ///  Use `ActorBox::free` to free its resources
274    pub fn alloc() -> Option<ActorBox> {
275        unsafe { from_glib_full(ffi::clutter_actor_box_alloc()) }
276    }
277}
278
279#[doc(hidden)]
280impl Uninitialized for ActorBox {
281    #[inline]
282    unsafe fn uninitialized() -> Self {
283        Self::alloc().unwrap()
284    }
285}
286
287impl PartialEq for ActorBox {
288    #[inline]
289    fn eq(&self, other: &Self) -> bool {
290        self.equal(other)
291    }
292}
293
294impl Eq for ActorBox {}