Add min and max simplexpr functions (#1123)

* Add 'min' and 'max' function calls to simplexpr

* Add changelog entry for 'min' and 'max' simplexpr functions
This commit is contained in:
ovalkonia 2024-07-05 13:57:48 +03:00 committed by GitHub
parent d1fde927d2
commit 4d55e9ad63
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 0 deletions

View File

@ -11,6 +11,7 @@ All notable changes to eww will be listed here, starting at changes since versio
### Features
- Add `:truncate` property to labels, disabled by default (except in cases where truncation would be enabled in version `0.5.0` and before) (By: Rayzeq).
- Add support for `:hover` css selectors for tray items (By: zeapoz)
- Add `min` and `max` function calls to simplexpr (By: ovalkonia)
## [0.6.0] (21.04.2024)

View File

@ -328,6 +328,22 @@ fn call_expr_function(name: &str, args: Vec<DynVal>) -> Result<DynVal, EvalError
}
_ => Err(EvalError::WrongArgCount(name.to_string())),
},
"min" => match args.as_slice() {
[a, b] => {
let a = a.as_f64()?;
let b = b.as_f64()?;
Ok(DynVal::from(f64::min(a, b)))
}
_ => Err(EvalError::WrongArgCount(name.to_string())),
},
"max" => match args.as_slice() {
[a, b] => {
let a = a.as_f64()?;
let b = b.as_f64()?;
Ok(DynVal::from(f64::max(a, b)))
}
_ => Err(EvalError::WrongArgCount(name.to_string())),
},
"sin" => match args.as_slice() {
[num] => {
let num = num.as_f64()?;