Skip to content

Commit

Permalink
Support negative numbers in cubic-bezier(...) function
Browse files Browse the repository at this point in the history
  • Loading branch information
colelawrence committed Apr 28, 2023
1 parent 554ee02 commit 7319ea2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,10 @@ All notable changes to this project are documented in this file.

## Unreleased

### Slint Language

- Support negative numbers in `cubic-bezier(...)` function

### Rust

- Added `slint::Image::load_from_svg_data(buffer: &[u8])` to load SVGs from memory.
Expand Down
15 changes: 11 additions & 4 deletions internal/compiler/builtin_macros.rs
Expand Up @@ -28,6 +28,8 @@ pub fn lower_macro(
BuiltinMacroFunction::Debug => debug_macro(n, sub_expr.collect(), diag),
BuiltinMacroFunction::CubicBezier => {
let mut has_error = None;
let expected_argument_type_error =
"Arguments to cubic bezier curve must be number literal";
// FIXME: this is not pretty to be handling there.
// Maybe "cubic_bezier" should be a function that is lowered later
let mut a = || match sub_expr.next() {
Expand All @@ -36,11 +38,16 @@ pub fn lower_macro(
0.
}
Some((Expression::NumberLiteral(val, Unit::None), _)) => val as f32,
// handle negative numbers
Some((Expression::UnaryOp { sub, op: '-' }, n)) => match *sub {
Expression::NumberLiteral(val, Unit::None) => (-1.0 * val) as f32,
_ => {
has_error.get_or_insert((n, expected_argument_type_error));
0.
}
},
Some((_, n)) => {
has_error.get_or_insert((
n,
"Arguments to cubic bezier curve must be number literal",
));
has_error.get_or_insert((n, expected_argument_type_error));
0.
}
};
Expand Down
10 changes: 10 additions & 0 deletions tests/cases/types/cubic-bezier.slint
@@ -0,0 +1,10 @@
// Copyright © SixtyFPS GmbH <info@slint-ui.com>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial

// Test that cubic-bezier() can accept negative numbers

TestCase := Rectangle {
animate background {
easing: cubic-bezier(0.600, -0.280, 0.735, 0.045); // ease-in-back
}
}

0 comments on commit 7319ea2

Please sign in to comment.