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