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