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::{ffi, Expression, Filter};
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
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            let f: &F = &*(f as *const F);
129            f(&from_glib_borrow(this))
130        }
131        unsafe {
132            let f: Box_<F> = Box_::new(f);
133            connect_raw(
134                self.as_ptr() as *mut _,
135                c"notify::expression".as_ptr() as *const _,
136                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
137                    notify_expression_trampoline::<F> as *const (),
138                )),
139                Box_::into_raw(f),
140            )
141        }
142    }
143
144    #[doc(alias = "invert")]
145    pub fn connect_invert_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
146        unsafe extern "C" fn notify_invert_trampoline<F: Fn(&BoolFilter) + 'static>(
147            this: *mut ffi::GtkBoolFilter,
148            _param_spec: glib::ffi::gpointer,
149            f: glib::ffi::gpointer,
150        ) {
151            let f: &F = &*(f as *const F);
152            f(&from_glib_borrow(this))
153        }
154        unsafe {
155            let f: Box_<F> = Box_::new(f);
156            connect_raw(
157                self.as_ptr() as *mut _,
158                c"notify::invert".as_ptr() as *const _,
159                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
160                    notify_invert_trampoline::<F> as *const (),
161                )),
162                Box_::into_raw(f),
163            )
164        }
165    }
166}
167
168impl Default for BoolFilter {
169    fn default() -> Self {
170        glib::object::Object::new::<Self>()
171    }
172}
173
174// rustdoc-stripper-ignore-next
175/// A [builder-pattern] type to construct [`BoolFilter`] objects.
176///
177/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
178#[must_use = "The builder must be built to be used"]
179pub struct BoolFilterBuilder {
180    builder: glib::object::ObjectBuilder<'static, BoolFilter>,
181}
182
183impl BoolFilterBuilder {
184    fn new() -> Self {
185        Self {
186            builder: glib::object::Object::builder(),
187        }
188    }
189
190    /// The boolean expression to evaluate on each item.
191    pub fn expression(self, expression: impl AsRef<Expression>) -> Self {
192        Self {
193            builder: self
194                .builder
195                .property("expression", expression.as_ref().clone()),
196        }
197    }
198
199    /// If the expression result should be inverted.
200    pub fn invert(self, invert: bool) -> Self {
201        Self {
202            builder: self.builder.property("invert", invert),
203        }
204    }
205
206    // rustdoc-stripper-ignore-next
207    /// Build the [`BoolFilter`].
208    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
209    pub fn build(self) -> BoolFilter {
210        assert_initialized_main_thread!();
211        self.builder.build()
212    }
213}