Skip to content

Changed to use a simpler curve interpolate method - #597

Open
wmerrifield wants to merge 2 commits into
nicbarker:mainfrom
wmerrifield:curve_interpolation
Open

wmerrifield wants to merge 2 commits into
nicbarker:mainfrom
wmerrifield:curve_interpolation

Conversation

@wmerrifield

@wmerrifield wmerrifield commented Apr 7, 2026 •

Copy link
Copy Markdown

This is a PR to add a simpler simpler .curve() function, rather than having to do a lot of boilerplate with implementing a full .handler() functions when doing transitions. i.e. you can just have functions like this:

float smoothstep(float x) {
    return x * x * (3.0f - 2.0f * x);
}

float easeInOutElastic(float x) {
    const float c5 = (2.0f * (float)M_PI) / 4.5f;

    if (x == 0.0f) return 0.0f;
    if (x == 1.0f) return 1.0f;

    if (x < 0.5f) {
        return -(powf(2.0f, 20.0f * x - 10.0f) *
                 sinf((20.0f * x - 11.125f) * c5)) * 0.5f;
    } else {
        return (powf(2.0f, -20.0f * x + 10.0f) *
                sinf((20.0f * x - 11.125f) * c5)) * 0.5f + 1.0f;
    }
}

in your local app code, which simply convert a 0-1 value of "fraction through the animation" into an output value which varies from 0 (i.e. the start value) to 1 (i.e. the end value), and the intermediate values are simply lerped using what amounts to the existing code.

The changed API is an additional .curve property on the Clay_TransitionElementConfig structure. This is in addition to the old .handler callback, but either one or the other must be specified for the animation to function.

so you can still do

.transition = {
        .handler = Clay_EaseOut, // or my_own_Handler_Function
        .duration = 0.3f,
        .properties = CLAY_TRANSITION_PROPERTY_POSITION,

But if you want a "smoothstep" animation (or springy animation), instead of having to copy a ~50 line function each time, you can just write a one-line function (as shown above), and insert that.

.transition = {
        .curve = smoothstep,
        .duration = 0.3f,
        .properties = CLAY_TRANSITION_PROPERTY_POSITION,

@wmerrifield
wmerrifield force-pushed the curve_interpolation branch from 1ef9d94 to 5cb5eac Compare April 7, 2026 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant