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 
5 use gdk;
6 use glib::object::Cast;
7 use glib::object::IsA;
8 use glib::object::ObjectType as ObjectType_;
9 use glib::signal::connect_raw;
10 use glib::signal::SignalHandlerId;
11 use glib::translate::*;
12 use glib::StaticType;
13 use glib::ToValue;
14 use glib_sys;
15 use gtk_sys;
16 use libc;
17 use std::boxed::Box as Box_;
18 use std::fmt;
19 use std::mem;
20 use std::mem::transmute;
21 use EventController;
22 use Gesture;
23 use GestureSingle;
24 use PropagationPhase;
25 use Widget;
26 
27 glib_wrapper! {
28     pub struct GestureSwipe(Object<gtk_sys::GtkGestureSwipe, gtk_sys::GtkGestureSwipeClass, GestureSwipeClass>) @extends GestureSingle, Gesture, EventController;
29 
30     match fn {
31         get_type => || gtk_sys::gtk_gesture_swipe_get_type(),
32     }
33 }
34 
35 impl GestureSwipe {
new<P: IsA<Widget>>(widget: &P) -> GestureSwipe36     pub fn new<P: IsA<Widget>>(widget: &P) -> GestureSwipe {
37         skip_assert_initialized!();
38         unsafe {
39             Gesture::from_glib_full(gtk_sys::gtk_gesture_swipe_new(
40                 widget.as_ref().to_glib_none().0,
41             ))
42             .unsafe_cast()
43         }
44     }
45 
get_velocity(&self) -> Option<(f64, f64)>46     pub fn get_velocity(&self) -> Option<(f64, f64)> {
47         unsafe {
48             let mut velocity_x = mem::uninitialized();
49             let mut velocity_y = mem::uninitialized();
50             let ret = from_glib(gtk_sys::gtk_gesture_swipe_get_velocity(
51                 self.to_glib_none().0,
52                 &mut velocity_x,
53                 &mut velocity_y,
54             ));
55             if ret {
56                 Some((velocity_x, velocity_y))
57             } else {
58                 None
59             }
60         }
61     }
62 
connect_swipe<F: Fn(&GestureSwipe, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId63     pub fn connect_swipe<F: Fn(&GestureSwipe, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
64         unsafe extern "C" fn swipe_trampoline<F: Fn(&GestureSwipe, f64, f64) + 'static>(
65             this: *mut gtk_sys::GtkGestureSwipe,
66             velocity_x: libc::c_double,
67             velocity_y: libc::c_double,
68             f: glib_sys::gpointer,
69         ) {
70             let f: &F = &*(f as *const F);
71             f(&from_glib_borrow(this), velocity_x, velocity_y)
72         }
73         unsafe {
74             let f: Box_<F> = Box_::new(f);
75             connect_raw(
76                 self.as_ptr() as *mut _,
77                 b"swipe\0".as_ptr() as *const _,
78                 Some(transmute(swipe_trampoline::<F> as usize)),
79                 Box_::into_raw(f),
80             )
81         }
82     }
83 }
84 
85 pub struct GestureSwipeBuilder {
86     button: Option<u32>,
87     exclusive: Option<bool>,
88     touch_only: Option<bool>,
89     n_points: Option<u32>,
90     window: Option<gdk::Window>,
91     propagation_phase: Option<PropagationPhase>,
92     widget: Option<Widget>,
93 }
94 
95 impl GestureSwipeBuilder {
new() -> Self96     pub fn new() -> Self {
97         Self {
98             button: None,
99             exclusive: None,
100             touch_only: None,
101             n_points: None,
102             window: None,
103             propagation_phase: None,
104             widget: None,
105         }
106     }
107 
build(self) -> GestureSwipe108     pub fn build(self) -> GestureSwipe {
109         let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
110         if let Some(ref button) = self.button {
111             properties.push(("button", button));
112         }
113         if let Some(ref exclusive) = self.exclusive {
114             properties.push(("exclusive", exclusive));
115         }
116         if let Some(ref touch_only) = self.touch_only {
117             properties.push(("touch-only", touch_only));
118         }
119         if let Some(ref n_points) = self.n_points {
120             properties.push(("n-points", n_points));
121         }
122         if let Some(ref window) = self.window {
123             properties.push(("window", window));
124         }
125         if let Some(ref propagation_phase) = self.propagation_phase {
126             properties.push(("propagation-phase", propagation_phase));
127         }
128         if let Some(ref widget) = self.widget {
129             properties.push(("widget", widget));
130         }
131         glib::Object::new(GestureSwipe::static_type(), &properties)
132             .expect("object new")
133             .downcast()
134             .expect("downcast")
135     }
136 
button(mut self, button: u32) -> Self137     pub fn button(mut self, button: u32) -> Self {
138         self.button = Some(button);
139         self
140     }
141 
exclusive(mut self, exclusive: bool) -> Self142     pub fn exclusive(mut self, exclusive: bool) -> Self {
143         self.exclusive = Some(exclusive);
144         self
145     }
146 
touch_only(mut self, touch_only: bool) -> Self147     pub fn touch_only(mut self, touch_only: bool) -> Self {
148         self.touch_only = Some(touch_only);
149         self
150     }
151 
n_points(mut self, n_points: u32) -> Self152     pub fn n_points(mut self, n_points: u32) -> Self {
153         self.n_points = Some(n_points);
154         self
155     }
156 
window(mut self, window: &gdk::Window) -> Self157     pub fn window(mut self, window: &gdk::Window) -> Self {
158         self.window = Some(window.clone());
159         self
160     }
161 
propagation_phase(mut self, propagation_phase: PropagationPhase) -> Self162     pub fn propagation_phase(mut self, propagation_phase: PropagationPhase) -> Self {
163         self.propagation_phase = Some(propagation_phase);
164         self
165     }
166 
widget(mut self, widget: &Widget) -> Self167     pub fn widget(mut self, widget: &Widget) -> Self {
168         self.widget = Some(widget.clone());
169         self
170     }
171 }
172 
173 impl fmt::Display for GestureSwipe {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result174     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
175         write!(f, "GestureSwipe")
176     }
177 }
178