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    /// The [`Orientable`][crate::Orientable] interface is implemented by all widgets that can be
15    /// oriented horizontally or vertically.
16    ///
17    /// [`Orientable`][crate::Orientable] is more flexible in that it allows the orientation to be
18    /// changed at runtime, allowing the widgets to “flip”.
19    ///
20    /// ## CSS nodes
21    ///
22    /// [`Widget`][crate::Widget] types implementing the [`Orientable`][crate::Orientable] interface will
23    /// automatically acquire the `horizontal` or `vertical` CSS class depending on
24    /// the value of the [`orientation`][struct@crate::Orientable#orientation] property.
25    ///
26    /// ## Properties
27    ///
28    ///
29    /// #### `orientation`
30    ///  The orientation of the orientable.
31    ///
32    /// Readable | Writeable
33    ///
34    /// # Implements
35    ///
36    /// [`OrientableExt`][trait@crate::prelude::OrientableExt]
37    #[doc(alias = "GtkOrientable")]
38    pub struct Orientable(Interface<ffi::GtkOrientable, ffi::GtkOrientableIface>);
39
40    match fn {
41        type_ => || ffi::gtk_orientable_get_type(),
42    }
43}
44
45impl Orientable {
46    pub const NONE: Option<&'static Orientable> = None;
47}
48
49mod sealed {
50    pub trait Sealed {}
51    impl<T: super::IsA<super::Orientable>> Sealed for T {}
52}
53
54/// Trait containing all [`struct@Orientable`] methods.
55///
56/// # Implementors
57///
58/// [`BoxLayout`][struct@crate::BoxLayout], [`Box`][struct@crate::Box], [`CellAreaBox`][struct@crate::CellAreaBox], [`CellRendererProgress`][struct@crate::CellRendererProgress], [`CellView`][struct@crate::CellView], [`CenterBox`][struct@crate::CenterBox], [`FlowBox`][struct@crate::FlowBox], [`GridView`][struct@crate::GridView], [`Grid`][struct@crate::Grid], [`LevelBar`][struct@crate::LevelBar], [`ListBase`][struct@crate::ListBase], [`ListView`][struct@crate::ListView], [`Orientable`][struct@crate::Orientable], [`Paned`][struct@crate::Paned], [`ProgressBar`][struct@crate::ProgressBar], [`Range`][struct@crate::Range], [`ScaleButton`][struct@crate::ScaleButton], [`Scale`][struct@crate::Scale], [`Scrollbar`][struct@crate::Scrollbar], [`Separator`][struct@crate::Separator], [`ShortcutsGroup`][struct@crate::ShortcutsGroup], [`ShortcutsSection`][struct@crate::ShortcutsSection], [`SpinButton`][struct@crate::SpinButton], [`StackSwitcher`][struct@crate::StackSwitcher], [`VolumeButton`][struct@crate::VolumeButton]
59pub trait OrientableExt: IsA<Orientable> + sealed::Sealed + 'static {
60    /// Retrieves the orientation of the @self.
61    ///
62    /// # Returns
63    ///
64    /// the orientation of the @self
65    #[doc(alias = "gtk_orientable_get_orientation")]
66    #[doc(alias = "get_orientation")]
67    fn orientation(&self) -> Orientation {
68        unsafe {
69            from_glib(ffi::gtk_orientable_get_orientation(
70                self.as_ref().to_glib_none().0,
71            ))
72        }
73    }
74
75    /// Sets the orientation of the @self.
76    /// ## `orientation`
77    /// the orientable’s new orientation
78    #[doc(alias = "gtk_orientable_set_orientation")]
79    #[doc(alias = "orientation")]
80    fn set_orientation(&self, orientation: Orientation) {
81        unsafe {
82            ffi::gtk_orientable_set_orientation(
83                self.as_ref().to_glib_none().0,
84                orientation.into_glib(),
85            );
86        }
87    }
88
89    #[doc(alias = "orientation")]
90    fn connect_orientation_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
91        unsafe extern "C" fn notify_orientation_trampoline<
92            P: IsA<Orientable>,
93            F: Fn(&P) + 'static,
94        >(
95            this: *mut ffi::GtkOrientable,
96            _param_spec: glib::ffi::gpointer,
97            f: glib::ffi::gpointer,
98        ) {
99            let f: &F = &*(f as *const F);
100            f(Orientable::from_glib_borrow(this).unsafe_cast_ref())
101        }
102        unsafe {
103            let f: Box_<F> = Box_::new(f);
104            connect_raw(
105                self.as_ptr() as *mut _,
106                b"notify::orientation\0".as_ptr() as *const _,
107                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
108                    notify_orientation_trampoline::<Self, F> as *const (),
109                )),
110                Box_::into_raw(f),
111            )
112        }
113    }
114}
115
116impl<O: IsA<Orientable>> OrientableExt for O {}