# Easing and transitions

Make a change feel deliberate without changing how long it takes. Easing maps a normalized time fraction to a normalized progress value; interpolation turns that progress into a position, size, or opacity.

In [Frames and time](../frames/index.md), the dot uses cubic ease-in-out. The helper below uses cubic ease-out: it starts quickly and settles gently.

## Keep timing separate from presentation

```csharp
using System;
using Xui.Core.Animation;
using NFloat = System.Runtime.InteropServices.NFloat;

public struct TimedTransition
{
    private NFloat from;
    private NFloat target;
    private TimeSpan started;
    private TimeSpan duration;
    public NFloat Value { get; private set; }
    public bool Running { get; private set; }

    public void Start(NFloat current, NFloat destination, TimeSpan now, TimeSpan length)
    {
        from = current;
        target = destination;
        started = now;
        duration = length;
        Running = length > TimeSpan.Zero && current != destination;
        Value = Running ? current : destination;
    }

    public NFloat Advance(TimeSpan now)
    {
        if (!Running)
            return Value;
        NFloat t = NFloat.Clamp((NFloat)((now - started).TotalSeconds / duration.TotalSeconds), 0, 1);
        Value = from + (target - from) * Easing.EaseOutCubic(t);
        if (t == 1)
        {
            Value = target;
            Running = false;
        }

        return Value;
    }
}
```

Keep this struct in a field. Call `Start` with the current displayed value, destination, current frame time, and duration. Call `Advance` from `AnimateCore`, apply the returned value to your view, invalidate the relevant work, and request another frame while `Running` is true.

For example, begin at zero, target one, and pass a duration of 300 milliseconds. At the end, `Value` is exactly one and `Running` becomes false. A zero or negative duration applies the destination immediately rather than dividing by zero.

Use the same clock for `Start` and `Advance`. If an input callback has no frame timestamp, record the requested destination there and initialize the transition in the next animation callback, as the live dot example does.

## Choose the curve for the task

A linear fraction changes at a constant rate. Ease-out gives quick feedback and a soft landing. Ease-in-out provides a gentle start and finish. `Xui.Core.Animation.Easing` also includes sine, polynomial, back, elastic, and bounce functions.

Back and elastic curves can overshoot the interval from zero to one. That can suit a decorative position, but it is usually wrong for an opacity, a progress amount, or a size that must stay nonnegative. Clamp the final domain value when required or choose a curve without overshoot.

Do not use a spring-shaped easing curve as evidence that you have a physical spring model. A normalized easing function depends on time fraction; a motion curve that carries position and velocity answers a different problem.

## Retarget from the current value

To interrupt a running transition, advance it to the current time, then pass that value as the next `current` argument. Retargeting from the original start causes a discontinuity. Retargeting from the displayed value preserves position, although the ease-out helper intentionally restarts its velocity profile.

The helper does not schedule frames, access a dispatcher, or mutate controls. The view owns those decisions. Keeping this math independent makes it easy to test at the start, halfway through, and after the endpoint.

Try a destination smaller than the start, then a second retarget before the first finishes. The same interpolation works in both directions. Use [Animate layout and drawing](../layout-drawing/index.md) to choose which visual property should receive the value.
