glib/gobject/auto/
binding_group.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::{
6    Object, ffi,
7    prelude::*,
8    signal::{SignalHandlerId, connect_raw},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13crate::wrapper! {
14    /// `GBindingGroup` can be used to bind multiple properties
15    /// from an object collectively.
16    ///
17    /// Use the various methods to bind properties from a single source
18    /// object to multiple destination objects. Properties can be bound
19    /// bidirectionally and are connected when the source object is set
20    /// with [method[`Object`][crate::Object].set_source].
21    ///
22    /// ## Properties
23    ///
24    ///
25    /// #### `source`
26    ///  The source object used for binding properties.
27    ///
28    /// Readable | Writeable
29    ///
30    /// # Implements
31    ///
32    /// [`ObjectExt`][trait@crate::prelude::ObjectExt]
33    #[doc(alias = "GBindingGroup")]
34    pub struct BindingGroup(Object<crate::gobject_ffi::GBindingGroup>);
35
36    match fn {
37        type_ => || crate::gobject_ffi::g_binding_group_get_type(),
38    }
39}
40
41impl BindingGroup {
42    /// Creates a new [`BindingGroup`][crate::BindingGroup].
43    ///
44    /// # Returns
45    ///
46    /// a new [`BindingGroup`][crate::BindingGroup]
47    #[doc(alias = "g_binding_group_new")]
48    pub fn new() -> BindingGroup {
49        unsafe { from_glib_full(crate::gobject_ffi::g_binding_group_new()) }
50    }
51
52    /// Gets the source object used for binding properties.
53    ///
54    /// # Returns
55    ///
56    /// a [`Object`][crate::Object] or [`None`].
57    #[doc(alias = "g_binding_group_dup_source")]
58    #[doc(alias = "dup_source")]
59    pub fn source(&self) -> Option<Object> {
60        unsafe {
61            from_glib_none(crate::gobject_ffi::g_binding_group_dup_source(
62                self.to_glib_none().0,
63            ))
64        }
65    }
66
67    /// Sets `source` as the source object used for creating property
68    /// bindings. If there is already a source object all bindings from it
69    /// will be removed.
70    ///
71    /// Note that all properties that have been bound must exist on `source`.
72    /// ## `source`
73    /// the source [`Object`][crate::Object],
74    ///  or [`None`] to clear it
75    #[doc(alias = "g_binding_group_set_source")]
76    #[doc(alias = "source")]
77    pub fn set_source(&self, source: Option<&impl IsA<Object>>) {
78        unsafe {
79            crate::gobject_ffi::g_binding_group_set_source(
80                self.to_glib_none().0,
81                source.map(|p| p.as_ref()).to_glib_none().0,
82            );
83        }
84    }
85
86    #[cfg(feature = "v2_72")]
87    #[cfg_attr(docsrs, doc(cfg(feature = "v2_72")))]
88    #[doc(alias = "source")]
89    pub fn connect_source_notify<F: Fn(&Self) + Send + Sync + 'static>(
90        &self,
91        f: F,
92    ) -> SignalHandlerId {
93        unsafe extern "C" fn notify_source_trampoline<
94            F: Fn(&BindingGroup) + Send + Sync + 'static,
95        >(
96            this: *mut crate::gobject_ffi::GBindingGroup,
97            _param_spec: ffi::gpointer,
98            f: ffi::gpointer,
99        ) {
100            unsafe {
101                let f: &F = &*(f as *const F);
102                f(&from_glib_borrow(this))
103            }
104        }
105        unsafe {
106            let f: Box_<F> = Box_::new(f);
107            connect_raw(
108                self.as_ptr() as *mut _,
109                c"notify::source".as_ptr() as *const _,
110                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
111                    notify_source_trampoline::<F> as *const (),
112                )),
113                Box_::into_raw(f),
114            )
115        }
116    }
117}
118
119#[cfg(feature = "v2_72")]
120#[cfg_attr(docsrs, doc(cfg(feature = "v2_72")))]
121impl Default for BindingGroup {
122    fn default() -> Self {
123        Self::new()
124    }
125}
126
127unsafe impl Send for BindingGroup {}
128unsafe impl Sync for BindingGroup {}