[fractal/fractal-next] utils: Add boolean operator Expressions



commit fe35bf0bc63943652058d9850ab953ca18aa2b90
Author: Kai A. Hiller <V02460 gmail com>
Date:   Thu Aug 12 15:56:18 2021 +0200

    utils: Add boolean operator Expressions

 src/utils.rs | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
---
diff --git a/src/utils.rs b/src/utils.rs
index 7b5e8d3b..fb0d93f0 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -61,3 +61,44 @@ pub fn prop_expr<T: IsA<Object>>(object: &T, prop: &str) -> gtk::Expression {
     let obj_expr = gtk::ConstantExpression::new(object).upcast();
     gtk::PropertyExpression::new(T::static_type(), Some(&obj_expr), prop).upcast()
 }
+
+// Returns an expression that is the and’ed result of the given boolean expressions.
+#[allow(dead_code)]
+pub fn and_expr(a_expr: gtk::Expression, b_expr: gtk::Expression) -> gtk::Expression {
+    gtk::ClosureExpression::new(
+        move |args| {
+            let a: bool = args[1].get().unwrap();
+            let b: bool = args[2].get().unwrap();
+            a && b
+        },
+        &[a_expr, b_expr],
+    )
+    .upcast()
+}
+
+// Returns an expression that is the or’ed result of the given boolean expressions.
+#[allow(dead_code)]
+pub fn or_expr(a_expr: gtk::Expression, b_expr: gtk::Expression) -> gtk::Expression {
+    gtk::ClosureExpression::new(
+        move |args| {
+            let a: bool = args[1].get().unwrap();
+            let b: bool = args[2].get().unwrap();
+            a || b
+        },
+        &[a_expr, b_expr],
+    )
+    .upcast()
+}
+
+// Returns an expression that is the inverted result of the given boolean expressions.
+#[allow(dead_code)]
+pub fn not_expr(a_expr: gtk::Expression) -> gtk::Expression {
+    gtk::ClosureExpression::new(
+        move |args| {
+            let a: bool = args[1].get().unwrap();
+            !a
+        },
+        &[a_expr],
+    )
+    .upcast()
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]