Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add min and max simplexpr functions #1123

Merged
merged 2 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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