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 /// Represents a rectangle.
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 { Some(dest) } else { None }
91 }
92 }
93
94 /// Calculates the union of two rectangles.
95 ///
96 /// The union of rectangles @self and @src2 is the smallest rectangle which
97 /// includes both @self and @src2 within it. It is allowed for @dest to be
98 /// the same as either @self or @src2.
99 ///
100 /// Note that this function does not ignore 'empty' rectangles (ie. with
101 /// zero width or height).
102 /// ## `src2`
103 /// a [`Rectangle`][crate::Rectangle]
104 ///
105 /// # Returns
106 ///
107 ///
108 /// ## `dest`
109 /// return location for the union of @self and @src2
110 #[doc(alias = "gdk_rectangle_union")]
111 #[must_use]
112 pub fn union(&self, src2: &Rectangle) -> Rectangle {
113 unsafe {
114 let mut dest = Rectangle::uninitialized();
115 ffi::gdk_rectangle_union(
116 self.to_glib_none().0,
117 src2.to_glib_none().0,
118 dest.to_glib_none_mut().0,
119 );
120 dest
121 }
122 }
123}
124
125impl PartialEq for Rectangle {
126 #[inline]
127 fn eq(&self, other: &Self) -> bool {
128 self.equal(other)
129 }
130}
131
132impl Eq for Rectangle {}