clutter/auto/
path_constraint.rs1use crate::{Actor, ActorMeta, Constraint, Path};
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 PathConstraint(Object<ffi::ClutterPathConstraint, ffi::ClutterPathConstraintClass, PathConstraintClass>) @extends Constraint, ActorMeta, gobject::InitiallyUnowned;
13
14 match fn {
15 get_type => || ffi::clutter_path_constraint_get_type(),
16 }
17}
18
19impl PathConstraint {
20 pub fn new<P: IsA<Path>>(path: Option<&P>, offset: f32) -> PathConstraint {
30 unsafe {
31 Constraint::from_glib_none(ffi::clutter_path_constraint_new(
32 path.map(|p| p.as_ref()).to_glib_none().0,
33 offset,
34 ))
35 .unsafe_cast()
36 }
37 }
38
39 pub fn get_offset(&self) -> f32 {
45 unsafe { ffi::clutter_path_constraint_get_offset(self.to_glib_none().0) }
46 }
47
48 pub fn get_path(&self) -> Option<Path> {
56 unsafe { from_glib_none(ffi::clutter_path_constraint_get_path(self.to_glib_none().0)) }
57 }
58
59 pub fn set_offset(&self, offset: f32) {
63 unsafe {
64 ffi::clutter_path_constraint_set_offset(self.to_glib_none().0, offset);
65 }
66 }
67
68 pub fn set_path<P: IsA<Path>>(&self, path: Option<&P>) {
75 unsafe {
76 ffi::clutter_path_constraint_set_path(
77 self.to_glib_none().0,
78 path.map(|p| p.as_ref()).to_glib_none().0,
79 );
80 }
81 }
82
83 pub fn connect_node_reached<F: Fn(&PathConstraint, &Actor, u32) + 'static>(
91 &self,
92 f: F,
93 ) -> SignalHandlerId {
94 unsafe extern "C" fn node_reached_trampoline<
95 F: Fn(&PathConstraint, &Actor, u32) + 'static,
96 >(
97 this: *mut ffi::ClutterPathConstraint,
98 actor: *mut ffi::ClutterActor,
99 index: libc::c_uint,
100 f: glib_sys::gpointer,
101 ) {
102 let f: &F = &*(f as *const F);
103 f(&from_glib_borrow(this), &from_glib_borrow(actor), index)
104 }
105 unsafe {
106 let f: Box_<F> = Box_::new(f);
107 connect_raw(
108 self.as_ptr() as *mut _,
109 b"node-reached\0".as_ptr() as *const _,
110 Some(transmute::<_, unsafe extern "C" fn()>(
111 node_reached_trampoline::<F> as *const (),
112 )),
113 Box_::into_raw(f),
114 )
115 }
116 }
117
118 pub fn connect_property_offset_notify<F: Fn(&PathConstraint) + 'static>(
119 &self,
120 f: F,
121 ) -> SignalHandlerId {
122 unsafe extern "C" fn notify_offset_trampoline<F: Fn(&PathConstraint) + 'static>(
123 this: *mut ffi::ClutterPathConstraint,
124 _param_spec: glib_sys::gpointer,
125 f: glib_sys::gpointer,
126 ) {
127 let f: &F = &*(f as *const F);
128 f(&from_glib_borrow(this))
129 }
130 unsafe {
131 let f: Box_<F> = Box_::new(f);
132 connect_raw(
133 self.as_ptr() as *mut _,
134 b"notify::offset\0".as_ptr() as *const _,
135 Some(transmute::<_, unsafe extern "C" fn()>(
136 notify_offset_trampoline::<F> as *const (),
137 )),
138 Box_::into_raw(f),
139 )
140 }
141 }
142
143 pub fn connect_property_path_notify<F: Fn(&PathConstraint) + 'static>(
144 &self,
145 f: F,
146 ) -> SignalHandlerId {
147 unsafe extern "C" fn notify_path_trampoline<F: Fn(&PathConstraint) + 'static>(
148 this: *mut ffi::ClutterPathConstraint,
149 _param_spec: glib_sys::gpointer,
150 f: glib_sys::gpointer,
151 ) {
152 let f: &F = &*(f as *const F);
153 f(&from_glib_borrow(this))
154 }
155 unsafe {
156 let f: Box_<F> = Box_::new(f);
157 connect_raw(
158 self.as_ptr() as *mut _,
159 b"notify::path\0".as_ptr() as *const _,
160 Some(transmute::<_, unsafe extern "C" fn()>(
161 notify_path_trampoline::<F> as *const (),
162 )),
163 Box_::into_raw(f),
164 )
165 }
166 }
167}
168
169impl fmt::Display for PathConstraint {
170 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
171 write!(f, "PathConstraint")
172 }
173}