@@ -171,14 +171,47 @@ impl Expression {
171
171
}
172
172
173
173
// rustdoc-stripper-ignore-next
174
- /// Create a [`gtk::ClosureExpression`] with self as a parameter. This is useful in long
175
- /// chains of [`gtk::Expression`]s.
176
- pub fn chain_closure < F , R > ( & self , f : F ) -> crate :: ClosureExpression
174
+ /// Create a [`ClosureExpression`](crate::ClosureExpression) from a [`glib::Closure`] with self
175
+ /// as the second parameter and `R` as the return type. The return type is checked at run-time
176
+ /// and must always be specified. This is useful in long chains of
177
+ /// [`Expression`](crate::Expression)s when using the [`glib::closure!`] macro.
178
+ ///
179
+ /// Note that the first parameter will always be the `this` object bound to the expression. If
180
+ /// `None` is passed as `this` then the type of the first parameter must be
181
+ /// `Option<glib::Object>` otherwise type checking will panic.
182
+ ///
183
+ /// ```no_run
184
+ /// # use gtk4 as gtk;
185
+ /// use gtk::prelude::*;
186
+ /// use gtk::glib;
187
+ /// use glib::{closure, Object};
188
+ ///
189
+ /// let button = gtk::Button::new();
190
+ /// button.set_label("Hello");
191
+ /// let label = button
192
+ /// .property_expression("label")
193
+ /// .chain_closure::<String>(closure!(|_: Option<Object>, label: &str| {
194
+ /// format!("{} World", label)
195
+ /// }))
196
+ /// .evaluate_as::<String, _>(gtk::Widget::NONE);
197
+ /// assert_eq!(label.unwrap(), "Hello World");
198
+ /// ```
199
+ pub fn chain_closure < R > ( & self , closure : glib:: RustClosure ) -> crate :: ClosureExpression
200
+ where
201
+ R : glib:: value:: ValueType ,
202
+ {
203
+ crate :: ClosureExpression :: new :: < R , _ , _ > ( & [ self ] , closure)
204
+ }
205
+
206
+ // rustdoc-stripper-ignore-next
207
+ /// Create a [`ClosureExpression`](crate::ClosureExpression) with self as the second parameter.
208
+ /// This is useful in long chains of [`Expression`](crate::Expression)s.
209
+ pub fn chain_closure_with_callback < F , R > ( & self , f : F ) -> crate :: ClosureExpression
177
210
where
178
211
F : Fn ( & [ glib:: Value ] ) -> R + ' static ,
179
212
R : glib:: value:: ValueType ,
180
213
{
181
- crate :: ClosureExpression :: new ( & [ self ] , f)
214
+ crate :: ClosureExpression :: with_callback ( & [ self ] , f)
182
215
}
183
216
}
184
217
0 commit comments