1use crate::{LayoutManager, Orientation};
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 BoxLayout(Object<ffi::ClutterBoxLayout, ffi::ClutterBoxLayoutClass, BoxLayoutClass>) @extends LayoutManager, gobject::InitiallyUnowned;
13
14 match fn {
15 get_type => || ffi::clutter_box_layout_get_type(),
16 }
17}
18
19impl BoxLayout {
20 pub fn new() -> BoxLayout {
26 unsafe { LayoutManager::from_glib_none(ffi::clutter_box_layout_new()).unsafe_cast() }
27 }
28}
29
30impl Default for BoxLayout {
31 fn default() -> Self {
32 Self::new()
33 }
34}
35
36pub const NONE_BOX_LAYOUT: Option<&BoxLayout> = None;
37
38pub trait BoxLayoutExt: 'static {
44 fn get_homogeneous(&self) -> bool;
51
52 fn get_orientation(&self) -> Orientation;
58
59 fn get_pack_start(&self) -> bool;
66
67 fn get_spacing(&self) -> u32;
73
74 fn set_homogeneous(&self, homogeneous: bool);
79
80 fn set_orientation(&self, orientation: Orientation);
84
85 fn set_pack_start(&self, pack_start: bool);
91
92 fn set_spacing(&self, spacing: u32);
96
97 fn connect_property_homogeneous_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
98
99 fn connect_property_orientation_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
100
101 fn connect_property_pack_start_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
102
103 fn connect_property_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
104}
105
106impl<O: IsA<BoxLayout>> BoxLayoutExt for O {
107 fn get_homogeneous(&self) -> bool {
108 unsafe {
109 from_glib(ffi::clutter_box_layout_get_homogeneous(
110 self.as_ref().to_glib_none().0,
111 ))
112 }
113 }
114
115 fn get_orientation(&self) -> Orientation {
116 unsafe {
117 from_glib(ffi::clutter_box_layout_get_orientation(
118 self.as_ref().to_glib_none().0,
119 ))
120 }
121 }
122
123 fn get_pack_start(&self) -> bool {
124 unsafe {
125 from_glib(ffi::clutter_box_layout_get_pack_start(
126 self.as_ref().to_glib_none().0,
127 ))
128 }
129 }
130
131 fn get_spacing(&self) -> u32 {
132 unsafe { ffi::clutter_box_layout_get_spacing(self.as_ref().to_glib_none().0) }
133 }
134
135 fn set_homogeneous(&self, homogeneous: bool) {
136 unsafe {
137 ffi::clutter_box_layout_set_homogeneous(
138 self.as_ref().to_glib_none().0,
139 homogeneous.to_glib(),
140 );
141 }
142 }
143
144 fn set_orientation(&self, orientation: Orientation) {
145 unsafe {
146 ffi::clutter_box_layout_set_orientation(
147 self.as_ref().to_glib_none().0,
148 orientation.to_glib(),
149 );
150 }
151 }
152
153 fn set_pack_start(&self, pack_start: bool) {
154 unsafe {
155 ffi::clutter_box_layout_set_pack_start(
156 self.as_ref().to_glib_none().0,
157 pack_start.to_glib(),
158 );
159 }
160 }
161
162 fn set_spacing(&self, spacing: u32) {
163 unsafe {
164 ffi::clutter_box_layout_set_spacing(self.as_ref().to_glib_none().0, spacing);
165 }
166 }
167
168 fn connect_property_homogeneous_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
169 unsafe extern "C" fn notify_homogeneous_trampoline<P, F: Fn(&P) + 'static>(
170 this: *mut ffi::ClutterBoxLayout,
171 _param_spec: glib_sys::gpointer,
172 f: glib_sys::gpointer,
173 ) where
174 P: IsA<BoxLayout>,
175 {
176 let f: &F = &*(f as *const F);
177 f(&BoxLayout::from_glib_borrow(this).unsafe_cast_ref())
178 }
179 unsafe {
180 let f: Box_<F> = Box_::new(f);
181 connect_raw(
182 self.as_ptr() as *mut _,
183 b"notify::homogeneous\0".as_ptr() as *const _,
184 Some(transmute::<_, unsafe extern "C" fn()>(
185 notify_homogeneous_trampoline::<Self, F> as *const (),
186 )),
187 Box_::into_raw(f),
188 )
189 }
190 }
191
192 fn connect_property_orientation_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
193 unsafe extern "C" fn notify_orientation_trampoline<P, F: Fn(&P) + 'static>(
194 this: *mut ffi::ClutterBoxLayout,
195 _param_spec: glib_sys::gpointer,
196 f: glib_sys::gpointer,
197 ) where
198 P: IsA<BoxLayout>,
199 {
200 let f: &F = &*(f as *const F);
201 f(&BoxLayout::from_glib_borrow(this).unsafe_cast_ref())
202 }
203 unsafe {
204 let f: Box_<F> = Box_::new(f);
205 connect_raw(
206 self.as_ptr() as *mut _,
207 b"notify::orientation\0".as_ptr() as *const _,
208 Some(transmute::<_, unsafe extern "C" fn()>(
209 notify_orientation_trampoline::<Self, F> as *const (),
210 )),
211 Box_::into_raw(f),
212 )
213 }
214 }
215
216 fn connect_property_pack_start_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
217 unsafe extern "C" fn notify_pack_start_trampoline<P, F: Fn(&P) + 'static>(
218 this: *mut ffi::ClutterBoxLayout,
219 _param_spec: glib_sys::gpointer,
220 f: glib_sys::gpointer,
221 ) where
222 P: IsA<BoxLayout>,
223 {
224 let f: &F = &*(f as *const F);
225 f(&BoxLayout::from_glib_borrow(this).unsafe_cast_ref())
226 }
227 unsafe {
228 let f: Box_<F> = Box_::new(f);
229 connect_raw(
230 self.as_ptr() as *mut _,
231 b"notify::pack-start\0".as_ptr() as *const _,
232 Some(transmute::<_, unsafe extern "C" fn()>(
233 notify_pack_start_trampoline::<Self, F> as *const (),
234 )),
235 Box_::into_raw(f),
236 )
237 }
238 }
239
240 fn connect_property_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
241 unsafe extern "C" fn notify_spacing_trampoline<P, F: Fn(&P) + 'static>(
242 this: *mut ffi::ClutterBoxLayout,
243 _param_spec: glib_sys::gpointer,
244 f: glib_sys::gpointer,
245 ) where
246 P: IsA<BoxLayout>,
247 {
248 let f: &F = &*(f as *const F);
249 f(&BoxLayout::from_glib_borrow(this).unsafe_cast_ref())
250 }
251 unsafe {
252 let f: Box_<F> = Box_::new(f);
253 connect_raw(
254 self.as_ptr() as *mut _,
255 b"notify::spacing\0".as_ptr() as *const _,
256 Some(transmute::<_, unsafe extern "C" fn()>(
257 notify_spacing_trampoline::<Self, F> as *const (),
258 )),
259 Box_::into_raw(f),
260 )
261 }
262 }
263}
264
265impl fmt::Display for BoxLayout {
266 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
267 write!(f, "BoxLayout")
268 }
269}