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