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

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

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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.
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
}
}
Comment on lines +4 to +10
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just for the interpreter, so there might be a better place to put this.