gdk4/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 /// A [`Rectangle`][crate::Rectangle] data type for representing rectangles.
10 ///
11 /// [`Rectangle`][crate::Rectangle] is identical to `cairo_rectangle_t`. Together with Cairo’s
12 /// [`cairo::Region`][crate::cairo::Region] data type, these are the central types for representing
13 /// sets of pixels.
14 ///
15 /// The intersection of two rectangles can be computed with
16 /// [`intersect()`][Self::intersect()]; to find the union of two rectangles use
17 /// [`union()`][Self::union()].
18 ///
19 /// The [`cairo::Region`][crate::cairo::Region] type provided by Cairo is usually used for managing
20 /// non-rectangular clipping of graphical operations.
21 ///
22 /// The Graphene library has a number of other data types for regions and
23 /// volumes in 2D and 3D.
24 pub struct Rectangle(BoxedInline<ffi::GdkRectangle>);
25
26 match fn {
27 copy => |ptr| glib::gobject_ffi::g_boxed_copy(ffi::gdk_rectangle_get_type(), ptr as *mut _) as *mut ffi::GdkRectangle,
28 free => |ptr| glib::gobject_ffi::g_boxed_free(ffi::gdk_rectangle_get_type(), ptr as *mut _),
29 type_ => || ffi::gdk_rectangle_get_type(),
30 }
31}
32
33impl Rectangle {
34 /// Returns [`true`] if @self contains the point described by @x and @y.
35 /// ## `x`
36 /// X coordinate
37 /// ## `y`
38 /// Y coordinate
39 ///
40 /// # Returns
41 ///
42 /// [`true`] if @self contains the point
43 #[doc(alias = "gdk_rectangle_contains_point")]
44 pub fn contains_point(&self, x: i32, y: i32) -> bool {
45 unsafe {
46 from_glib(ffi::gdk_rectangle_contains_point(
47 self.to_glib_none().0,
48 x,
49 y,
50 ))
51 }
52 }
53
54 #[doc(alias = "gdk_rectangle_equal")]
55 fn equal(&self, rect2: &Rectangle) -> bool {
56 unsafe {
57 from_glib(ffi::gdk_rectangle_equal(
58 self.to_glib_none().0,
59 rect2.to_glib_none().0,
60 ))
61 }
62 }
63
64 /// Calculates the intersection of two rectangles.
65 ///
66 /// It is allowed for @dest to be the same as either @self or @src2.
67 /// If the rectangles do not intersect, @dest’s width and height is set
68 /// to 0 and its x and y values are undefined. If you are only interested
69 /// in whether the rectangles intersect, but not in the intersecting area
70 /// itself, pass [`None`] for @dest.
71 /// ## `src2`
72 /// a [`Rectangle`][crate::Rectangle]
73 ///
74 /// # Returns
75 ///
76 /// [`true`] if the rectangles intersect.
77 ///
78 /// ## `dest`
79 /// return location for the
80 /// intersection of @self and @src2
81 #[doc(alias = "gdk_rectangle_intersect")]
82 pub fn intersect(&self, src2: &Rectangle) -> Option<Rectangle> {
83 unsafe {
84 let mut dest = Rectangle::uninitialized();
85 let ret = from_glib(ffi::gdk_rectangle_intersect(
86 self.to_glib_none().0,
87 src2.to_glib_none().0,
88 dest.to_glib_none_mut().0,
89 ));
90 if ret {
91 Some(dest)
92 } else {
93 None
94 }
95 }
96 }
97
98 /// Calculates the union of two rectangles.
99 ///
100 /// The union of rectangles @self and @src2 is the smallest rectangle which
101 /// includes both @self and @src2 within it. It is allowed for @dest to be
102 /// the same as either @self or @src2.
103 ///
104 /// Note that this function does not ignore 'empty' rectangles (ie. with
105 /// zero width or height).
106 /// ## `src2`
107 /// a [`Rectangle`][crate::Rectangle]
108 ///
109 /// # Returns
110 ///
111 ///
112 /// ## `dest`
113 /// return location for the union of @self and @src2
114 #[doc(alias = "gdk_rectangle_union")]
115 #[must_use]
116 pub fn union(&self, src2: &Rectangle) -> Rectangle {
117 unsafe {
118 let mut dest = Rectangle::uninitialized();
119 ffi::gdk_rectangle_union(
120 self.to_glib_none().0,
121 src2.to_glib_none().0,
122 dest.to_glib_none_mut().0,
123 );
124 dest
125 }
126 }
127}
128
129impl PartialEq for Rectangle {
130 #[inline]
131 fn eq(&self, other: &Self) -> bool {
132 self.equal(other)
133 }
134}
135
136impl Eq for Rectangle {}