gtk4/auto/
gesture_long_press.rs1use crate::{ffi, EventController, Gesture, GestureSingle, PropagationLimit, PropagationPhase};
6use glib::{
7 object::ObjectType as _,
8 prelude::*,
9 signal::{connect_raw, SignalHandlerId},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 #[doc(alias = "GtkGestureLongPress")]
16 pub struct GestureLongPress(Object<ffi::GtkGestureLongPress, ffi::GtkGestureLongPressClass>) @extends GestureSingle, Gesture, EventController;
17
18 match fn {
19 type_ => || ffi::gtk_gesture_long_press_get_type(),
20 }
21}
22
23impl GestureLongPress {
24 #[doc(alias = "gtk_gesture_long_press_new")]
25 pub fn new() -> GestureLongPress {
26 assert_initialized_main_thread!();
27 unsafe { Gesture::from_glib_full(ffi::gtk_gesture_long_press_new()).unsafe_cast() }
28 }
29
30 pub fn builder() -> GestureLongPressBuilder {
35 GestureLongPressBuilder::new()
36 }
37
38 #[doc(alias = "gtk_gesture_long_press_get_delay_factor")]
39 #[doc(alias = "get_delay_factor")]
40 #[doc(alias = "delay-factor")]
41 pub fn delay_factor(&self) -> f64 {
42 unsafe { ffi::gtk_gesture_long_press_get_delay_factor(self.to_glib_none().0) }
43 }
44
45 #[doc(alias = "gtk_gesture_long_press_set_delay_factor")]
46 #[doc(alias = "delay-factor")]
47 pub fn set_delay_factor(&self, delay_factor: f64) {
48 unsafe {
49 ffi::gtk_gesture_long_press_set_delay_factor(self.to_glib_none().0, delay_factor);
50 }
51 }
52
53 #[doc(alias = "cancelled")]
54 pub fn connect_cancelled<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
55 unsafe extern "C" fn cancelled_trampoline<F: Fn(&GestureLongPress) + 'static>(
56 this: *mut ffi::GtkGestureLongPress,
57 f: glib::ffi::gpointer,
58 ) {
59 let f: &F = &*(f as *const F);
60 f(&from_glib_borrow(this))
61 }
62 unsafe {
63 let f: Box_<F> = Box_::new(f);
64 connect_raw(
65 self.as_ptr() as *mut _,
66 c"cancelled".as_ptr() as *const _,
67 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
68 cancelled_trampoline::<F> as *const (),
69 )),
70 Box_::into_raw(f),
71 )
72 }
73 }
74
75 #[doc(alias = "pressed")]
76 pub fn connect_pressed<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
77 unsafe extern "C" fn pressed_trampoline<F: Fn(&GestureLongPress, f64, f64) + 'static>(
78 this: *mut ffi::GtkGestureLongPress,
79 x: std::ffi::c_double,
80 y: std::ffi::c_double,
81 f: glib::ffi::gpointer,
82 ) {
83 let f: &F = &*(f as *const F);
84 f(&from_glib_borrow(this), x, y)
85 }
86 unsafe {
87 let f: Box_<F> = Box_::new(f);
88 connect_raw(
89 self.as_ptr() as *mut _,
90 c"pressed".as_ptr() as *const _,
91 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
92 pressed_trampoline::<F> as *const (),
93 )),
94 Box_::into_raw(f),
95 )
96 }
97 }
98
99 #[doc(alias = "delay-factor")]
100 pub fn connect_delay_factor_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
101 unsafe extern "C" fn notify_delay_factor_trampoline<F: Fn(&GestureLongPress) + 'static>(
102 this: *mut ffi::GtkGestureLongPress,
103 _param_spec: glib::ffi::gpointer,
104 f: glib::ffi::gpointer,
105 ) {
106 let f: &F = &*(f as *const F);
107 f(&from_glib_borrow(this))
108 }
109 unsafe {
110 let f: Box_<F> = Box_::new(f);
111 connect_raw(
112 self.as_ptr() as *mut _,
113 c"notify::delay-factor".as_ptr() as *const _,
114 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
115 notify_delay_factor_trampoline::<F> as *const (),
116 )),
117 Box_::into_raw(f),
118 )
119 }
120 }
121}
122
123impl Default for GestureLongPress {
124 fn default() -> Self {
125 Self::new()
126 }
127}
128
129#[must_use = "The builder must be built to be used"]
134pub struct GestureLongPressBuilder {
135 builder: glib::object::ObjectBuilder<'static, GestureLongPress>,
136}
137
138impl GestureLongPressBuilder {
139 fn new() -> Self {
140 Self {
141 builder: glib::object::Object::builder(),
142 }
143 }
144
145 pub fn delay_factor(self, delay_factor: f64) -> Self {
146 Self {
147 builder: self.builder.property("delay-factor", delay_factor),
148 }
149 }
150
151 pub fn button(self, button: u32) -> Self {
152 Self {
153 builder: self.builder.property("button", button),
154 }
155 }
156
157 pub fn exclusive(self, exclusive: bool) -> Self {
158 Self {
159 builder: self.builder.property("exclusive", exclusive),
160 }
161 }
162
163 pub fn touch_only(self, touch_only: bool) -> Self {
164 Self {
165 builder: self.builder.property("touch-only", touch_only),
166 }
167 }
168
169 pub fn n_points(self, n_points: u32) -> Self {
170 Self {
171 builder: self.builder.property("n-points", n_points),
172 }
173 }
174
175 pub fn name(self, name: impl Into<glib::GString>) -> Self {
176 Self {
177 builder: self.builder.property("name", name.into()),
178 }
179 }
180
181 pub fn propagation_limit(self, propagation_limit: PropagationLimit) -> Self {
182 Self {
183 builder: self
184 .builder
185 .property("propagation-limit", propagation_limit),
186 }
187 }
188
189 pub fn propagation_phase(self, propagation_phase: PropagationPhase) -> Self {
190 Self {
191 builder: self
192 .builder
193 .property("propagation-phase", propagation_phase),
194 }
195 }
196
197 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
200 pub fn build(self) -> GestureLongPress {
201 assert_initialized_main_thread!();
202 self.builder.build()
203 }
204}