1use crate::{FlowOrientation, LayoutManager};
2use glib::{
3 object as gobject,
4 object::{Cast, IsA},
5 signal::{connect_raw, SignalHandlerId},
6 translate::*,
7 StaticType, Value,
8};
9use std::boxed::Box as Box_;
10use std::{fmt, mem, mem::transmute};
11
12glib_wrapper! {
13 pub struct FlowLayout(Object<ffi::ClutterFlowLayout, ffi::ClutterFlowLayoutClass, FlowLayoutClass>) @extends LayoutManager, gobject::InitiallyUnowned;
14
15 match fn {
16 get_type => || ffi::clutter_flow_layout_get_type(),
17 }
18}
19
20impl FlowLayout {
21 pub fn new(orientation: FlowOrientation) -> FlowLayout {
29 unsafe {
30 LayoutManager::from_glib_none(ffi::clutter_flow_layout_new(orientation.to_glib()))
31 .unsafe_cast()
32 }
33 }
34}
35
36pub const NONE_FLOW_LAYOUT: Option<&FlowLayout> = None;
37
38pub trait FlowLayoutExt: 'static {
44 fn get_column_spacing(&self) -> f32;
51
52 fn get_column_width(&self) -> (f32, f32);
58
59 fn get_homogeneous(&self) -> bool;
65
66 fn get_orientation(&self) -> FlowOrientation;
72
73 fn get_row_height(&self) -> (f32, f32);
79
80 fn get_row_spacing(&self) -> f32;
87
88 fn get_snap_to_grid(&self) -> bool;
94
95 fn set_column_spacing(&self, spacing: f32);
99
100 fn set_column_width(&self, min_width: f32, max_width: f32);
106
107 fn set_homogeneous(&self, homogeneous: bool);
112
113 fn set_orientation(&self, orientation: FlowOrientation);
121
122 fn set_row_height(&self, min_height: f32, max_height: f32);
128
129 fn set_row_spacing(&self, spacing: f32);
133
134 fn set_snap_to_grid(&self, snap_to_grid: bool);
138
139 fn get_property_max_column_width(&self) -> f32;
142
143 fn set_property_max_column_width(&self, max_column_width: f32);
146
147 fn get_property_max_row_height(&self) -> f32;
150
151 fn set_property_max_row_height(&self, max_row_height: f32);
154
155 fn get_property_min_column_width(&self) -> f32;
157
158 fn set_property_min_column_width(&self, min_column_width: f32);
160
161 fn get_property_min_row_height(&self) -> f32;
163
164 fn set_property_min_row_height(&self, min_row_height: f32);
166
167 fn connect_property_column_spacing_notify<F: Fn(&Self) + 'static>(
168 &self,
169 f: F,
170 ) -> SignalHandlerId;
171
172 fn connect_property_homogeneous_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
173
174 fn connect_property_max_column_width_notify<F: Fn(&Self) + 'static>(
175 &self,
176 f: F,
177 ) -> SignalHandlerId;
178
179 fn connect_property_max_row_height_notify<F: Fn(&Self) + 'static>(
180 &self,
181 f: F,
182 ) -> SignalHandlerId;
183
184 fn connect_property_min_column_width_notify<F: Fn(&Self) + 'static>(
185 &self,
186 f: F,
187 ) -> SignalHandlerId;
188
189 fn connect_property_min_row_height_notify<F: Fn(&Self) + 'static>(
190 &self,
191 f: F,
192 ) -> SignalHandlerId;
193
194 fn connect_property_orientation_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
195
196 fn connect_property_row_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
197
198 fn connect_property_snap_to_grid_notify<F: Fn(&Self) + 'static>(&self, f: F)
199 -> SignalHandlerId;
200}
201
202impl<O: IsA<FlowLayout>> FlowLayoutExt for O {
203 fn get_column_spacing(&self) -> f32 {
204 unsafe { ffi::clutter_flow_layout_get_column_spacing(self.as_ref().to_glib_none().0) }
205 }
206
207 fn get_column_width(&self) -> (f32, f32) {
208 unsafe {
209 let mut min_width = mem::MaybeUninit::uninit();
210 let mut max_width = mem::MaybeUninit::uninit();
211 ffi::clutter_flow_layout_get_column_width(
212 self.as_ref().to_glib_none().0,
213 min_width.as_mut_ptr(),
214 max_width.as_mut_ptr(),
215 );
216 let min_width = min_width.assume_init();
217 let max_width = max_width.assume_init();
218 (min_width, max_width)
219 }
220 }
221
222 fn get_homogeneous(&self) -> bool {
223 unsafe {
224 from_glib(ffi::clutter_flow_layout_get_homogeneous(
225 self.as_ref().to_glib_none().0,
226 ))
227 }
228 }
229
230 fn get_orientation(&self) -> FlowOrientation {
231 unsafe {
232 from_glib(ffi::clutter_flow_layout_get_orientation(
233 self.as_ref().to_glib_none().0,
234 ))
235 }
236 }
237
238 fn get_row_height(&self) -> (f32, f32) {
239 unsafe {
240 let mut min_height = mem::MaybeUninit::uninit();
241 let mut max_height = mem::MaybeUninit::uninit();
242 ffi::clutter_flow_layout_get_row_height(
243 self.as_ref().to_glib_none().0,
244 min_height.as_mut_ptr(),
245 max_height.as_mut_ptr(),
246 );
247 let min_height = min_height.assume_init();
248 let max_height = max_height.assume_init();
249 (min_height, max_height)
250 }
251 }
252
253 fn get_row_spacing(&self) -> f32 {
254 unsafe { ffi::clutter_flow_layout_get_row_spacing(self.as_ref().to_glib_none().0) }
255 }
256
257 fn get_snap_to_grid(&self) -> bool {
258 unsafe {
259 from_glib(ffi::clutter_flow_layout_get_snap_to_grid(
260 self.as_ref().to_glib_none().0,
261 ))
262 }
263 }
264
265 fn set_column_spacing(&self, spacing: f32) {
266 unsafe {
267 ffi::clutter_flow_layout_set_column_spacing(self.as_ref().to_glib_none().0, spacing);
268 }
269 }
270
271 fn set_column_width(&self, min_width: f32, max_width: f32) {
272 unsafe {
273 ffi::clutter_flow_layout_set_column_width(
274 self.as_ref().to_glib_none().0,
275 min_width,
276 max_width,
277 );
278 }
279 }
280
281 fn set_homogeneous(&self, homogeneous: bool) {
282 unsafe {
283 ffi::clutter_flow_layout_set_homogeneous(
284 self.as_ref().to_glib_none().0,
285 homogeneous.to_glib(),
286 );
287 }
288 }
289
290 fn set_orientation(&self, orientation: FlowOrientation) {
291 unsafe {
292 ffi::clutter_flow_layout_set_orientation(
293 self.as_ref().to_glib_none().0,
294 orientation.to_glib(),
295 );
296 }
297 }
298
299 fn set_row_height(&self, min_height: f32, max_height: f32) {
300 unsafe {
301 ffi::clutter_flow_layout_set_row_height(
302 self.as_ref().to_glib_none().0,
303 min_height,
304 max_height,
305 );
306 }
307 }
308
309 fn set_row_spacing(&self, spacing: f32) {
310 unsafe {
311 ffi::clutter_flow_layout_set_row_spacing(self.as_ref().to_glib_none().0, spacing);
312 }
313 }
314
315 fn set_snap_to_grid(&self, snap_to_grid: bool) {
316 unsafe {
317 ffi::clutter_flow_layout_set_snap_to_grid(
318 self.as_ref().to_glib_none().0,
319 snap_to_grid.to_glib(),
320 );
321 }
322 }
323
324 fn get_property_max_column_width(&self) -> f32 {
325 unsafe {
326 let mut value = Value::from_type(<f32 as StaticType>::static_type());
327 gobject_sys::g_object_get_property(
328 self.to_glib_none().0 as *mut gobject_sys::GObject,
329 b"max-column-width\0".as_ptr() as *const _,
330 value.to_glib_none_mut().0,
331 );
332 value
333 .get()
334 .expect("Return Value for property `max-column-width` getter")
335 .unwrap()
336 }
337 }
338
339 fn set_property_max_column_width(&self, max_column_width: f32) {
340 unsafe {
341 gobject_sys::g_object_set_property(
342 self.to_glib_none().0 as *mut gobject_sys::GObject,
343 b"max-column-width\0".as_ptr() as *const _,
344 Value::from(&max_column_width).to_glib_none().0,
345 );
346 }
347 }
348
349 fn get_property_max_row_height(&self) -> f32 {
350 unsafe {
351 let mut value = Value::from_type(<f32 as StaticType>::static_type());
352 gobject_sys::g_object_get_property(
353 self.to_glib_none().0 as *mut gobject_sys::GObject,
354 b"max-row-height\0".as_ptr() as *const _,
355 value.to_glib_none_mut().0,
356 );
357 value
358 .get()
359 .expect("Return Value for property `max-row-height` getter")
360 .unwrap()
361 }
362 }
363
364 fn set_property_max_row_height(&self, max_row_height: f32) {
365 unsafe {
366 gobject_sys::g_object_set_property(
367 self.to_glib_none().0 as *mut gobject_sys::GObject,
368 b"max-row-height\0".as_ptr() as *const _,
369 Value::from(&max_row_height).to_glib_none().0,
370 );
371 }
372 }
373
374 fn get_property_min_column_width(&self) -> f32 {
375 unsafe {
376 let mut value = Value::from_type(<f32 as StaticType>::static_type());
377 gobject_sys::g_object_get_property(
378 self.to_glib_none().0 as *mut gobject_sys::GObject,
379 b"min-column-width\0".as_ptr() as *const _,
380 value.to_glib_none_mut().0,
381 );
382 value
383 .get()
384 .expect("Return Value for property `min-column-width` getter")
385 .unwrap()
386 }
387 }
388
389 fn set_property_min_column_width(&self, min_column_width: f32) {
390 unsafe {
391 gobject_sys::g_object_set_property(
392 self.to_glib_none().0 as *mut gobject_sys::GObject,
393 b"min-column-width\0".as_ptr() as *const _,
394 Value::from(&min_column_width).to_glib_none().0,
395 );
396 }
397 }
398
399 fn get_property_min_row_height(&self) -> f32 {
400 unsafe {
401 let mut value = Value::from_type(<f32 as StaticType>::static_type());
402 gobject_sys::g_object_get_property(
403 self.to_glib_none().0 as *mut gobject_sys::GObject,
404 b"min-row-height\0".as_ptr() as *const _,
405 value.to_glib_none_mut().0,
406 );
407 value
408 .get()
409 .expect("Return Value for property `min-row-height` getter")
410 .unwrap()
411 }
412 }
413
414 fn set_property_min_row_height(&self, min_row_height: f32) {
415 unsafe {
416 gobject_sys::g_object_set_property(
417 self.to_glib_none().0 as *mut gobject_sys::GObject,
418 b"min-row-height\0".as_ptr() as *const _,
419 Value::from(&min_row_height).to_glib_none().0,
420 );
421 }
422 }
423
424 fn connect_property_column_spacing_notify<F: Fn(&Self) + 'static>(
425 &self,
426 f: F,
427 ) -> SignalHandlerId {
428 unsafe extern "C" fn notify_column_spacing_trampoline<P, F: Fn(&P) + 'static>(
429 this: *mut ffi::ClutterFlowLayout,
430 _param_spec: glib_sys::gpointer,
431 f: glib_sys::gpointer,
432 ) where
433 P: IsA<FlowLayout>,
434 {
435 let f: &F = &*(f as *const F);
436 f(&FlowLayout::from_glib_borrow(this).unsafe_cast_ref())
437 }
438 unsafe {
439 let f: Box_<F> = Box_::new(f);
440 connect_raw(
441 self.as_ptr() as *mut _,
442 b"notify::column-spacing\0".as_ptr() as *const _,
443 Some(transmute::<_, unsafe extern "C" fn()>(
444 notify_column_spacing_trampoline::<Self, F> as *const (),
445 )),
446 Box_::into_raw(f),
447 )
448 }
449 }
450
451 fn connect_property_homogeneous_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
452 unsafe extern "C" fn notify_homogeneous_trampoline<P, F: Fn(&P) + 'static>(
453 this: *mut ffi::ClutterFlowLayout,
454 _param_spec: glib_sys::gpointer,
455 f: glib_sys::gpointer,
456 ) where
457 P: IsA<FlowLayout>,
458 {
459 let f: &F = &*(f as *const F);
460 f(&FlowLayout::from_glib_borrow(this).unsafe_cast_ref())
461 }
462 unsafe {
463 let f: Box_<F> = Box_::new(f);
464 connect_raw(
465 self.as_ptr() as *mut _,
466 b"notify::homogeneous\0".as_ptr() as *const _,
467 Some(transmute::<_, unsafe extern "C" fn()>(
468 notify_homogeneous_trampoline::<Self, F> as *const (),
469 )),
470 Box_::into_raw(f),
471 )
472 }
473 }
474
475 fn connect_property_max_column_width_notify<F: Fn(&Self) + 'static>(
476 &self,
477 f: F,
478 ) -> SignalHandlerId {
479 unsafe extern "C" fn notify_max_column_width_trampoline<P, F: Fn(&P) + 'static>(
480 this: *mut ffi::ClutterFlowLayout,
481 _param_spec: glib_sys::gpointer,
482 f: glib_sys::gpointer,
483 ) where
484 P: IsA<FlowLayout>,
485 {
486 let f: &F = &*(f as *const F);
487 f(&FlowLayout::from_glib_borrow(this).unsafe_cast_ref())
488 }
489 unsafe {
490 let f: Box_<F> = Box_::new(f);
491 connect_raw(
492 self.as_ptr() as *mut _,
493 b"notify::max-column-width\0".as_ptr() as *const _,
494 Some(transmute::<_, unsafe extern "C" fn()>(
495 notify_max_column_width_trampoline::<Self, F> as *const (),
496 )),
497 Box_::into_raw(f),
498 )
499 }
500 }
501
502 fn connect_property_max_row_height_notify<F: Fn(&Self) + 'static>(
503 &self,
504 f: F,
505 ) -> SignalHandlerId {
506 unsafe extern "C" fn notify_max_row_height_trampoline<P, F: Fn(&P) + 'static>(
507 this: *mut ffi::ClutterFlowLayout,
508 _param_spec: glib_sys::gpointer,
509 f: glib_sys::gpointer,
510 ) where
511 P: IsA<FlowLayout>,
512 {
513 let f: &F = &*(f as *const F);
514 f(&FlowLayout::from_glib_borrow(this).unsafe_cast_ref())
515 }
516 unsafe {
517 let f: Box_<F> = Box_::new(f);
518 connect_raw(
519 self.as_ptr() as *mut _,
520 b"notify::max-row-height\0".as_ptr() as *const _,
521 Some(transmute::<_, unsafe extern "C" fn()>(
522 notify_max_row_height_trampoline::<Self, F> as *const (),
523 )),
524 Box_::into_raw(f),
525 )
526 }
527 }
528
529 fn connect_property_min_column_width_notify<F: Fn(&Self) + 'static>(
530 &self,
531 f: F,
532 ) -> SignalHandlerId {
533 unsafe extern "C" fn notify_min_column_width_trampoline<P, F: Fn(&P) + 'static>(
534 this: *mut ffi::ClutterFlowLayout,
535 _param_spec: glib_sys::gpointer,
536 f: glib_sys::gpointer,
537 ) where
538 P: IsA<FlowLayout>,
539 {
540 let f: &F = &*(f as *const F);
541 f(&FlowLayout::from_glib_borrow(this).unsafe_cast_ref())
542 }
543 unsafe {
544 let f: Box_<F> = Box_::new(f);
545 connect_raw(
546 self.as_ptr() as *mut _,
547 b"notify::min-column-width\0".as_ptr() as *const _,
548 Some(transmute::<_, unsafe extern "C" fn()>(
549 notify_min_column_width_trampoline::<Self, F> as *const (),
550 )),
551 Box_::into_raw(f),
552 )
553 }
554 }
555
556 fn connect_property_min_row_height_notify<F: Fn(&Self) + 'static>(
557 &self,
558 f: F,
559 ) -> SignalHandlerId {
560 unsafe extern "C" fn notify_min_row_height_trampoline<P, F: Fn(&P) + 'static>(
561 this: *mut ffi::ClutterFlowLayout,
562 _param_spec: glib_sys::gpointer,
563 f: glib_sys::gpointer,
564 ) where
565 P: IsA<FlowLayout>,
566 {
567 let f: &F = &*(f as *const F);
568 f(&FlowLayout::from_glib_borrow(this).unsafe_cast_ref())
569 }
570 unsafe {
571 let f: Box_<F> = Box_::new(f);
572 connect_raw(
573 self.as_ptr() as *mut _,
574 b"notify::min-row-height\0".as_ptr() as *const _,
575 Some(transmute::<_, unsafe extern "C" fn()>(
576 notify_min_row_height_trampoline::<Self, F> as *const (),
577 )),
578 Box_::into_raw(f),
579 )
580 }
581 }
582
583 fn connect_property_orientation_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
584 unsafe extern "C" fn notify_orientation_trampoline<P, F: Fn(&P) + 'static>(
585 this: *mut ffi::ClutterFlowLayout,
586 _param_spec: glib_sys::gpointer,
587 f: glib_sys::gpointer,
588 ) where
589 P: IsA<FlowLayout>,
590 {
591 let f: &F = &*(f as *const F);
592 f(&FlowLayout::from_glib_borrow(this).unsafe_cast_ref())
593 }
594 unsafe {
595 let f: Box_<F> = Box_::new(f);
596 connect_raw(
597 self.as_ptr() as *mut _,
598 b"notify::orientation\0".as_ptr() as *const _,
599 Some(transmute::<_, unsafe extern "C" fn()>(
600 notify_orientation_trampoline::<Self, F> as *const (),
601 )),
602 Box_::into_raw(f),
603 )
604 }
605 }
606
607 fn connect_property_row_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
608 unsafe extern "C" fn notify_row_spacing_trampoline<P, F: Fn(&P) + 'static>(
609 this: *mut ffi::ClutterFlowLayout,
610 _param_spec: glib_sys::gpointer,
611 f: glib_sys::gpointer,
612 ) where
613 P: IsA<FlowLayout>,
614 {
615 let f: &F = &*(f as *const F);
616 f(&FlowLayout::from_glib_borrow(this).unsafe_cast_ref())
617 }
618 unsafe {
619 let f: Box_<F> = Box_::new(f);
620 connect_raw(
621 self.as_ptr() as *mut _,
622 b"notify::row-spacing\0".as_ptr() as *const _,
623 Some(transmute::<_, unsafe extern "C" fn()>(
624 notify_row_spacing_trampoline::<Self, F> as *const (),
625 )),
626 Box_::into_raw(f),
627 )
628 }
629 }
630
631 fn connect_property_snap_to_grid_notify<F: Fn(&Self) + 'static>(
632 &self,
633 f: F,
634 ) -> SignalHandlerId {
635 unsafe extern "C" fn notify_snap_to_grid_trampoline<P, F: Fn(&P) + 'static>(
636 this: *mut ffi::ClutterFlowLayout,
637 _param_spec: glib_sys::gpointer,
638 f: glib_sys::gpointer,
639 ) where
640 P: IsA<FlowLayout>,
641 {
642 let f: &F = &*(f as *const F);
643 f(&FlowLayout::from_glib_borrow(this).unsafe_cast_ref())
644 }
645 unsafe {
646 let f: Box_<F> = Box_::new(f);
647 connect_raw(
648 self.as_ptr() as *mut _,
649 b"notify::snap-to-grid\0".as_ptr() as *const _,
650 Some(transmute::<_, unsafe extern "C" fn()>(
651 notify_snap_to_grid_trampoline::<Self, F> as *const (),
652 )),
653 Box_::into_raw(f),
654 )
655 }
656 }
657}
658
659impl fmt::Display for FlowLayout {
660 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
661 write!(f, "FlowLayout")
662 }
663}