clutter/auto/
actor_meta.rs1use 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
22pub trait ActorMetaExt: 'static {
28 fn get_actor(&self) -> Option<Actor>;
34
35 fn get_enabled(&self) -> bool;
41
42 fn get_name(&self) -> Option<GString>;
51
52 fn set_enabled(&self, is_enabled: bool);
56
57 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}