libadwaita 0.9.1

Rust bindings for libadwaita
Documentation
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files.git)
// DO NOT EDIT

#[cfg(feature = "v1_4")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
use crate::LengthUnit;
use crate::ffi;
use glib::{
    prelude::*,
    signal::{SignalHandlerId, connect_raw},
    translate::*,
};
use std::boxed::Box as Box_;

glib::wrapper! {
    #[doc(alias = "AdwClampLayout")]
    pub struct ClampLayout(Object<ffi::AdwClampLayout, ffi::AdwClampLayoutClass>) @extends gtk::LayoutManager, @implements gtk::Orientable;

    match fn {
        type_ => || ffi::adw_clamp_layout_get_type(),
    }
}

impl ClampLayout {
    #[doc(alias = "adw_clamp_layout_new")]
    pub fn new() -> ClampLayout {
        assert_initialized_main_thread!();
        unsafe { gtk::LayoutManager::from_glib_full(ffi::adw_clamp_layout_new()).unsafe_cast() }
    }

    // rustdoc-stripper-ignore-next
    /// Creates a new builder-pattern struct instance to construct [`ClampLayout`] objects.
    ///
    /// This method returns an instance of [`ClampLayoutBuilder`](crate::builders::ClampLayoutBuilder) which can be used to create [`ClampLayout`] objects.
    pub fn builder() -> ClampLayoutBuilder {
        ClampLayoutBuilder::new()
    }

    #[doc(alias = "adw_clamp_layout_get_maximum_size")]
    #[doc(alias = "get_maximum_size")]
    #[doc(alias = "maximum-size")]
    pub fn maximum_size(&self) -> i32 {
        unsafe { ffi::adw_clamp_layout_get_maximum_size(self.to_glib_none().0) }
    }

    #[doc(alias = "adw_clamp_layout_get_tightening_threshold")]
    #[doc(alias = "get_tightening_threshold")]
    #[doc(alias = "tightening-threshold")]
    pub fn tightening_threshold(&self) -> i32 {
        unsafe { ffi::adw_clamp_layout_get_tightening_threshold(self.to_glib_none().0) }
    }

    #[cfg(feature = "v1_4")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
    #[doc(alias = "adw_clamp_layout_get_unit")]
    #[doc(alias = "get_unit")]
    pub fn unit(&self) -> LengthUnit {
        unsafe { from_glib(ffi::adw_clamp_layout_get_unit(self.to_glib_none().0)) }
    }

    #[doc(alias = "adw_clamp_layout_set_maximum_size")]
    #[doc(alias = "maximum-size")]
    pub fn set_maximum_size(&self, maximum_size: i32) {
        unsafe {
            ffi::adw_clamp_layout_set_maximum_size(self.to_glib_none().0, maximum_size);
        }
    }

    #[doc(alias = "adw_clamp_layout_set_tightening_threshold")]
    #[doc(alias = "tightening-threshold")]
    pub fn set_tightening_threshold(&self, tightening_threshold: i32) {
        unsafe {
            ffi::adw_clamp_layout_set_tightening_threshold(
                self.to_glib_none().0,
                tightening_threshold,
            );
        }
    }

    #[cfg(feature = "v1_4")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
    #[doc(alias = "adw_clamp_layout_set_unit")]
    #[doc(alias = "unit")]
    pub fn set_unit(&self, unit: LengthUnit) {
        unsafe {
            ffi::adw_clamp_layout_set_unit(self.to_glib_none().0, unit.into_glib());
        }
    }

    #[doc(alias = "maximum-size")]
    pub fn connect_maximum_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_maximum_size_trampoline<F: Fn(&ClampLayout) + 'static>(
            this: *mut ffi::AdwClampLayout,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(&from_glib_borrow(this))
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::maximum-size".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_maximum_size_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "tightening-threshold")]
    pub fn connect_tightening_threshold_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_tightening_threshold_trampoline<
            F: Fn(&ClampLayout) + 'static,
        >(
            this: *mut ffi::AdwClampLayout,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(&from_glib_borrow(this))
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::tightening-threshold".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_tightening_threshold_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[cfg(feature = "v1_4")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
    #[doc(alias = "unit")]
    pub fn connect_unit_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_unit_trampoline<F: Fn(&ClampLayout) + 'static>(
            this: *mut ffi::AdwClampLayout,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(&from_glib_borrow(this))
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::unit".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_unit_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl Default for ClampLayout {
    fn default() -> Self {
        Self::new()
    }
}

// rustdoc-stripper-ignore-next
/// A [builder-pattern] type to construct [`ClampLayout`] objects.
///
/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
#[must_use = "The builder must be built to be used"]
pub struct ClampLayoutBuilder {
    builder: glib::object::ObjectBuilder<'static, ClampLayout>,
}

impl ClampLayoutBuilder {
    fn new() -> Self {
        Self {
            builder: glib::object::Object::builder(),
        }
    }

    pub fn maximum_size(self, maximum_size: i32) -> Self {
        Self {
            builder: self.builder.property("maximum-size", maximum_size),
        }
    }

    pub fn tightening_threshold(self, tightening_threshold: i32) -> Self {
        Self {
            builder: self
                .builder
                .property("tightening-threshold", tightening_threshold),
        }
    }

    #[cfg(feature = "v1_4")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
    pub fn unit(self, unit: LengthUnit) -> Self {
        Self {
            builder: self.builder.property("unit", unit),
        }
    }

    pub fn orientation(self, orientation: gtk::Orientation) -> Self {
        Self {
            builder: self.builder.property("orientation", orientation),
        }
    }

    // rustdoc-stripper-ignore-next
    /// Build the [`ClampLayout`].
    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
    pub fn build(self) -> ClampLayout {
        assert_initialized_main_thread!();
        self.builder.build()
    }
}