Attribute Macro zng::widget::easing

source ·
#[easing]
Expand description

Expands a property assign to include an easing animation.

The attribute generates a property build action that applies Var::easing to the final variable inputs of the property.

§Arguments

The attribute takes one required argument and one optional that matches the Var::easing parameters. The required first arg is the duration, the second arg is an easing function, if not present the easing::linear is used.

Some items are auto-imported in each argument scope, TimeUnits for the first arg and the easing functions for the second. This enables syntax like #[easing(300.ms(), expo)].

§Unset

An alternative argument unset can be used instead to remove animations set by the inherited context or styles.

§When

The attribute can also be set in when assigns, in this case the easing will be applied when the condition is active, so only the transition to the true value is animated using the conditional easing.

Note that you can’t unset easing in when conditions, but you can set it to 0.ms(), if all easing set for a property are 0 no easing variable is generated, in contexts that actually have animation the `when`` value will be set immediately, by a zero sized animation.

§Examples

The example demonstrates setting and removing easing animations.

Foo! {
    #[easing(300.ms(), expo)] // set/override the easing.
    background_color = colors::RED;

    #[easing(unset)] // remove easing set by style or widget defaults.
    margin = 0;
}

§Limitations

The attribute only works in properties that only have variable inputs of types that are Transitionable, if the attribute is set in a property that does not match this a cryptic type error occurs, with a mention of easing_property_input_Transitionable.

Expands a property assign to include a build action that applies an easing transition to the variable inputs.

§Full Documentation

Read the documentation in the zng::widget::easing.