gtk/auto/
gesture_swipe.rs1use gdk;
6use glib::object::Cast;
7use glib::object::IsA;
8use glib::object::ObjectType as ObjectType_;
9use glib::signal::connect_raw;
10use glib::signal::SignalHandlerId;
11use glib::translate::*;
12use glib::StaticType;
13use glib::ToValue;
14use glib_sys;
15use gtk_sys;
16use libc;
17use std::boxed::Box as Box_;
18use std::fmt;
19use std::mem;
20use std::mem::transmute;
21use EventController;
22use Gesture;
23use GestureSingle;
24use PropagationPhase;
25use Widget;
26
27glib_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
35impl GestureSwipe {
36 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
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
63 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
85pub 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
95impl GestureSwipeBuilder {
96 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
108 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
137 pub fn button(mut self, button: u32) -> Self {
138 self.button = Some(button);
139 self
140 }
141
142 pub fn exclusive(mut self, exclusive: bool) -> Self {
143 self.exclusive = Some(exclusive);
144 self
145 }
146
147 pub fn touch_only(mut self, touch_only: bool) -> Self {
148 self.touch_only = Some(touch_only);
149 self
150 }
151
152 pub fn n_points(mut self, n_points: u32) -> Self {
153 self.n_points = Some(n_points);
154 self
155 }
156
157 pub fn window(mut self, window: &gdk::Window) -> Self {
158 self.window = Some(window.clone());
159 self
160 }
161
162 pub fn propagation_phase(mut self, propagation_phase: PropagationPhase) -> Self {
163 self.propagation_phase = Some(propagation_phase);
164 self
165 }
166
167 pub fn widget(mut self, widget: &Widget) -> Self {
168 self.widget = Some(widget.clone());
169 self
170 }
171}
172
173impl fmt::Display for GestureSwipe {
174 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
175 write!(f, "GestureSwipe")
176 }
177}