animate/legacy/
align_constraint.rs1use crate::{Actor, ActorMeta, AlignAxis, Constraint};
2use glib::{
3 object as gobject,
4 object::{Cast, IsA, ObjectType as ObjectType_},
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 AlignConstraint(Object<ffi::ClutterAlignConstraint, ffi::ClutterAlignConstraintClass, AlignConstraintClass>) @extends Constraint, ActorMeta, gobject::InitiallyUnowned;
13
14 match fn {
15 get_type => || ffi::clutter_align_constraint_get_type(),
16 }
17}
18
19impl AlignConstraint {
20 pub fn new<P: IsA<Actor>>(source: Option<&P>, axis: AlignAxis, factor: f32) -> AlignConstraint {
35 unsafe {
36 Constraint::from_glib_none(ffi::clutter_align_constraint_new(
37 source.map(|p| p.as_ref()).to_glib_none().0,
38 axis.to_glib(),
39 factor,
40 ))
41 .unsafe_cast()
42 }
43 }
44
45 pub fn get_align_axis(&self) -> AlignAxis {
51 unsafe {
52 from_glib(ffi::clutter_align_constraint_get_align_axis(
53 self.to_glib_none().0,
54 ))
55 }
56 }
57
58 pub fn get_factor(&self) -> f32 {
64 unsafe { ffi::clutter_align_constraint_get_factor(self.to_glib_none().0) }
65 }
66
67 pub fn get_source(&self) -> Option<Actor> {
74 unsafe {
75 from_glib_none(ffi::clutter_align_constraint_get_source(
76 self.to_glib_none().0,
77 ))
78 }
79 }
80
81 pub fn set_align_axis(&self, axis: AlignAxis) {
85 unsafe {
86 ffi::clutter_align_constraint_set_align_axis(self.to_glib_none().0, axis.to_glib());
87 }
88 }
89
90 pub fn set_factor(&self, factor: f32) {
104 unsafe {
105 ffi::clutter_align_constraint_set_factor(self.to_glib_none().0, factor);
106 }
107 }
108
109 pub fn set_source<P: IsA<Actor>>(&self, source: Option<&P>) {
113 unsafe {
114 ffi::clutter_align_constraint_set_source(
115 self.to_glib_none().0,
116 source.map(|p| p.as_ref()).to_glib_none().0,
117 );
118 }
119 }
120
121 pub fn connect_property_align_axis_notify<F: Fn(&AlignConstraint) + 'static>(
122 &self,
123 f: F,
124 ) -> SignalHandlerId {
125 unsafe extern "C" fn notify_align_axis_trampoline<F: Fn(&AlignConstraint) + 'static>(
126 this: *mut ffi::ClutterAlignConstraint,
127 _param_spec: glib_sys::gpointer,
128 f: glib_sys::gpointer,
129 ) {
130 let f: &F = &*(f as *const F);
131 f(&from_glib_borrow(this))
132 }
133 unsafe {
134 let f: Box_<F> = Box_::new(f);
135 connect_raw(
136 self.as_ptr() as *mut _,
137 b"notify::align-axis\0".as_ptr() as *const _,
138 Some(transmute::<_, unsafe extern "C" fn()>(
139 notify_align_axis_trampoline::<F> as *const (),
140 )),
141 Box_::into_raw(f),
142 )
143 }
144 }
145
146 pub fn connect_property_factor_notify<F: Fn(&AlignConstraint) + 'static>(
147 &self,
148 f: F,
149 ) -> SignalHandlerId {
150 unsafe extern "C" fn notify_factor_trampoline<F: Fn(&AlignConstraint) + 'static>(
151 this: *mut ffi::ClutterAlignConstraint,
152 _param_spec: glib_sys::gpointer,
153 f: glib_sys::gpointer,
154 ) {
155 let f: &F = &*(f as *const F);
156 f(&from_glib_borrow(this))
157 }
158 unsafe {
159 let f: Box_<F> = Box_::new(f);
160 connect_raw(
161 self.as_ptr() as *mut _,
162 b"notify::factor\0".as_ptr() as *const _,
163 Some(transmute::<_, unsafe extern "C" fn()>(
164 notify_factor_trampoline::<F> as *const (),
165 )),
166 Box_::into_raw(f),
167 )
168 }
169 }
170
171 pub fn connect_property_source_notify<F: Fn(&AlignConstraint) + 'static>(
172 &self,
173 f: F,
174 ) -> SignalHandlerId {
175 unsafe extern "C" fn notify_source_trampoline<F: Fn(&AlignConstraint) + 'static>(
176 this: *mut ffi::ClutterAlignConstraint,
177 _param_spec: glib_sys::gpointer,
178 f: glib_sys::gpointer,
179 ) {
180 let f: &F = &*(f as *const F);
181 f(&from_glib_borrow(this))
182 }
183 unsafe {
184 let f: Box_<F> = Box_::new(f);
185 connect_raw(
186 self.as_ptr() as *mut _,
187 b"notify::source\0".as_ptr() as *const _,
188 Some(transmute::<_, unsafe extern "C" fn()>(
189 notify_source_trampoline::<F> as *const (),
190 )),
191 Box_::into_raw(f),
192 )
193 }
194 }
195}
196
197impl fmt::Display for AlignConstraint {
198 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
199 write!(f, "AlignConstraint")
200 }
201}