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::MaybeUninit::uninit(); 49 let mut velocity_y = mem::MaybeUninit::uninit(); 50 let ret = from_glib(gtk_sys::gtk_gesture_swipe_get_velocity( 51 self.to_glib_none().0, 52 velocity_x.as_mut_ptr(), 53 velocity_y.as_mut_ptr(), 54 )); 55 let velocity_x = velocity_x.assume_init(); 56 let velocity_y = velocity_y.assume_init(); 57 if ret { 58 Some((velocity_x, velocity_y)) 59 } else { 60 None 61 } 62 } 63 } 64 connect_swipe<F: Fn(&GestureSwipe, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId65 pub fn connect_swipe<F: Fn(&GestureSwipe, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId { 66 unsafe extern "C" fn swipe_trampoline<F: Fn(&GestureSwipe, f64, f64) + 'static>( 67 this: *mut gtk_sys::GtkGestureSwipe, 68 velocity_x: libc::c_double, 69 velocity_y: libc::c_double, 70 f: glib_sys::gpointer, 71 ) { 72 let f: &F = &*(f as *const F); 73 f(&from_glib_borrow(this), velocity_x, velocity_y) 74 } 75 unsafe { 76 let f: Box_<F> = Box_::new(f); 77 connect_raw( 78 self.as_ptr() as *mut _, 79 b"swipe\0".as_ptr() as *const _, 80 Some(transmute(swipe_trampoline::<F> as usize)), 81 Box_::into_raw(f), 82 ) 83 } 84 } 85 } 86 87 #[derive(Clone, Default)] 88 pub struct GestureSwipeBuilder { 89 button: Option<u32>, 90 exclusive: Option<bool>, 91 touch_only: Option<bool>, 92 n_points: Option<u32>, 93 window: Option<gdk::Window>, 94 propagation_phase: Option<PropagationPhase>, 95 widget: Option<Widget>, 96 } 97 98 impl GestureSwipeBuilder { new() -> Self99 pub fn new() -> Self { 100 Self::default() 101 } 102 build(self) -> GestureSwipe103 pub fn build(self) -> GestureSwipe { 104 let mut properties: Vec<(&str, &dyn ToValue)> = vec![]; 105 if let Some(ref button) = self.button { 106 properties.push(("button", button)); 107 } 108 if let Some(ref exclusive) = self.exclusive { 109 properties.push(("exclusive", exclusive)); 110 } 111 if let Some(ref touch_only) = self.touch_only { 112 properties.push(("touch-only", touch_only)); 113 } 114 if let Some(ref n_points) = self.n_points { 115 properties.push(("n-points", n_points)); 116 } 117 if let Some(ref window) = self.window { 118 properties.push(("window", window)); 119 } 120 if let Some(ref propagation_phase) = self.propagation_phase { 121 properties.push(("propagation-phase", propagation_phase)); 122 } 123 if let Some(ref widget) = self.widget { 124 properties.push(("widget", widget)); 125 } 126 glib::Object::new(GestureSwipe::static_type(), &properties) 127 .expect("object new") 128 .downcast() 129 .expect("downcast") 130 } 131 button(mut self, button: u32) -> Self132 pub fn button(mut self, button: u32) -> Self { 133 self.button = Some(button); 134 self 135 } 136 exclusive(mut self, exclusive: bool) -> Self137 pub fn exclusive(mut self, exclusive: bool) -> Self { 138 self.exclusive = Some(exclusive); 139 self 140 } 141 touch_only(mut self, touch_only: bool) -> Self142 pub fn touch_only(mut self, touch_only: bool) -> Self { 143 self.touch_only = Some(touch_only); 144 self 145 } 146 n_points(mut self, n_points: u32) -> Self147 pub fn n_points(mut self, n_points: u32) -> Self { 148 self.n_points = Some(n_points); 149 self 150 } 151 window<P: IsA<gdk::Window>>(mut self, window: &P) -> Self152 pub fn window<P: IsA<gdk::Window>>(mut self, window: &P) -> Self { 153 self.window = Some(window.clone().upcast()); 154 self 155 } 156 propagation_phase(mut self, propagation_phase: PropagationPhase) -> Self157 pub fn propagation_phase(mut self, propagation_phase: PropagationPhase) -> Self { 158 self.propagation_phase = Some(propagation_phase); 159 self 160 } 161 widget<P: IsA<Widget>>(mut self, widget: &P) -> Self162 pub fn widget<P: IsA<Widget>>(mut self, widget: &P) -> Self { 163 self.widget = Some(widget.clone().upcast()); 164 self 165 } 166 } 167 168 impl fmt::Display for GestureSwipe { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result169 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 170 write!(f, "GestureSwipe") 171 } 172 } 173