gdk/auto/rectangle.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use glib::translate::*;
6
7glib::wrapper! {
8 /// Defines the position and size of a rectangle. It is identical to
9 /// `cairo_rectangle_int_t`.
10 pub struct Rectangle(BoxedInline<ffi::GdkRectangle>);
11
12 match fn {
13 copy => |ptr| glib::gobject_ffi::g_boxed_copy(ffi::gdk_rectangle_get_type(), ptr as *mut _) as *mut ffi::GdkRectangle,
14 free => |ptr| glib::gobject_ffi::g_boxed_free(ffi::gdk_rectangle_get_type(), ptr as *mut _),
15 type_ => || ffi::gdk_rectangle_get_type(),
16 }
17}
18
19impl Rectangle {
20 #[doc(alias = "gdk_rectangle_equal")]
21 fn equal(&self, rect2: &Rectangle) -> bool {
22 unsafe {
23 from_glib(ffi::gdk_rectangle_equal(
24 self.to_glib_none().0,
25 rect2.to_glib_none().0,
26 ))
27 }
28 }
29
30 /// Calculates the intersection of two rectangles. It is allowed for
31 /// `dest` to be the same as either `self` or `src2`. If the rectangles
32 /// do not intersect, `dest`’s width and height is set to 0 and its x
33 /// and y values are undefined. If you are only interested in whether
34 /// the rectangles intersect, but not in the intersecting area itself,
35 /// pass [`None`] for `dest`.
36 /// ## `src2`
37 /// a [`Rectangle`][crate::Rectangle]
38 ///
39 /// # Returns
40 ///
41 /// [`true`] if the rectangles intersect.
42 ///
43 /// ## `dest`
44 /// return location for the
45 /// intersection of `self` and `src2`, or [`None`]
46 #[doc(alias = "gdk_rectangle_intersect")]
47 pub fn intersect(&self, src2: &Rectangle) -> Option<Rectangle> {
48 unsafe {
49 let mut dest = Rectangle::uninitialized();
50 let ret = from_glib(ffi::gdk_rectangle_intersect(
51 self.to_glib_none().0,
52 src2.to_glib_none().0,
53 dest.to_glib_none_mut().0,
54 ));
55 if ret {
56 Some(dest)
57 } else {
58 None
59 }
60 }
61 }
62
63 /// Calculates the union of two rectangles.
64 /// The union of rectangles `self` and `src2` is the smallest rectangle which
65 /// includes both `self` and `src2` within it.
66 /// It is allowed for `dest` to be the same as either `self` or `src2`.
67 ///
68 /// Note that this function does not ignore 'empty' rectangles (ie. with
69 /// zero width or height).
70 /// ## `src2`
71 /// a [`Rectangle`][crate::Rectangle]
72 ///
73 /// # Returns
74 ///
75 ///
76 /// ## `dest`
77 /// return location for the union of `self` and `src2`
78 #[doc(alias = "gdk_rectangle_union")]
79 #[must_use]
80 pub fn union(&self, src2: &Rectangle) -> Rectangle {
81 unsafe {
82 let mut dest = Rectangle::uninitialized();
83 ffi::gdk_rectangle_union(
84 self.to_glib_none().0,
85 src2.to_glib_none().0,
86 dest.to_glib_none_mut().0,
87 );
88 dest
89 }
90 }
91}
92
93impl PartialEq for Rectangle {
94 #[inline]
95 fn eq(&self, other: &Self) -> bool {
96 self.equal(other)
97 }
98}
99
100impl Eq for Rectangle {}