libadwaita 0.9.2

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_10")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_10")))]
use crate::CssClassBinding;
use crate::ffi;
use glib::{prelude::*, translate::*};
#[cfg(feature = "v1_10")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_10")))]
use std::boxed::Box as Box_;

#[cfg(feature = "v1_10")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_10")))]
#[doc(alias = "adw_bind_property_to_css_class")]
pub fn bind_property_to_css_class(
    source: &impl IsA<glib::Object>,
    source_property: &str,
    target: &impl IsA<gtk::Widget>,
    target_css_class: &str,
    flags: glib::BindingFlags,
) -> CssClassBinding {
    assert_initialized_main_thread!();
    unsafe {
        from_glib_none(ffi::adw_bind_property_to_css_class(
            source.as_ref().to_glib_none().0,
            source_property.to_glib_none().0,
            target.as_ref().to_glib_none().0,
            target_css_class.to_glib_none().0,
            flags.into_glib(),
        ))
    }
}

#[cfg(feature = "v1_10")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_10")))]
#[doc(alias = "adw_bind_property_to_css_class_full")]
pub fn bind_property_to_css_class_full(
    source: &impl IsA<glib::Object>,
    source_property: &str,
    target: &impl IsA<gtk::Widget>,
    target_css_class: &str,
    flags: glib::BindingFlags,
    map_to_class: Option<Box_<dyn Fn(&CssClassBinding, &glib::Value) -> bool + 'static>>,
    map_to_property: Option<Box_<dyn Fn(&CssClassBinding, bool, &glib::Value) + 'static>>,
) -> CssClassBinding {
    assert_initialized_main_thread!();
    let map_to_class_data: Option<Box_<dyn Fn(&CssClassBinding, &glib::Value) -> bool + 'static>> =
        map_to_class;
    unsafe extern "C" fn map_to_class_func(
        self_: *mut ffi::AdwCssClassBinding,
        property_value: *const glib::gobject_ffi::GValue,
        user_data: glib::ffi::gpointer,
    ) -> glib::ffi::gboolean {
        unsafe {
            let self_ = from_glib_borrow(self_);
            let property_value = from_glib_borrow(property_value);
            let callback: &(
                Option<Box_<dyn Fn(&CssClassBinding, &glib::Value) -> bool + 'static>>,
                Option<Box_<dyn Fn(&CssClassBinding, bool, &glib::Value) + 'static>>,
            ) = &*(user_data as *mut _);
            if let Some(ref callback) = callback.0 {
                callback(&self_, &property_value)
            } else {
                panic!("cannot get closure...")
            }
            .into_glib()
        }
    }
    let map_to_class = if map_to_class_data.is_some() {
        Some(map_to_class_func as _)
    } else {
        None
    };
    let map_to_property_data: Option<Box_<dyn Fn(&CssClassBinding, bool, &glib::Value) + 'static>> =
        map_to_property;
    unsafe extern "C" fn map_to_property_func(
        self_: *mut ffi::AdwCssClassBinding,
        class_applied: glib::ffi::gboolean,
        property_value: *mut glib::gobject_ffi::GValue,
        user_data: glib::ffi::gpointer,
    ) {
        unsafe {
            let self_ = from_glib_borrow(self_);
            let class_applied = from_glib(class_applied);
            let property_value = from_glib_borrow(property_value);
            let callback: &(
                Option<Box_<dyn Fn(&CssClassBinding, &glib::Value) -> bool + 'static>>,
                Option<Box_<dyn Fn(&CssClassBinding, bool, &glib::Value) + 'static>>,
            ) = &*(user_data as *mut _);
            if let Some(ref callback) = callback.1 {
                callback(&self_, class_applied, &property_value)
            } else {
                panic!("cannot get closure...")
            }
        }
    }
    let map_to_property = if map_to_property_data.is_some() {
        Some(map_to_property_func as _)
    } else {
        None
    };
    unsafe extern "C" fn notify_func(data: glib::ffi::gpointer) {
        unsafe {
            let _callback: Box_<(
                Option<Box_<dyn Fn(&CssClassBinding, &glib::Value) -> bool + 'static>>,
                Option<Box_<dyn Fn(&CssClassBinding, bool, &glib::Value) + 'static>>,
            )> = Box_::from_raw(data as *mut _);
        }
    }
    let destroy_call8 = Some(notify_func as _);
    let super_callback0: Box_<(
        Option<Box_<dyn Fn(&CssClassBinding, &glib::Value) -> bool + 'static>>,
        Option<Box_<dyn Fn(&CssClassBinding, bool, &glib::Value) + 'static>>,
    )> = Box_::new((map_to_class_data, map_to_property_data));
    unsafe {
        from_glib_none(ffi::adw_bind_property_to_css_class_full(
            source.as_ref().to_glib_none().0,
            source_property.to_glib_none().0,
            target.as_ref().to_glib_none().0,
            target_css_class.to_glib_none().0,
            flags.into_glib(),
            map_to_class,
            map_to_property,
            Box_::into_raw(super_callback0) as *mut _,
            destroy_call8,
        ))
    }
}

#[doc(alias = "adw_get_enable_animations")]
#[doc(alias = "get_enable_animations")]
pub fn is_animations_enabled(widget: &impl IsA<gtk::Widget>) -> bool {
    assert_initialized_main_thread!();
    unsafe {
        from_glib(ffi::adw_get_enable_animations(
            widget.as_ref().to_glib_none().0,
        ))
    }
}

#[doc(alias = "adw_get_major_version")]
#[doc(alias = "get_major_version")]
pub fn major_version() -> u32 {
    assert_initialized_main_thread!();
    unsafe { ffi::adw_get_major_version() }
}

#[doc(alias = "adw_get_micro_version")]
#[doc(alias = "get_micro_version")]
pub fn micro_version() -> u32 {
    assert_initialized_main_thread!();
    unsafe { ffi::adw_get_micro_version() }
}

#[doc(alias = "adw_get_minor_version")]
#[doc(alias = "get_minor_version")]
pub fn minor_version() -> u32 {
    assert_initialized_main_thread!();
    unsafe { ffi::adw_get_minor_version() }
}

#[doc(alias = "adw_is_initialized")]
pub fn is_initialized() -> bool {
    assert_initialized_main_thread!();
    unsafe { from_glib(ffi::adw_is_initialized()) }
}

#[doc(alias = "adw_lerp")]
pub fn lerp(a: f64, b: f64, t: f64) -> f64 {
    assert_initialized_main_thread!();
    unsafe { ffi::adw_lerp(a, b, t) }
}

#[cfg(feature = "v1_6")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_6")))]
#[doc(alias = "adw_rgba_to_standalone")]
pub fn rgba_to_standalone(rgba: &gdk::RGBA, dark: bool) -> gdk::RGBA {
    assert_initialized_main_thread!();
    unsafe {
        let mut standalone_rgba = gdk::RGBA::uninitialized();
        ffi::adw_rgba_to_standalone(
            rgba.to_glib_none().0,
            dark.into_glib(),
            standalone_rgba.to_glib_none_mut().0,
        );
        standalone_rgba
    }
}