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 crate::EventController; 6 use crate::Gesture; 7 use crate::GestureDrag; 8 use crate::GestureSingle; 9 use crate::Orientation; 10 use crate::PanDirection; 11 use crate::PropagationPhase; 12 use crate::Widget; 13 use glib::object::Cast; 14 use glib::object::IsA; 15 use glib::object::ObjectType as ObjectType_; 16 use glib::signal::connect_raw; 17 use glib::signal::SignalHandlerId; 18 use glib::translate::*; 19 use glib::StaticType; 20 use glib::ToValue; 21 use std::boxed::Box as Box_; 22 use std::fmt; 23 use std::mem::transmute; 24 25 glib::wrapper! { 26 #[doc(alias = "GtkGesturePan")] 27 pub struct GesturePan(Object<ffi::GtkGesturePan, ffi::GtkGesturePanClass>) @extends GestureDrag, GestureSingle, Gesture, EventController; 28 29 match fn { 30 type_ => || ffi::gtk_gesture_pan_get_type(), 31 } 32 } 33 34 impl GesturePan { 35 #[doc(alias = "gtk_gesture_pan_new")] new<P: IsA<Widget>>(widget: &P, orientation: Orientation) -> GesturePan36 pub fn new<P: IsA<Widget>>(widget: &P, orientation: Orientation) -> GesturePan { 37 skip_assert_initialized!(); 38 unsafe { 39 Gesture::from_glib_full(ffi::gtk_gesture_pan_new( 40 widget.as_ref().to_glib_none().0, 41 orientation.into_glib(), 42 )) 43 .unsafe_cast() 44 } 45 } 46 47 // rustdoc-stripper-ignore-next 48 /// Creates a new builder-pattern struct instance to construct [`GesturePan`] objects. 49 /// 50 /// This method returns an instance of [`GesturePanBuilder`] which can be used to create [`GesturePan`] objects. builder() -> GesturePanBuilder51 pub fn builder() -> GesturePanBuilder { 52 GesturePanBuilder::default() 53 } 54 55 #[doc(alias = "gtk_gesture_pan_get_orientation")] 56 #[doc(alias = "get_orientation")] orientation(&self) -> Orientation57 pub fn orientation(&self) -> Orientation { 58 unsafe { from_glib(ffi::gtk_gesture_pan_get_orientation(self.to_glib_none().0)) } 59 } 60 61 #[doc(alias = "gtk_gesture_pan_set_orientation")] set_orientation(&self, orientation: Orientation)62 pub fn set_orientation(&self, orientation: Orientation) { 63 unsafe { 64 ffi::gtk_gesture_pan_set_orientation(self.to_glib_none().0, orientation.into_glib()); 65 } 66 } 67 68 #[doc(alias = "pan")] connect_pan<F: Fn(&Self, PanDirection, f64) + 'static>(&self, f: F) -> SignalHandlerId69 pub fn connect_pan<F: Fn(&Self, PanDirection, f64) + 'static>(&self, f: F) -> SignalHandlerId { 70 unsafe extern "C" fn pan_trampoline<F: Fn(&GesturePan, PanDirection, f64) + 'static>( 71 this: *mut ffi::GtkGesturePan, 72 direction: ffi::GtkPanDirection, 73 offset: libc::c_double, 74 f: glib::ffi::gpointer, 75 ) { 76 let f: &F = &*(f as *const F); 77 f(&from_glib_borrow(this), from_glib(direction), offset) 78 } 79 unsafe { 80 let f: Box_<F> = Box_::new(f); 81 connect_raw( 82 self.as_ptr() as *mut _, 83 b"pan\0".as_ptr() as *const _, 84 Some(transmute::<_, unsafe extern "C" fn()>( 85 pan_trampoline::<F> as *const (), 86 )), 87 Box_::into_raw(f), 88 ) 89 } 90 } 91 92 #[doc(alias = "orientation")] connect_orientation_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId93 pub fn connect_orientation_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { 94 unsafe extern "C" fn notify_orientation_trampoline<F: Fn(&GesturePan) + 'static>( 95 this: *mut ffi::GtkGesturePan, 96 _param_spec: glib::ffi::gpointer, 97 f: glib::ffi::gpointer, 98 ) { 99 let f: &F = &*(f as *const F); 100 f(&from_glib_borrow(this)) 101 } 102 unsafe { 103 let f: Box_<F> = Box_::new(f); 104 connect_raw( 105 self.as_ptr() as *mut _, 106 b"notify::orientation\0".as_ptr() as *const _, 107 Some(transmute::<_, unsafe extern "C" fn()>( 108 notify_orientation_trampoline::<F> as *const (), 109 )), 110 Box_::into_raw(f), 111 ) 112 } 113 } 114 } 115 116 #[derive(Clone, Default)] 117 // rustdoc-stripper-ignore-next 118 /// A [builder-pattern] type to construct [`GesturePan`] objects. 119 /// 120 /// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html 121 pub struct GesturePanBuilder { 122 orientation: Option<Orientation>, 123 button: Option<u32>, 124 exclusive: Option<bool>, 125 touch_only: Option<bool>, 126 n_points: Option<u32>, 127 window: Option<gdk::Window>, 128 propagation_phase: Option<PropagationPhase>, 129 widget: Option<Widget>, 130 } 131 132 impl GesturePanBuilder { 133 // rustdoc-stripper-ignore-next 134 /// Create a new [`GesturePanBuilder`]. new() -> Self135 pub fn new() -> Self { 136 Self::default() 137 } 138 139 // rustdoc-stripper-ignore-next 140 /// Build the [`GesturePan`]. build(self) -> GesturePan141 pub fn build(self) -> GesturePan { 142 let mut properties: Vec<(&str, &dyn ToValue)> = vec![]; 143 if let Some(ref orientation) = self.orientation { 144 properties.push(("orientation", orientation)); 145 } 146 if let Some(ref button) = self.button { 147 properties.push(("button", button)); 148 } 149 if let Some(ref exclusive) = self.exclusive { 150 properties.push(("exclusive", exclusive)); 151 } 152 if let Some(ref touch_only) = self.touch_only { 153 properties.push(("touch-only", touch_only)); 154 } 155 if let Some(ref n_points) = self.n_points { 156 properties.push(("n-points", n_points)); 157 } 158 if let Some(ref window) = self.window { 159 properties.push(("window", window)); 160 } 161 if let Some(ref propagation_phase) = self.propagation_phase { 162 properties.push(("propagation-phase", propagation_phase)); 163 } 164 if let Some(ref widget) = self.widget { 165 properties.push(("widget", widget)); 166 } 167 glib::Object::new::<GesturePan>(&properties) 168 .expect("Failed to create an instance of GesturePan") 169 } 170 orientation(mut self, orientation: Orientation) -> Self171 pub fn orientation(mut self, orientation: Orientation) -> Self { 172 self.orientation = Some(orientation); 173 self 174 } 175 button(mut self, button: u32) -> Self176 pub fn button(mut self, button: u32) -> Self { 177 self.button = Some(button); 178 self 179 } 180 exclusive(mut self, exclusive: bool) -> Self181 pub fn exclusive(mut self, exclusive: bool) -> Self { 182 self.exclusive = Some(exclusive); 183 self 184 } 185 touch_only(mut self, touch_only: bool) -> Self186 pub fn touch_only(mut self, touch_only: bool) -> Self { 187 self.touch_only = Some(touch_only); 188 self 189 } 190 n_points(mut self, n_points: u32) -> Self191 pub fn n_points(mut self, n_points: u32) -> Self { 192 self.n_points = Some(n_points); 193 self 194 } 195 window(mut self, window: &gdk::Window) -> Self196 pub fn window(mut self, window: &gdk::Window) -> Self { 197 self.window = Some(window.clone()); 198 self 199 } 200 propagation_phase(mut self, propagation_phase: PropagationPhase) -> Self201 pub fn propagation_phase(mut self, propagation_phase: PropagationPhase) -> Self { 202 self.propagation_phase = Some(propagation_phase); 203 self 204 } 205 widget<P: IsA<Widget>>(mut self, widget: &P) -> Self206 pub fn widget<P: IsA<Widget>>(mut self, widget: &P) -> Self { 207 self.widget = Some(widget.clone().upcast()); 208 self 209 } 210 } 211 212 impl fmt::Display for GesturePan { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result213 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 214 f.write_str("GesturePan") 215 } 216 } 217