Skip to content

Commit

Permalink
Add min and max simplexpr functions (#1123)
Browse files Browse the repository at this point in the history
* Add 'min' and 'max' function calls to simplexpr

* Add changelog entry for 'min' and 'max' simplexpr functions
  • Loading branch information
ovalkonia authored Jul 5, 2024
1 parent d1fde92 commit 4d55e9a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
16 changes: 16 additions & 0 deletions crates/simplexpr/src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;
Expand Down

0 comments on commit 4d55e9a

Please sign in to comment.