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

This commit is contained in:
Cole Lawrence 2023-04-28 14:16:30 -03:00 committed by Olivier Goffart
parent c977c7bc73
commit 95e00c5621
3 changed files with 25 additions and 4 deletions

View file

@ -7,6 +7,10 @@ All notable changes to this project are documented in this file.
* Fixed missing items compilation error in the generated code related to public functions (#2655).
### Slint Language
- Support negative numbers in `cubic-bezier(...)` function.
### Rust
- Added `slint::Image::load_from_svg_data(buffer: &[u8])` to load SVGs from memory.

View file

@ -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() {
@ -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.
}
};

View file

@ -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
}
}