clutter/auto/
actor_meta.rs

1use crate::Actor;
2use glib::{
3    object as gobject,
4    object::{Cast, IsA},
5    signal::{connect_raw, SignalHandlerId},
6    translate::*,
7    GString,
8};
9use std::boxed::Box as Box_;
10use std::{fmt, mem::transmute};
11
12glib_wrapper! {
13    pub struct ActorMeta(Object<ffi::ClutterActorMeta, ffi::ClutterActorMetaClass, ActorMetaClass>) @extends gobject::InitiallyUnowned;
14
15    match fn {
16        get_type => || ffi::clutter_actor_meta_get_type(),
17    }
18}
19
20pub const NONE_ACTOR_META: Option<&ActorMeta> = None;
21
22/// Trait containing all `ActorMeta` methods.
23///
24/// # Implementors
25///
26/// [`Action`](struct.Action.html), [`ActorMeta`](struct.ActorMeta.html), [`Constraint`](struct.Constraint.html), [`Effect`](struct.Effect.html)
27pub trait ActorMetaExt: 'static {
28    /// Retrieves a pointer to the `Actor` that owns `self`
29    ///
30    /// # Returns
31    ///
32    /// a pointer to a `Actor` or `None`
33    fn get_actor(&self) -> Option<Actor>;
34
35    /// Retrieves whether `self` is enabled
36    ///
37    /// # Returns
38    ///
39    /// `true` if the `ActorMeta` instance is enabled
40    fn get_enabled(&self) -> bool;
41
42    /// Retrieves the name set using `ActorMetaExt::set_name`
43    ///
44    /// # Returns
45    ///
46    /// the name of the `ActorMeta`
47    ///  instance, or `None` if none was set. The returned string is owned
48    ///  by the `ActorMeta` instance and it should not be modified
49    ///  or freed
50    fn get_name(&self) -> Option<GString>;
51
52    /// Sets whether `self` should be enabled or not
53    /// ## `is_enabled`
54    /// whether `self` is enabled
55    fn set_enabled(&self, is_enabled: bool);
56
57    /// Sets the name of `self`
58    ///
59    /// The name can be used to identify the `ActorMeta` instance
60    /// ## `name`
61    /// the name of `self`
62    fn set_name(&self, name: &str);
63
64    fn connect_property_actor_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
65
66    fn connect_property_enabled_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
67
68    fn connect_property_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
69}
70
71impl<O: IsA<ActorMeta>> ActorMetaExt for O {
72    fn get_actor(&self) -> Option<Actor> {
73        unsafe {
74            from_glib_none(ffi::clutter_actor_meta_get_actor(
75                self.as_ref().to_glib_none().0,
76            ))
77        }
78    }
79
80    fn get_enabled(&self) -> bool {
81        unsafe {
82            from_glib(ffi::clutter_actor_meta_get_enabled(
83                self.as_ref().to_glib_none().0,
84            ))
85        }
86    }
87
88    fn get_name(&self) -> Option<GString> {
89        unsafe {
90            from_glib_none(ffi::clutter_actor_meta_get_name(
91                self.as_ref().to_glib_none().0,
92            ))
93        }
94    }
95
96    fn set_enabled(&self, is_enabled: bool) {
97        unsafe {
98            ffi::clutter_actor_meta_set_enabled(
99                self.as_ref().to_glib_none().0,
100                is_enabled.to_glib(),
101            );
102        }
103    }
104
105    fn set_name(&self, name: &str) {
106        unsafe {
107            ffi::clutter_actor_meta_set_name(self.as_ref().to_glib_none().0, name.to_glib_none().0);
108        }
109    }
110
111    fn connect_property_actor_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
112        unsafe extern "C" fn notify_actor_trampoline<P, F: Fn(&P) + 'static>(
113            this: *mut ffi::ClutterActorMeta,
114            _param_spec: glib_sys::gpointer,
115            f: glib_sys::gpointer,
116        ) where
117            P: IsA<ActorMeta>,
118        {
119            let f: &F = &*(f as *const F);
120            f(&ActorMeta::from_glib_borrow(this).unsafe_cast_ref())
121        }
122        unsafe {
123            let f: Box_<F> = Box_::new(f);
124            connect_raw(
125                self.as_ptr() as *mut _,
126                b"notify::actor\0".as_ptr() as *const _,
127                Some(transmute::<_, unsafe extern "C" fn()>(
128                    notify_actor_trampoline::<Self, F> as *const (),
129                )),
130                Box_::into_raw(f),
131            )
132        }
133    }
134
135    fn connect_property_enabled_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
136        unsafe extern "C" fn notify_enabled_trampoline<P, F: Fn(&P) + 'static>(
137            this: *mut ffi::ClutterActorMeta,
138            _param_spec: glib_sys::gpointer,
139            f: glib_sys::gpointer,
140        ) where
141            P: IsA<ActorMeta>,
142        {
143            let f: &F = &*(f as *const F);
144            f(&ActorMeta::from_glib_borrow(this).unsafe_cast_ref())
145        }
146        unsafe {
147            let f: Box_<F> = Box_::new(f);
148            connect_raw(
149                self.as_ptr() as *mut _,
150                b"notify::enabled\0".as_ptr() as *const _,
151                Some(transmute::<_, unsafe extern "C" fn()>(
152                    notify_enabled_trampoline::<Self, F> as *const (),
153                )),
154                Box_::into_raw(f),
155            )
156        }
157    }
158
159    fn connect_property_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
160        unsafe extern "C" fn notify_name_trampoline<P, F: Fn(&P) + 'static>(
161            this: *mut ffi::ClutterActorMeta,
162            _param_spec: glib_sys::gpointer,
163            f: glib_sys::gpointer,
164        ) where
165            P: IsA<ActorMeta>,
166        {
167            let f: &F = &*(f as *const F);
168            f(&ActorMeta::from_glib_borrow(this).unsafe_cast_ref())
169        }
170        unsafe {
171            let f: Box_<F> = Box_::new(f);
172            connect_raw(
173                self.as_ptr() as *mut _,
174                b"notify::name\0".as_ptr() as *const _,
175                Some(transmute::<_, unsafe extern "C" fn()>(
176                    notify_name_trampoline::<Self, F> as *const (),
177                )),
178                Box_::into_raw(f),
179            )
180        }
181    }
182}
183
184impl fmt::Display for ActorMeta {
185    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
186        write!(f, "ActorMeta")
187    }
188}