You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Slint animations use a **mocked time system** rather than real-time clocks. This provides:
13
+
- Deterministic animation behavior for testing
14
+
- Frame-rate independence
15
+
- Consistent behavior across platforms
16
+
17
+
The animation driver (`internal/core/animations.rs`) manages a global instant that advances each frame:
18
+
19
+
```
20
+
AnimationDriver
21
+
├── global_instant: Property<Instant> // Current animation time
22
+
├── active_animations: bool // Whether animations are running
23
+
└── update_animations(new_tick) // Called per frame by the backend
24
+
```
25
+
26
+
**Key components:**
27
+
-`Instant` - Milliseconds since animation driver started
28
+
-`current_tick()` - Get current animation time (registers as dependency)
29
+
-`animation_tick()` - Same as above, but signals a frame is needed
30
+
-`update_timers_and_animations()` - Called by the platform each frame
31
+
32
+
## Easing Curve Implementation
33
+
34
+
Easing curves are defined in the `EasingCurve` enum in `internal/core/items.rs`. The interpolation logic is in `internal/core/animations.rs`.
35
+
36
+
For `cubic-bezier(a, b, c, d)`, Slint uses a binary search algorithm to find the t parameter for a given x value, then evaluates the y component of the bezier curve.
Copy file name to clipboardExpand all lines: docs/astro/src/content/docs/guide/development/debugging_techniques.mdx
+46-2Lines changed: 46 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,11 +11,55 @@ On this page we share different techniques and tools we've built into Slint that
11
11
12
12
Use the <Linktype="DebugFn"label="debug()" /> function to print the values of properties to stderr.
13
13
14
-
## Slow Motion Animations
14
+
## Debugging Animations
15
15
16
16
Animations in the user interface need to be carefully designed to have the correct duration and changes in element positioning or size need to follow an easing curve.
17
17
18
-
To inspect the animations in your application, set the `SLINT_SLOW_ANIMATIONS` environment variable before running the program. This variable accepts an unsigned integer value that is the factor by which to globally slow down the steps of all animations, automatically. This means that you don't have to make any manual changes to the `.slint` markup and recompile. For example,`SLINT_SLOW_ANIMATIONS=4` slows down animations by a factor of four.
18
+
### Slow Motion Animations
19
+
20
+
To inspect the animations in your application, set the `SLINT_SLOW_ANIMATIONS` environment variable before running the program. This variable accepts an unsigned integer value that is the factor by which to globally slow down the steps of all animations, automatically. This means that you don't have to make any manual changes to the `.slint` markup and recompile.
21
+
22
+
```sh
23
+
# Slow animations by a factor of 2
24
+
SLINT_SLOW_ANIMATIONS=2 cargo run
25
+
26
+
# Slow by a factor of 10 for detailed inspection
27
+
SLINT_SLOW_ANIMATIONS=10 cargo run
28
+
```
29
+
30
+
This is particularly useful for:
31
+
- Verifying easing curves look correct
32
+
- Checking that animation start and end states are correct
33
+
- Debugging timing issues between multiple animations
34
+
- Inspecting complex state transitions
35
+
36
+
### Checking for Active Animations
37
+
38
+
In Rust, you can programmatically check if animations are currently running:
39
+
40
+
```rust
41
+
ifwindow.has_active_animations() {
42
+
// Animations are in progress
43
+
}
44
+
```
45
+
46
+
This is useful when you need to synchronize application logic with animation completion.
47
+
48
+
### Mock Time in Tests
49
+
50
+
For automated testing, Slint provides a mock time system that allows precise control over animation timing. Instead of waiting for real time to pass, you can advance the animation clock directly:
51
+
52
+
```rust
53
+
useslint_testing::mock_elapsed_time;
54
+
55
+
// Advance animation time by 100ms
56
+
mock_elapsed_time(100);
57
+
58
+
// Advance to complete a 300ms animation
59
+
mock_elapsed_time(300);
60
+
```
61
+
62
+
This enables deterministic animation testing without slow, flaky time-based waits.
Copy file name to clipboardExpand all lines: docs/astro/src/content/docs/guide/language/coding/animation.mdx
+27Lines changed: 27 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -70,3 +70,30 @@ Can be any of the following. See [`easings.net`](https://easings.net/) for a vis
70
70
Use this to set or change the direction of the animation.
71
71
</SlintProperty>
72
72
73
+
## Performance Considerations
74
+
75
+
Each animated property re-evaluates its binding every frame, marks dependents dirty, and triggers re-rendering of affected items. For best performance, avoid animating properties that cause layout recalculations.
76
+
77
+
```slint
78
+
export component Example inherits Window {
79
+
preferred-width: 200px;
80
+
preferred-height: 100px;
81
+
82
+
Rectangle {
83
+
// Good: Animate position (no layout recalculation)
Properties like `x`, `y`, `opacity`, `rotation-angle`, and `background` are efficient to animate. Properties like `width`, `height`, `preferred-width`, and `preferred-height` trigger layout recalculations and should be animated sparingly.
0 commit comments