Skip to content

ui::KeyFrame

Header: winui/ui/Animation.hpp.

One key frame: a value at a time (milliseconds from the animation's start). Build one with the named factories, so kind and easing agree.

Example:

const std::vector<ui::KeyFrame> frames{
    ui::KeyFrame::linear(0ms, 0.0f),
    ui::KeyFrame::eased(300ms, 1.0f, ui::CubicEase{}),
    ui::KeyFrame::discrete(600ms, 0.5f),
    ui::KeyFrame::spline(900ms, 1.0f, ui::CubicBezier{0.8f, 0.0f, 0.2f, 1.0f}),
};
auto element = std::make_unique<ui::RectangleControl>();
element->start_animation(ui::AnimatedProperty::Opacity, ui::KeyFrameAnimation{.key_frames = frames});

time

Duration time {}

Key time from the animation's start.

value

float value = 0.0f

The value reached at time.

kind

KeyFrameKind kind = KeyFrameKind::Linear

How the segment ending at this frame interpolates.

easing

EasingFunction easing {}

The segment's curve for Spline (a CubicBezier) and Easing; ignored otherwise.

linear

static KeyFrame linear(Duration time, float value)

Interpolates linearly from the previous value.

discrete

static KeyFrame discrete(Duration time, float value)

Holds the previous value, then jumps to value at time.

spline

static KeyFrame spline(Duration time, float value, CubicBezier spline)

Interpolates along the cubic Bézier spline.

eased

static KeyFrame eased(Duration time, float value, EasingFunction easing)

Interpolates along easing.