Animation

The library supports two types of animation:

  • Animated property value changes (hereinafter "transition animation")
  • Script animated change of one or more properties (hereinafter simply "animation script")

Animation interface

The Animation interface is used to set animation parameters. It extends the Properties interface.The interface is created using the function:

func NewAnimation(params Params) Animation

Some of the properties of the Animation interface are used in both types of animation, the rest are used onlyin animation scripts.

Common properties are

Property Constant Type Default Description
"duration" Duration float64 1 Animation duration in seconds
"delay" Delay float64 0 Delay before animation in seconds
"timing-function" TimingFunction string "ease" The function of changing the animation speed

Properties used only in animation scripts will be described below.

"timing-function" property

The "timing-function" property describes in text the function of changing the speed of the animation.Functions can be divided into 2 types: simple functions and functions with parameters.

Simple functions

Function Constant Description
"ease" EaseTiming the speed increases towards the middle and slows down at the end.
"ease-in" EaseInTiming the speed is slow at first, but increases in the end.
"ease-out" EaseOutTiming speed is fast at first, but decreases rapidly. Most of the slow
"ease-in-out" EaseInOutTiming the speed is fast at first, but quickly decreases, and at the end it increases again.
"linear" LinearTiming constant speed

And there are two functions with parameters:

  • "steps(N)" - discrete function, where N is an integer specifying the number of steps.You can specify this function either as text or using the function:
func StepsTiming(stepCount int) string

For example

animation := rui.NewAnimation(rui.Params{
	rui.TimingFunction: rui.StepsTiming(10),
})

equivalent to

animation := rui.NewAnimation(rui.Params{
	rui.TimingFunction: "steps(10)",
})

  • "cubic-bezier(x1, y1, x2, y2)" - time function of a cubic Bezier curve. x1, y1, x2, y2 are of type float64.x1 and x2 must be in the range [0...1]. You can specify this function either as text or using the function:
func CubicBezierTiming(x1, y1, x2, y2 float64) string