@@ -22,6 +22,7 @@ use i_slint_core as corelib;
2222use i_slint_core:: input:: FocusReason ;
2323use i_slint_core:: items:: ItemRc ;
2424use smol_str:: SmolStr ;
25+ use std:: cell:: RefCell ;
2526use std:: collections:: HashMap ;
2627use std:: rc:: Rc ;
2728
@@ -408,7 +409,17 @@ pub fn eval_expression(expression: &Expression, local_context: &mut EvalLocalCon
408409 }
409410 Expression :: EmptyComponentFactory => Value :: ComponentFactory ( Default :: default ( ) ) ,
410411 Expression :: DebugHook { expression, .. } => eval_expression ( expression, local_context) ,
411- Expression :: Predicate { arg_name, expression } => todo ! ( ) ,
412+ Expression :: Predicate { arg_name, expression } => {
413+ let arg_name = arg_name. clone ( ) ;
414+ let expression = expression. clone ( ) ;
415+ let predicate: Rc < RefCell < dyn Fn ( & mut EvalLocalContext < ' _ , ' _ > , & Value ) -> Value + ' static > > =
416+ Rc :: new ( RefCell :: new ( move |local_context : & mut EvalLocalContext < ' _ , ' _ > , value : & Value | {
417+ local_context. local_variables . insert ( arg_name. clone ( ) , value. clone ( ) ) ;
418+ eval_expression ( & expression, local_context)
419+ } ) ) ;
420+
421+ Value :: Predicate ( predicate)
422+ } ,
412423 }
413424}
414425
@@ -1369,8 +1380,37 @@ fn call_builtin_function(
13691380 panic ! ( "internal error: argument to RestartTimer must be an element" )
13701381 }
13711382 }
1372- BuiltinFunction :: ArrayAny => todo ! ( ) ,
1373- BuiltinFunction :: ArrayAll => todo ! ( ) ,
1383+ BuiltinFunction :: ArrayAny => {
1384+ let model: ModelRc < Value > =
1385+ eval_expression ( & arguments[ 0 ] , local_context) . try_into ( ) . unwrap ( ) ;
1386+ let predicate: Rc < RefCell < dyn FnMut ( & mut EvalLocalContext , & Value ) -> Value > > =
1387+ eval_expression ( & arguments[ 1 ] , local_context) . try_into ( ) . unwrap ( ) ;
1388+ let mut predicate = predicate. borrow_mut ( ) ;
1389+
1390+ for x in model. iter ( ) {
1391+ if predicate ( local_context, & x) . try_into ( ) . unwrap ( ) {
1392+ return Value :: Bool ( true ) ;
1393+ }
1394+ }
1395+
1396+ Value :: Bool ( false )
1397+ }
1398+ BuiltinFunction :: ArrayAll => {
1399+ let model: ModelRc < Value > =
1400+ eval_expression ( & arguments[ 0 ] , local_context) . try_into ( ) . unwrap ( ) ;
1401+ let predicate: Rc < RefCell < dyn FnMut ( & mut EvalLocalContext , & Value ) -> Value > > =
1402+ eval_expression ( & arguments[ 1 ] , local_context) . try_into ( ) . unwrap ( ) ;
1403+ let mut predicate = predicate. borrow_mut ( ) ;
1404+
1405+ for x in model. iter ( ) {
1406+ let result: bool = predicate ( local_context, & x) . try_into ( ) . unwrap ( ) ;
1407+ if !result {
1408+ return Value :: Bool ( false ) ;
1409+ }
1410+ }
1411+
1412+ Value :: Bool ( true )
1413+ }
13741414 }
13751415}
13761416
0 commit comments