clutter/auto/
rotate_action.rs1use crate::{Action, Actor, ActorMeta, GestureAction};
2use glib::{
3 object as gobject,
4 object::{Cast, IsA},
5 signal::{connect_raw, SignalHandlerId},
6 translate::*,
7};
8use std::boxed::Box as Box_;
9use std::{fmt, mem::transmute};
10
11glib_wrapper! {
12 pub struct RotateAction(Object<ffi::ClutterRotateAction, ffi::ClutterRotateActionClass, RotateActionClass>) @extends GestureAction, Action, ActorMeta, gobject::InitiallyUnowned;
13
14 match fn {
15 get_type => || ffi::clutter_rotate_action_get_type(),
16 }
17}
18
19impl RotateAction {
20 pub fn new() -> RotateAction {
26 unsafe { Action::from_glib_none(ffi::clutter_rotate_action_new()).unsafe_cast() }
27 }
28}
29
30impl Default for RotateAction {
31 fn default() -> Self {
32 Self::new()
33 }
34}
35
36pub const NONE_ROTATE_ACTION: Option<&RotateAction> = None;
37
38pub trait RotateActionExt: 'static {
44 fn connect_rotate<F: Fn(&Self, &Actor, f64) -> bool + 'static>(&self, f: F) -> SignalHandlerId;
58}
59
60impl<O: IsA<RotateAction>> RotateActionExt for O {
61 fn connect_rotate<F: Fn(&Self, &Actor, f64) -> bool + 'static>(&self, f: F) -> SignalHandlerId {
62 unsafe extern "C" fn rotate_trampoline<P, F: Fn(&P, &Actor, f64) -> bool + 'static>(
63 this: *mut ffi::ClutterRotateAction,
64 actor: *mut ffi::ClutterActor,
65 angle: libc::c_double,
66 f: glib_sys::gpointer,
67 ) -> glib_sys::gboolean
68 where
69 P: IsA<RotateAction>,
70 {
71 let f: &F = &*(f as *const F);
72 f(
73 &RotateAction::from_glib_borrow(this).unsafe_cast_ref(),
74 &from_glib_borrow(actor),
75 angle,
76 )
77 .to_glib()
78 }
79 unsafe {
80 let f: Box_<F> = Box_::new(f);
81 connect_raw(
82 self.as_ptr() as *mut _,
83 b"rotate\0".as_ptr() as *const _,
84 Some(transmute::<_, unsafe extern "C" fn()>(
85 rotate_trampoline::<Self, F> as *const (),
86 )),
87 Box_::into_raw(f),
88 )
89 }
90 }
91}
92
93impl fmt::Display for RotateAction {
94 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
95 write!(f, "RotateAction")
96 }
97}