Skip to main content

gtk4/auto/
bool_filter.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::{Expression, Filter, ffi};
6use glib::{
7    prelude::*,
8    signal::{SignalHandlerId, connect_raw},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    /// Evaluates a boolean expression to determine whether to include items.
15    ///
16    /// ## Properties
17    ///
18    ///
19    /// #### `expression`
20    ///  The boolean expression to evaluate on each item.
21    ///
22    /// Readable | Writeable
23    ///
24    ///
25    /// #### `invert`
26    ///  If the expression result should be inverted.
27    ///
28    /// Readable | Writeable
29    ///
30    /// # Implements
31    ///
32    /// [`FilterExt`][trait@crate::prelude::FilterExt], [`trait@glib::ObjectExt`]
33    #[doc(alias = "GtkBoolFilter")]
34    pub struct BoolFilter(Object<ffi::GtkBoolFilter, ffi::GtkBoolFilterClass>) @extends Filter;
35
36    match fn {
37        type_ => || ffi::gtk_bool_filter_get_type(),
38    }
39}
40
41impl BoolFilter {
42    /// Creates a new bool filter.
43    /// ## `expression`
44    /// the expression to evaluate
45    ///
46    /// # Returns
47    ///
48    /// a new [`BoolFilter`][crate::BoolFilter]
49    #[doc(alias = "gtk_bool_filter_new")]
50    pub fn new(expression: Option<impl AsRef<Expression>>) -> BoolFilter {
51        assert_initialized_main_thread!();
52        unsafe {
53            from_glib_full(ffi::gtk_bool_filter_new(
54                expression
55                    .map(|p| p.as_ref().clone().upcast())
56                    .into_glib_ptr(),
57            ))
58        }
59    }
60
61    // rustdoc-stripper-ignore-next
62    /// Creates a new builder-pattern struct instance to construct [`BoolFilter`] objects.
63    ///
64    /// This method returns an instance of [`BoolFilterBuilder`](crate::builders::BoolFilterBuilder) which can be used to create [`BoolFilter`] objects.
65    pub fn builder() -> BoolFilterBuilder {
66        BoolFilterBuilder::new()
67    }
68
69    /// Gets the expression that the filter evaluates for
70    /// each item.
71    ///
72    /// # Returns
73    ///
74    /// the expression
75    #[doc(alias = "gtk_bool_filter_get_expression")]
76    #[doc(alias = "get_expression")]
77    pub fn expression(&self) -> Option<Expression> {
78        unsafe { from_glib_none(ffi::gtk_bool_filter_get_expression(self.to_glib_none().0)) }
79    }
80
81    /// Returns whether the filter inverts the expression.
82    ///
83    /// # Returns
84    ///
85    /// true if the filter inverts
86    #[doc(alias = "gtk_bool_filter_get_invert")]
87    #[doc(alias = "get_invert")]
88    #[doc(alias = "invert")]
89    pub fn inverts(&self) -> bool {
90        unsafe { from_glib(ffi::gtk_bool_filter_get_invert(self.to_glib_none().0)) }
91    }
92
93    /// Sets the expression that the filter uses to check if items
94    /// should be filtered.
95    ///
96    /// The expression must have a value type of `G_TYPE_BOOLEAN`.
97    /// ## `expression`
98    /// the expression
99    #[doc(alias = "gtk_bool_filter_set_expression")]
100    #[doc(alias = "expression")]
101    pub fn set_expression(&self, expression: Option<impl AsRef<Expression>>) {
102        unsafe {
103            ffi::gtk_bool_filter_set_expression(
104                self.to_glib_none().0,
105                expression.as_ref().map(|p| p.as_ref()).to_glib_none().0,
106            );
107        }
108    }
109
110    /// Sets whether the filter should invert the expression.
111    /// ## `invert`
112    /// true to invert
113    #[doc(alias = "gtk_bool_filter_set_invert")]
114    #[doc(alias = "invert")]
115    pub fn set_invert(&self, invert: bool) {
116        unsafe {
117            ffi::gtk_bool_filter_set_invert(self.to_glib_none().0, invert.into_glib());
118        }
119    }
120
121    #[doc(alias = "expression")]
122    pub fn connect_expression_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
123        unsafe extern "C" fn notify_expression_trampoline<F: Fn(&BoolFilter) + 'static>(
124            this: *mut ffi::GtkBoolFilter,
125            _param_spec: glib::ffi::gpointer,
126            f: glib::ffi::gpointer,
127        ) {
128            unsafe {
129                let f: &F = &*(f as *const F);
130                f(&from_glib_borrow(this))
131            }
132        }
133        unsafe {
134            let f: Box_<F> = Box_::new(f);
135            connect_raw(
136                self.as_ptr() as *mut _,
137                c"notify::expression".as_ptr() as *const _,
138                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
139                    notify_expression_trampoline::<F> as *const (),
140                )),
141                Box_::into_raw(f),
142            )
143        }
144    }
145
146    #[doc(alias = "invert")]
147    pub fn connect_invert_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
148        unsafe extern "C" fn notify_invert_trampoline<F: Fn(&BoolFilter) + 'static>(
149            this: *mut ffi::GtkBoolFilter,
150            _param_spec: glib::ffi::gpointer,
151            f: glib::ffi::gpointer,
152        ) {
153            unsafe {
154                let f: &F = &*(f as *const F);
155                f(&from_glib_borrow(this))
156            }
157        }
158        unsafe {
159            let f: Box_<F> = Box_::new(f);
160            connect_raw(
161                self.as_ptr() as *mut _,
162                c"notify::invert".as_ptr() as *const _,
163                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
164                    notify_invert_trampoline::<F> as *const (),
165                )),
166                Box_::into_raw(f),
167            )
168        }
169    }
170}
171
172impl Default for BoolFilter {
173    fn default() -> Self {
174        glib::object::Object::new::<Self>()
175    }
176}
177
178// rustdoc-stripper-ignore-next
179/// A [builder-pattern] type to construct [`BoolFilter`] objects.
180///
181/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
182#[must_use = "The builder must be built to be used"]
183pub struct BoolFilterBuilder {
184    builder: glib::object::ObjectBuilder<'static, BoolFilter>,
185}
186
187impl BoolFilterBuilder {
188    fn new() -> Self {
189        Self {
190            builder: glib::object::Object::builder(),
191        }
192    }
193
194    /// The boolean expression to evaluate on each item.
195    pub fn expression(self, expression: impl AsRef<Expression>) -> Self {
196        Self {
197            builder: self
198                .builder
199                .property("expression", expression.as_ref().clone()),
200        }
201    }
202
203    /// If the expression result should be inverted.
204    pub fn invert(self, invert: bool) -> Self {
205        Self {
206            builder: self.builder.property("invert", invert),
207        }
208    }
209
210    // rustdoc-stripper-ignore-next
211    /// Build the [`BoolFilter`].
212    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
213    pub fn build(self) -> BoolFilter {
214        assert_initialized_main_thread!();
215        self.builder.build()
216    }
217}