Skip to content

Commit e0ae0af

Browse files
authored
Add an Easing namespace (#9179)
The definition of an Easing namespace allows to name an easing curve outside an expression of type easing like, for instance, a struct field. Closes #3943. ChangeLog: Added an `Easing` namespace to reference easing curve outside of `easing` properties.
1 parent f9ba878 commit e0ae0af

File tree

4 files changed

+61
-2
lines changed

4 files changed

+61
-2
lines changed

docs/astro/src/content/docs/reference/primitive-types.mdx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,9 @@ See also the <Link type="Image" label="Image element"/>.
229229
## Animation
230230
### easing
231231
<SlintProperty propName="easing" typeName="easing" defaultValue='linear'>
232-
Property animation allow specifying an easing curve.
233-
`easing`: can be any of the following. See [`easings.net`](https://easings.net/) for a visual reference:
232+
The `easing` type allows defining an easing curve for animations.
233+
234+
To specify an easing curve, use the values from the `Easing` namespace. For example you can use `Easing.ease-out` or `Easing.ease-in-quad`. The namespace consists of the following names (see [`easings.net`](https://easings.net/) for a visual reference):
234235

235236
- `linear`
236237
- `ease-in-quad`
@@ -265,6 +266,26 @@ Property animation allow specifying an easing curve.
265266
- `ease-out-bounce`
266267
- `ease-in-out-bounce`
267268
- `cubic-bezier(a, b, c, d)` as in CSS
269+
270+
Additionally, in expressions of type `easing`, those names are available directly.
271+
272+
```slint
273+
struct AnimationData {
274+
curve: easing,
275+
}
276+
277+
component Custom inherits Rectangle {
278+
property<AnimationData> animation: {
279+
// Using the Easing namespace.
280+
curve: Easing.ease-in-circ,
281+
};
282+
283+
animate x {
284+
// In easing expressions the names are available via global scope.
285+
easing: ease-out-bounce;
286+
}
287+
}
288+
```
268289
</SlintProperty>
269290

270291

internal/compiler/generator/rust.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ pub fn rust_primitive_type(ty: &Type) -> Option<proc_macro2::TokenStream> {
8383
Type::Float32 => Some(quote!(f32)),
8484
Type::String => Some(quote!(sp::SharedString)),
8585
Type::Color => Some(quote!(sp::Color)),
86+
Type::Easing => Some(quote!(sp::EasingCurve)),
8687
Type::ComponentFactory => Some(quote!(slint::ComponentFactory)),
8788
Type::Duration => Some(quote!(i64)),
8889
Type::Angle => Some(quote!(f32)),

internal/compiler/lookup.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ pub enum LookupResultCallable {
118118
#[derive(Debug, derive_more::Display)]
119119
pub enum BuiltinNamespace {
120120
Colors,
121+
Easing,
121122
Math,
122123
Key,
123124
SlintInternal,
@@ -196,6 +197,9 @@ impl LookupObject for LookupResult {
196197
LookupResult::Namespace(BuiltinNamespace::Colors) => {
197198
(ColorSpecific, ColorFunctions).for_each_entry(ctx, f)
198199
}
200+
LookupResult::Namespace(BuiltinNamespace::Easing) => {
201+
EasingSpecific.for_each_entry(ctx, f)
202+
}
199203
LookupResult::Namespace(BuiltinNamespace::Math) => MathFunctions.for_each_entry(ctx, f),
200204
LookupResult::Namespace(BuiltinNamespace::Key) => KeysLookup.for_each_entry(ctx, f),
201205
LookupResult::Namespace(BuiltinNamespace::SlintInternal) => {
@@ -212,6 +216,7 @@ impl LookupObject for LookupResult {
212216
LookupResult::Namespace(BuiltinNamespace::Colors) => {
213217
(ColorSpecific, ColorFunctions).lookup(ctx, name)
214218
}
219+
LookupResult::Namespace(BuiltinNamespace::Easing) => EasingSpecific.lookup(ctx, name),
215220
LookupResult::Namespace(BuiltinNamespace::Math) => MathFunctions.lookup(ctx, name),
216221
LookupResult::Namespace(BuiltinNamespace::Key) => KeysLookup.lookup(ctx, name),
217222
LookupResult::Namespace(BuiltinNamespace::SlintInternal) => {
@@ -842,6 +847,7 @@ impl LookupObject for BuiltinNamespaceLookup {
842847
) -> Option<R> {
843848
let mut f = |s, res| f(&SmolStr::new_static(s), res);
844849
None.or_else(|| f("Colors", LookupResult::Namespace(BuiltinNamespace::Colors)))
850+
.or_else(|| f("Easing", LookupResult::Namespace(BuiltinNamespace::Easing)))
845851
.or_else(|| f("Math", LookupResult::Namespace(BuiltinNamespace::Math)))
846852
.or_else(|| f("Key", LookupResult::Namespace(BuiltinNamespace::Key)))
847853
.or_else(|| {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright © SixtyFPS GmbH <[email protected]>
2+
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
3+
4+
struct Animation {
5+
easing: easing,
6+
}
7+
8+
export component Test inherits Rectangle {
9+
property <Animation> animation1: {
10+
easing: Easing.linear,
11+
};
12+
13+
property <Animation> animation2: {
14+
easing: Easing.some-curve,
15+
// ^error{'some-curve' is not a member of the namespace Easing}
16+
};
17+
18+
property <Animation> animation3: {
19+
easing: Easing,
20+
// ^error{Cannot take reference to a namespace}
21+
};
22+
23+
property <Animation> animation4: {
24+
easing: Easing.cubic-bezier(0.05, 07, 0.1, 1.0)
25+
};
26+
27+
property <Animation> animation5: {
28+
easing: Easing.cubic-bezier(0.05, 07)
29+
// ^error{Not enough arguments}
30+
};
31+
}

0 commit comments

Comments
 (0)