Skip to main content

gtk/
border.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use glib::translate::*;
4use std::fmt;
5use std::ops;
6
7glib::wrapper! {
8    /// A struct that specifies a border around a rectangular area
9    /// that can be of different width on each side.
10    #[doc(alias = "GtkBorder")]
11    pub struct Border(BoxedInline<ffi::GtkBorder>);
12
13    match fn {
14        copy => |ptr| ffi::gtk_border_copy(mut_override(ptr)),
15        free => |ptr| ffi::gtk_border_free(ptr),
16        type_ => || ffi::gtk_border_get_type(),
17    }
18}
19
20impl ops::Deref for Border {
21    type Target = ffi::GtkBorder;
22
23    fn deref(&self) -> &Self::Target {
24        &self.inner
25    }
26}
27
28impl ops::DerefMut for Border {
29    fn deref_mut(&mut self) -> &mut Self::Target {
30        &mut self.inner
31    }
32}
33
34impl Border {
35    /// Allocates a new [`Border`][crate::Border]-struct and initializes its elements to zero.
36    ///
37    /// # Returns
38    ///
39    /// a newly allocated [`Border`][crate::Border]-struct.
40    ///  Free with `gtk_border_free()`
41    #[doc(alias = "gtk_border_new")]
42    pub fn new() -> Self {
43        assert_initialized_main_thread!();
44        unsafe { from_glib_full(ffi::gtk_border_new()) }
45    }
46}
47
48impl Default for Border {
49    fn default() -> Self {
50        Self::new()
51    }
52}
53
54impl fmt::Debug for Border {
55    fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
56        fmt.debug_struct("Border")
57            .field("left", &self.left)
58            .field("right", &self.right)
59            .field("top", &self.top)
60            .field("bottom", &self.bottom)
61            .finish()
62    }
63}
64
65impl PartialEq for Border {
66    fn eq(&self, other: &Self) -> bool {
67        self.left == other.left
68            && self.right == other.right
69            && self.top == other.top
70            && self.bottom == other.bottom
71    }
72}
73
74impl Eq for Border {}