Skip to content

ui::ExpressionAnimation

Header: winui/ui/Animation.hpp.

An animation driven by a C++ callable. It is evaluated every frame and wherever the element's transform is read, so it is never a frame behind the elements it reads. A float() callable drives a scalar property, or every component of a Vector3 one. A Vector3() callable drives a Vector3 property, or a scalar one with its .x. It runs until stopped.

Example:

// Keep `badge` at the inverse of `card`'s animated scale, so it never looks stretched.
auto                  stack = std::make_unique<ui::StackControl>(ui::Orientation::Vertical);
ui::BorderControl*    card  = stack->add(std::make_unique<ui::BorderControl>());
ui::RectangleControl* badge = stack->add(std::make_unique<ui::RectangleControl>());
badge->start_animation(ui::AnimatedProperty::Scale,
                       ui::ExpressionAnimation{.expression = ui::Callback<ui::Vector3()>{[card] {
                           const ui::Vector3 s = card->current_scale();
                           return ui::Vector3{1.0f / s.x, 1.0f / s.y, 1.0f};
                       }}});
// ... later
badge->stop_animation(ui::AnimatedProperty::Scale);

Field Type Default
expression std::variant<Callback<float()>, Callback<Vector3()>> The expression, evaluated again every frame. Captured elements must outlive the animation.