1use crate::{ffi, Orientation};
6use glib::{
7 prelude::*,
8 signal::{connect_raw, SignalHandlerId},
9 translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14 #[doc(alias = "GtkOrientable")]
15 pub struct Orientable(Interface<ffi::GtkOrientable, ffi::GtkOrientableIface>);
16
17 match fn {
18 type_ => || ffi::gtk_orientable_get_type(),
19 }
20}
21
22impl Orientable {
23 pub const NONE: Option<&'static Orientable> = None;
24}
25
26pub trait OrientableExt: IsA<Orientable> + 'static {
27 #[doc(alias = "gtk_orientable_get_orientation")]
28 #[doc(alias = "get_orientation")]
29 fn orientation(&self) -> Orientation {
30 unsafe {
31 from_glib(ffi::gtk_orientable_get_orientation(
32 self.as_ref().to_glib_none().0,
33 ))
34 }
35 }
36
37 #[doc(alias = "gtk_orientable_set_orientation")]
38 #[doc(alias = "orientation")]
39 fn set_orientation(&self, orientation: Orientation) {
40 unsafe {
41 ffi::gtk_orientable_set_orientation(
42 self.as_ref().to_glib_none().0,
43 orientation.into_glib(),
44 );
45 }
46 }
47
48 #[doc(alias = "orientation")]
49 fn connect_orientation_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
50 unsafe extern "C" fn notify_orientation_trampoline<
51 P: IsA<Orientable>,
52 F: Fn(&P) + 'static,
53 >(
54 this: *mut ffi::GtkOrientable,
55 _param_spec: glib::ffi::gpointer,
56 f: glib::ffi::gpointer,
57 ) {
58 let f: &F = &*(f as *const F);
59 f(Orientable::from_glib_borrow(this).unsafe_cast_ref())
60 }
61 unsafe {
62 let f: Box_<F> = Box_::new(f);
63 connect_raw(
64 self.as_ptr() as *mut _,
65 c"notify::orientation".as_ptr() as *const _,
66 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
67 notify_orientation_trampoline::<Self, F> as *const (),
68 )),
69 Box_::into_raw(f),
70 )
71 }
72 }
73}
74
75impl<O: IsA<Orientable>> OrientableExt for O {}