Skip to main content

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