gtk4/auto/
orientable.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use 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
26mod sealed {
27    pub trait Sealed {}
28    impl<T: super::IsA<super::Orientable>> Sealed for T {}
29}
30
31pub trait OrientableExt: IsA<Orientable> + sealed::Sealed + 'static {
32    #[doc(alias = "gtk_orientable_get_orientation")]
33    #[doc(alias = "get_orientation")]
34    fn orientation(&self) -> Orientation {
35        unsafe {
36            from_glib(ffi::gtk_orientable_get_orientation(
37                self.as_ref().to_glib_none().0,
38            ))
39        }
40    }
41
42    #[doc(alias = "gtk_orientable_set_orientation")]
43    #[doc(alias = "orientation")]
44    fn set_orientation(&self, orientation: Orientation) {
45        unsafe {
46            ffi::gtk_orientable_set_orientation(
47                self.as_ref().to_glib_none().0,
48                orientation.into_glib(),
49            );
50        }
51    }
52
53    #[doc(alias = "orientation")]
54    fn connect_orientation_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
55        unsafe extern "C" fn notify_orientation_trampoline<
56            P: IsA<Orientable>,
57            F: Fn(&P) + 'static,
58        >(
59            this: *mut ffi::GtkOrientable,
60            _param_spec: glib::ffi::gpointer,
61            f: glib::ffi::gpointer,
62        ) {
63            let f: &F = &*(f as *const F);
64            f(Orientable::from_glib_borrow(this).unsafe_cast_ref())
65        }
66        unsafe {
67            let f: Box_<F> = Box_::new(f);
68            connect_raw(
69                self.as_ptr() as *mut _,
70                b"notify::orientation\0".as_ptr() as *const _,
71                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
72                    notify_orientation_trampoline::<Self, F> as *const (),
73                )),
74                Box_::into_raw(f),
75            )
76        }
77    }
78}
79
80impl<O: IsA<Orientable>> OrientableExt for O {}