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