1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT
use crate::{EventController, Gesture};
use glib::{
prelude::*,
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use std::boxed::Box as Box_;
glib::wrapper! {
/// [`GestureSingle`][crate::GestureSingle] is a `GtkGestures` subclass optimized for singe-touch
/// and mouse gestures.
///
/// Under interaction, these gestures stick to the first interacting sequence,
/// which is accessible through [`GestureSingleExt::current_sequence()`][crate::prelude::GestureSingleExt::current_sequence()]
/// while the gesture is being interacted with.
///
/// By default gestures react to both `GDK_BUTTON_PRIMARY` and touch events.
/// [`GestureSingleExt::set_touch_only()`][crate::prelude::GestureSingleExt::set_touch_only()] can be used to change the
/// touch behavior. Callers may also specify a different mouse button number
/// to interact with through [`GestureSingleExt::set_button()`][crate::prelude::GestureSingleExt::set_button()], or react
/// to any mouse button by setting it to 0. While the gesture is active, the
/// button being currently pressed can be known through
/// [`GestureSingleExt::current_button()`][crate::prelude::GestureSingleExt::current_button()].
///
/// ## Properties
///
///
/// #### `button`
/// Mouse button number to listen to, or 0 to listen for any button.
///
/// Readable | Writeable
///
///
/// #### `exclusive`
/// Whether the gesture is exclusive.
///
/// Exclusive gestures only listen to pointer and pointer emulated events.
///
/// Readable | Writeable
///
///
/// #### `touch-only`
/// Whether the gesture handles only touch events.
///
/// Readable | Writeable
/// <details><summary><h4>Gesture</h4></summary>
///
///
/// #### `n-points`
/// The number of touch points that trigger
/// recognition on this gesture.
///
/// Readable | Writeable | Construct Only
/// </details>
/// <details><summary><h4>EventController</h4></summary>
///
///
/// #### `name`
/// The name for this controller, typically used for debugging purposes.
///
/// Readable | Writeable
///
///
/// #### `propagation-limit`
/// The limit for which events this controller will handle.
///
/// Readable | Writeable
///
///
/// #### `propagation-phase`
/// The propagation phase at which this controller will handle events.
///
/// Readable | Writeable
///
///
/// #### `widget`
/// The widget receiving the `GdkEvents` that the controller will handle.
///
/// Readable
/// </details>
///
/// # Implements
///
/// [`GestureSingleExt`][trait@crate::prelude::GestureSingleExt], [`GestureExt`][trait@crate::prelude::GestureExt], [`EventControllerExt`][trait@crate::prelude::EventControllerExt], [`trait@glib::ObjectExt`]
#[doc(alias = "GtkGestureSingle")]
pub struct GestureSingle(Object<ffi::GtkGestureSingle, ffi::GtkGestureSingleClass>) @extends Gesture, EventController;
match fn {
type_ => || ffi::gtk_gesture_single_get_type(),
}
}
impl GestureSingle {
pub const NONE: Option<&'static GestureSingle> = None;
}
mod sealed {
pub trait Sealed {}
impl<T: super::IsA<super::GestureSingle>> Sealed for T {}
}
/// Trait containing all [`struct@GestureSingle`] methods.
///
/// # Implementors
///
/// [`DragSource`][struct@crate::DragSource], [`GestureClick`][struct@crate::GestureClick], [`GestureDrag`][struct@crate::GestureDrag], [`GestureLongPress`][struct@crate::GestureLongPress], [`GestureSingle`][struct@crate::GestureSingle], [`GestureStylus`][struct@crate::GestureStylus], [`GestureSwipe`][struct@crate::GestureSwipe]
pub trait GestureSingleExt: IsA<GestureSingle> + sealed::Sealed + 'static {
/// Returns the button number @self listens for.
///
/// If this is 0, the gesture reacts to any button press.
///
/// # Returns
///
/// The button number, or 0 for any button
#[doc(alias = "gtk_gesture_single_get_button")]
#[doc(alias = "get_button")]
fn button(&self) -> u32 {
unsafe { ffi::gtk_gesture_single_get_button(self.as_ref().to_glib_none().0) }
}
/// Returns the button number currently interacting
/// with @self, or 0 if there is none.
///
/// # Returns
///
/// The current button number
#[doc(alias = "gtk_gesture_single_get_current_button")]
#[doc(alias = "get_current_button")]
fn current_button(&self) -> u32 {
unsafe { ffi::gtk_gesture_single_get_current_button(self.as_ref().to_glib_none().0) }
}
/// Returns the event sequence currently interacting with @self.
///
/// This is only meaningful if [`GestureExt::is_active()`][crate::prelude::GestureExt::is_active()]
/// returns [`true`].
///
/// # Returns
///
/// the current sequence
#[doc(alias = "gtk_gesture_single_get_current_sequence")]
#[doc(alias = "get_current_sequence")]
fn current_sequence(&self) -> Option<gdk::EventSequence> {
unsafe {
from_glib_full(ffi::gtk_gesture_single_get_current_sequence(
self.as_ref().to_glib_none().0,
))
}
}
/// Gets whether a gesture is exclusive.
///
/// For more information, see [`set_exclusive()`][Self::set_exclusive()].
///
/// # Returns
///
/// Whether the gesture is exclusive
#[doc(alias = "gtk_gesture_single_get_exclusive")]
#[doc(alias = "get_exclusive")]
fn is_exclusive(&self) -> bool {
unsafe {
from_glib(ffi::gtk_gesture_single_get_exclusive(
self.as_ref().to_glib_none().0,
))
}
}
/// Returns [`true`] if the gesture is only triggered by touch events.
///
/// # Returns
///
/// [`true`] if the gesture only handles touch events
#[doc(alias = "gtk_gesture_single_get_touch_only")]
#[doc(alias = "get_touch_only")]
fn is_touch_only(&self) -> bool {
unsafe {
from_glib(ffi::gtk_gesture_single_get_touch_only(
self.as_ref().to_glib_none().0,
))
}
}
/// Sets the button number @self listens to.
///
/// If non-0, every button press from a different button
/// number will be ignored. Touch events implicitly match
/// with button 1.
/// ## `button`
/// button number to listen to, or 0 for any button
#[doc(alias = "gtk_gesture_single_set_button")]
fn set_button(&self, button: u32) {
unsafe {
ffi::gtk_gesture_single_set_button(self.as_ref().to_glib_none().0, button);
}
}
/// Sets whether @self is exclusive.
///
/// An exclusive gesture will only handle pointer and "pointer emulated"
/// touch events, so at any given time, there is only one sequence able
/// to interact with those.
/// ## `exclusive`
/// [`true`] to make @self exclusive
#[doc(alias = "gtk_gesture_single_set_exclusive")]
fn set_exclusive(&self, exclusive: bool) {
unsafe {
ffi::gtk_gesture_single_set_exclusive(
self.as_ref().to_glib_none().0,
exclusive.into_glib(),
);
}
}
/// Sets whether to handle only touch events.
///
/// If @touch_only is [`true`], @self will only handle events of type
/// `GDK_TOUCH_BEGIN`, `GDK_TOUCH_UPDATE` or `GDK_TOUCH_END`. If [`false`],
/// mouse events will be handled too.
/// ## `touch_only`
/// whether @self handles only touch events
#[doc(alias = "gtk_gesture_single_set_touch_only")]
fn set_touch_only(&self, touch_only: bool) {
unsafe {
ffi::gtk_gesture_single_set_touch_only(
self.as_ref().to_glib_none().0,
touch_only.into_glib(),
);
}
}
#[doc(alias = "button")]
fn connect_button_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_button_trampoline<
P: IsA<GestureSingle>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::GtkGestureSingle,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(GestureSingle::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::button\0".as_ptr() as *const _,
Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
notify_button_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "exclusive")]
fn connect_exclusive_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_exclusive_trampoline<
P: IsA<GestureSingle>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::GtkGestureSingle,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(GestureSingle::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::exclusive\0".as_ptr() as *const _,
Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
notify_exclusive_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "touch-only")]
fn connect_touch_only_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_touch_only_trampoline<
P: IsA<GestureSingle>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::GtkGestureSingle,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(GestureSingle::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::touch-only\0".as_ptr() as *const _,
Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
notify_touch_only_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl<O: IsA<GestureSingle>> GestureSingleExt for O {}