gtk4/auto/
bool_filter.rs
1use 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 #[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 #[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 pub fn builder() -> BoolFilterBuilder {
66 BoolFilterBuilder::new()
67 }
68
69 #[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 #[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 #[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 #[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#[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 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 pub fn invert(self, invert: bool) -> Self {
201 Self {
202 builder: self.builder.property("invert", invert),
203 }
204 }
205
206 #[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}