1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files.git)
// DO NOT EDIT

use crate::{ffi, NavigationDirection};
use glib::{prelude::*, translate::*};

glib::wrapper! {
    /// An interface for swipeable widgets.
    ///
    /// The `BisSwipeable` interface is implemented by all swipeable widgets.
    ///
    /// See [`SwipeTracker`][crate::SwipeTracker] for details about implementing it.
    ///
    /// # Implements
    ///
    /// [`SwipeableExt`][trait@crate::prelude::SwipeableExt], [`trait@gtk::prelude::WidgetExt`], [`trait@glib::ObjectExt`], [`trait@gtk::prelude::AccessibleExt`], [`trait@gtk::prelude::BuildableExt`], [`trait@gtk::prelude::ConstraintTargetExt`]
    #[doc(alias = "BisSwipeable")]
    pub struct Swipeable(Interface<ffi::BisSwipeable, ffi::BisSwipeableInterface>) @requires gtk::Widget, gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;

    match fn {
        type_ => || ffi::bis_swipeable_get_type(),
    }
}

impl Swipeable {
    pub const NONE: Option<&'static Swipeable> = None;
}

mod sealed {
    pub trait Sealed {}
    impl<T: super::IsA<super::Swipeable>> Sealed for T {}
}

/// Trait containing all [`struct@Swipeable`] methods.
///
/// # Implementors
///
/// [`Album`][struct@crate::Album], [`Carousel`][struct@crate::Carousel], [`Lapel`][struct@crate::Lapel], [`Swipeable`][struct@crate::Swipeable]
pub trait SwipeableExt: IsA<Swipeable> + sealed::Sealed + 'static {
    /// Gets the progress @self will snap back to after the gesture is canceled.
    ///
    /// # Returns
    ///
    /// the cancel progress, unitless
    #[doc(alias = "bis_swipeable_get_cancel_progress")]
    #[doc(alias = "get_cancel_progress")]
    fn cancel_progress(&self) -> f64 {
        unsafe { ffi::bis_swipeable_get_cancel_progress(self.as_ref().to_glib_none().0) }
    }

    /// Gets the swipe distance of @self.
    ///
    /// This corresponds to how many pixels 1 unit represents.
    ///
    /// # Returns
    ///
    /// the swipe distance in pixels
    #[doc(alias = "bis_swipeable_get_distance")]
    #[doc(alias = "get_distance")]
    fn distance(&self) -> f64 {
        unsafe { ffi::bis_swipeable_get_distance(self.as_ref().to_glib_none().0) }
    }

    /// Gets the current progress of @self.
    ///
    /// # Returns
    ///
    /// the current progress, unitless
    #[doc(alias = "bis_swipeable_get_progress")]
    #[doc(alias = "get_progress")]
    fn progress(&self) -> f64 {
        unsafe { ffi::bis_swipeable_get_progress(self.as_ref().to_glib_none().0) }
    }

    /// Gets the snap points of @self.
    ///
    /// Each snap point represents a progress value that is considered acceptable to
    /// end the swipe on.
    ///
    /// # Returns
    ///
    /// the snap points
    #[doc(alias = "bis_swipeable_get_snap_points")]
    #[doc(alias = "get_snap_points")]
    fn snap_points(&self) -> Vec<f64> {
        unsafe {
            let mut n_snap_points = std::mem::MaybeUninit::uninit();
            let ret = FromGlibContainer::from_glib_full_num(
                ffi::bis_swipeable_get_snap_points(
                    self.as_ref().to_glib_none().0,
                    n_snap_points.as_mut_ptr(),
                ),
                n_snap_points.assume_init() as _,
            );
            ret
        }
    }

    /// Gets the area @self can start a swipe from for the given direction and
    /// gesture type.
    ///
    /// This can be used to restrict swipes to only be possible from a certain area,
    /// for example, to only allow edge swipes, or to have a draggable element and
    /// ignore swipes elsewhere.
    ///
    /// If not implemented, the default implementation returns the allocation of
    /// @self, allowing swipes from anywhere.
    /// ## `navigation_direction`
    /// the direction of the swipe
    /// ## `is_drag`
    /// whether the swipe is caused by a dragging gesture
    ///
    /// # Returns
    ///
    ///
    /// ## `rect`
    /// a pointer to a rectangle to store the swipe area
    #[doc(alias = "bis_swipeable_get_swipe_area")]
    #[doc(alias = "get_swipe_area")]
    fn swipe_area(
        &self,
        navigation_direction: NavigationDirection,
        is_drag: bool,
    ) -> gdk::Rectangle {
        unsafe {
            let mut rect = gdk::Rectangle::uninitialized();
            ffi::bis_swipeable_get_swipe_area(
                self.as_ref().to_glib_none().0,
                navigation_direction.into_glib(),
                is_drag.into_glib(),
                rect.to_glib_none_mut().0,
            );
            rect
        }
    }
}

impl<O: IsA<Swipeable>> SwipeableExt for O {}