Using Animations

A common PixelUI animation changes an int32_t from A to B over a duration. Easing uses fixed-point calculations, and animation objects live directly in the fixed-capacity AnimationManager.

Animation demo

In this demo, motion parameters are ordinary int32_t members read by the App during each draw.

The older AnimationManager diagram still captures the basic idea: animate() creates entries updated by one manager. The current implementation uses fixed-capacity inline CallbackAnimation objects, so do not interpret the long slots in that diagram as a heap-allocated pointer container.

One value

1
2
3
4
5
6
int32_t panelX = -64;

if (!ui.animate(panelX, 0, 400, EasingType::EASE_OUT_CUBIC)) {
// The animation container is full. Set the final value or report an error.
panelX = 0;
}

animate() returns bool. When all PIXELUI_MAX_ANIMATION_COUNT slots are occupied, it returns false, and the original variable does not automatically reach its final value.

Two values

1
2
3
4
if (!ui.animate(x, y, 32, 20, 500, EasingType::EASE_IN_OUT_QUAD)) {
x = 32;
y = 20;
}

This overload requires two free slots at once. Otherwise it fails without starting only X or only Y.

Custom callback

1
2
3
4
5
6
7
8
ui.animateCallback(
0,
100,
600,
EasingType::EASE_OUT_CUBIC,
[this](int32_t value) {
brightness_ = value;
});

The callback is stored in etl::inplace_function<..., CALLBACK_STORAGE_SIZE>. An oversized capture fails at compile time. When capturing this or a reference, the target must live until the Animation ends or is cleared. See Resource limits for capacity configuration.

Easing

LINEAR, EASE_IN_QUAD, EASE_OUT_QUAD, EASE_IN_OUT_QUAD, EASE_IN_CUBIC, EASE_OUT_CUBIC, EASE_IN_OUT_CUBIC, and EASE_OUT_BOUNCE can be passed directly to animate().

Refresh and markDirty()

AnimationManager updates values and marks the UI dirty when deadlines are reached, so continuous drawing is not required. Call ui.markDirty() after ordinary application state changes. See Event-driven rendering for scheduling rules.

Protection and cleanup

  • PROTECTION::PROTECTED only prevents clearUnprotectedAnimations() from removing an Animation.
  • clearAllAnimations() removes every Animation, including protected ones.
  • ViewManager clears Animations during App transitions and exit. Protection does not allow an Animation to outlive a destroyed App.
  • clearAnimationProtection() only removes protection flags; it does not delete Animations immediately.

Animations hold references to their target variables. Be especially careful when a target is not an App member.

最新文章
网站信息
文章数目 :
1
本站访客数 :
本站总浏览量 :
最后更新时间 :