Skip to main content

gsk4/
rect_snap.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use crate::{Side, SnapDirection, ffi};
4use glib::translate::*;
5
6#[derive(Debug, Clone, Copy)]
7pub struct RectSnap(libc::c_uint);
8
9impl FromGlib<libc::c_uint> for RectSnap {
10    unsafe fn from_glib(value: libc::c_uint) -> Self {
11        Self(value)
12    }
13}
14
15impl IntoGlib for RectSnap {
16    type GlibType = libc::c_uint;
17
18    fn into_glib(self) -> libc::c_uint {
19        self.0
20    }
21}
22
23impl RectSnap {
24    #[cfg(feature = "v4_24")]
25    #[cfg_attr(docsrs, doc(cfg(feature = "v4_24")))]
26    #[doc(alias = "gsk_rect_snap_get_direction")]
27    #[doc(alias = "get_direction")]
28    pub fn direction(&self, side: Side) -> SnapDirection {
29        assert_initialized_main_thread!();
30        unsafe {
31            from_glib(ffi::gsk_rect_snap_get_direction(
32                self.into_glib(),
33                side.into_glib(),
34            ))
35        }
36    }
37
38    #[cfg(feature = "v4_24")]
39    #[cfg_attr(docsrs, doc(cfg(feature = "v4_24")))]
40    #[doc(alias = "gsk_rect_snap_new")]
41    pub fn new(
42        top: SnapDirection,
43        right: SnapDirection,
44        bottom: SnapDirection,
45        left: SnapDirection,
46    ) -> RectSnap {
47        assert_initialized_main_thread!();
48        unsafe {
49            from_glib(ffi::gsk_rect_snap_new(
50                top.into_glib(),
51                right.into_glib(),
52                bottom.into_glib(),
53                left.into_glib(),
54            ))
55        }
56    }
57}