diff --git a/CHANGELOG.md b/CHANGELOG.md index c0227ba..0f5c1c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,11 +28,12 @@ NewViewFilter function -> NewFilterProperty Animation interface -> AnimationProperty AnimationTag constant -> Animation + NewAnimation function -> NewAnimationProperty * Added functions: NewBounds, NewEllipticRadius, NewRadii, NewLinearGradient, NewCircleRadialGradient, NewEllipseRadialGradient, GetPushTransform, GetPushDuration, GetPushTiming, IsMoveToFrontAnimation, GetBackground, GetMask, GetBackgroundClip,GetBackgroundOrigin, GetMaskClip, GetMaskOrigin, NewColumnSeparator, -NewClipShapeProperty. +NewClipShapeProperty, NewTransitionAnimation, NewAnimation. * Added SetConicGradientFillStyle and SetConicGradientStrokeStyle methods to Canvas interface. diff --git a/README-ru.md b/README-ru.md index 2beca26..ad9b748 100644 --- a/README-ru.md +++ b/README-ru.md @@ -5043,7 +5043,7 @@ onNo или onCancel (если она не nil). Для задания параметров анимации используется интерфейс AnimationProperty. Он расширяет интерфейс Properties. Интерфейс создается с помощью функции: - func NewAnimation(params Params) AnimationProperty + func NewAnimationProperty(params Params) AnimationProperty Часть свойств интерфейса AnimationProperty используется в обоих типах анимации, остальные используются только в сценариях анимации. @@ -5082,13 +5082,13 @@ onNo или onCancel (если она не nil). Например - animation := rui.NewAnimation(rui.Params{ + animation := rui.NewAnimationProperty(rui.Params{ rui.TimingFunction: rui.StepsTiming(10), }) эквивалентно - animation := rui.NewAnimation(rui.Params{ + animation := rui.NewAnimationProperty(rui.Params{ rui.TimingFunction: "steps(10)", }) @@ -5117,7 +5117,7 @@ x1 и x2 должны быть в диапазоне [0, 1]. Вы можете Она присваивает свойству новое значение, при этом изменение происходит с использованием заданной анимации. Например, - view.SetAnimated(rui.Width, rui.Px(400), rui.NewAnimation(rui.Params{ + view.SetAnimated(rui.Width, rui.Px(400), rui.NewAnimationProperty(rui.Params{ rui.Duration: 0.75, rui.TimingFunction: rui.EaseOutTiming, })) @@ -5132,11 +5132,11 @@ x1 и x2 должны быть в диапазоне [0, 1]. Вы можете Например, view.Set(rui.Transition, rui.Params{ - rui.Height: rui.NewAnimation(rui.Params{ + rui.Height: rui.NewAnimationProperty(rui.Params{ rui.Duration: 0.75, rui.TimingFunction: rui.EaseOutTiming, }, - rui.BackgroundColor: rui.NewAnimation(rui.Params{ + rui.BackgroundColor: rui.NewAnimationProperty(rui.Params{ rui.Duration: 1.5, rui.Delay: 0.5, rui.TimingFunction: rui.Linear, @@ -5273,7 +5273,7 @@ KeyFrames - промежуточные значения свойства (клю 90: rui.Px(220), } } - animation := rui.NewAnimation(rui.Params{ + animation := rui.NewAnimationProperty(rui.Params{ rui.PropertyTag: []rui.AnimatedProperty{prop}, rui.Duration: 2, rui.TimingFunction: LinearTiming, diff --git a/README.md b/README.md index c63510c..fb4c579 100644 --- a/README.md +++ b/README.md @@ -5014,7 +5014,7 @@ The library supports two types of animation: The AnimationProperty interface is used to set animation parameters. It extends the Properties interface. The interface is created using the function: - func NewAnimation(params Params) AnimationProperty + func NewAnimationProperty(params Params) AnimationProperty Some of the properties of the AnimationProperty interface are used in both types of animation, the rest are used only in animation scripts. @@ -5053,13 +5053,13 @@ You can specify this function either as text or using the function: For example - animation := rui.NewAnimation(rui.Params{ + animation := rui.NewAnimationProperty(rui.Params{ rui.TimingFunction: rui.StepsTiming(10), }) equivalent to - animation := rui.NewAnimation(rui.Params{ + animation := rui.NewAnimationProperty(rui.Params{ rui.TimingFunction: "steps(10)", }) @@ -5087,7 +5087,7 @@ This function has the following description: It assigns a new value to the property, and the change occurs using the specified animation. For example, - view.SetAnimated(rui.Width, rui.Px(400), rui.NewAnimation(rui.Params{ + view.SetAnimated(rui.Width, rui.Px(400), rui.NewAnimationProperty(rui.Params{ rui.Duration: 0.75, rui.TimingFunction: rui.EaseOutTiming, })) @@ -5103,11 +5103,11 @@ and the value should be the AnimationProperty interface. For example, view.Set(rui.Transition, rui.Params{ - rui.Height: rui.NewAnimation(rui.Params{ + rui.Height: rui.NewAnimationProperty(rui.Params{ rui.Duration: 0.75, rui.TimingFunction: rui.EaseOutTiming, }, - rui.BackgroundColor: rui.NewAnimation(rui.Params{ + rui.BackgroundColor: rui.NewAnimationProperty(rui.Params{ rui.Duration: 1.5, rui.Delay: 0.5, rui.TimingFunction: rui.Linear, @@ -5246,7 +5246,7 @@ Example, 90: rui.Px(220), } } - animation := rui.NewAnimation(rui.Params{ + animation := rui.NewAnimationProperty(rui.Params{ rui.PropertyTag: []rui.AnimatedProperty{prop}, rui.Duration: 2, rui.TimingFunction: LinearTiming, diff --git a/animation.go b/animation.go index f2e3034..41d8423 100644 --- a/animation.go +++ b/animation.go @@ -256,8 +256,19 @@ func parseAnimation(obj DataObject) AnimationProperty { return animation } -// NewAnimation creates a new animation object and return its interface -func NewAnimation(params Params) AnimationProperty { +// NewAnimationProperty creates a new animation object and return its interface +// +// The following properties can be used: +// - "id" (ID) - specifies the animation identifier. Used only for animation script. +// - "duration" (Duration) - specifies the length of time in seconds that an animation takes to complete one cycle; +// - "delay" (Delay) - specifies the amount of time in seconds to wait from applying the animation to an element before beginning to perform +// the animation. The animation can start later, immediately from its beginning or immediately and partway through the animation; +// - "timing-function" (TimingFunction) - specifies how an animation progresses through the duration of each cycle; +// - "iteration-count" (IterationCount) - specifies the number of times an animation sequence should be played before stopping. Used only for animation script; +// - "animation-direction" (AnimationDirection) - specifies whether an animation should play forward, backward, +// or alternate back and forth between playing the sequence forward and backward. Used only for animation script; +// - "property" (PropertyTag) - describes a scenario for changing a View's property. Used only for animation script. +func NewAnimationProperty(params Params) AnimationProperty { animation := new(animationData) animation.init() @@ -267,6 +278,88 @@ func NewAnimation(params Params) AnimationProperty { return animation } +// NewTransitionAnimation creates animation data for the transition. +// - timingFunc - specifies how an animation progresses through the duration of each cycle. If it is "" then "easy" function is used; +// - duration - specifies the length of time in seconds that an animation takes to complete one cycle. Must be > 0; +// - delay - specifies the amount of time in seconds to wait from applying the animation to an element before beginning to perform +// the animation. The animation can start later, immediately from its beginning or immediately and partway through the animation. +func NewTransitionAnimation(timingFunc string, duration float64, delay float64) AnimationProperty { + animation := new(animationData) + animation.init() + + if duration <= 0 { + ErrorLog("Animation duration must be greater than 0") + return nil + } + + if !animation.Set(Duration, duration) { + return nil + } + + if timingFunc != "" { + if !animation.Set(TimingFunction, timingFunc) { + return nil + } + } + + if delay != 0 { + animation.Set(Delay, delay) + } + + return animation +} + +// NewTransitionAnimation creates the animation scenario. +// - id - specifies the animation identifier. +// - timingFunc - specifies how an animation progresses through the duration of each cycle. If it is "" then "easy" function is used; +// - duration - specifies the length of time in seconds that an animation takes to complete one cycle. Must be > 0; +// - delay - specifies the amount of time in seconds to wait from applying the animation to an element before beginning to perform +// the animation. The animation can start later, immediately from its beginning or immediately and partway through the animation. +// - direction - specifies whether an animation should play forward, backward, +// or alternate back and forth between playing the sequence forward and backward. Only the following values ​​can be used: +// 0 (NormalAnimation), 1 (ReverseAnimation), 2 (AlternateAnimation), and 3 (AlternateReverseAnimation); +// - iterationCount - specifies the number of times an animation sequence should be played before stopping; +// - property - describes a scenario for changing a View's property. +func NewAnimation(id string, timingFunc string, duration float64, delay float64, direction int, iterationCount int, property ...AnimatedProperty) AnimationProperty { + animation := new(animationData) + animation.init() + + if duration <= 0 { + ErrorLog("Animation duration must be greater than 0") + return nil + } + + if !animation.Set(Duration, duration) { + return nil + } + + if id != "" { + animation.Set(ID, id) + } + + if timingFunc != "" { + animation.Set(TimingFunction, timingFunc) + } + + if delay != 0 { + animation.Set(Delay, delay) + } + + if direction > 0 { + animation.Set(AnimationDirection, direction) + } + + if iterationCount > 0 { + animation.Set(IterationCount, iterationCount) + } + + if len(property) > 0 { + animation.Set(PropertyTag, property) + } + + return animation +} + func (animation *animationData) init() { animation.dataProperty.init() animation.normalize = normalizeAnimation diff --git a/popup.go b/popup.go index a008305..00c0230 100644 --- a/popup.go +++ b/popup.go @@ -797,7 +797,7 @@ func (popup *popupData) init(view View, popupParams Params) { popup.layerView = NewGridLayout(session, layerParams) if popup.showOpacity != 1 || popup.showTransform != nil { - animation := NewAnimation(Params{ + animation := NewAnimationProperty(Params{ Duration: popup.showDuration, TimingFunction: popup.showTiming, }) diff --git a/propertyNames.go b/propertyNames.go index 3fd422c..b2259d9 100644 --- a/propertyNames.go +++ b/propertyNames.go @@ -6,14 +6,14 @@ type PropertyName string const ( // ID is the constant for "id" property tag. // - // # Used by View, Animation. + // # Used by View, AnimationProperty. // // Usage in View: // Optional textual identifier for the view. Used to reference view from source code if needed. // // Supported types: string. // - // # Usage in Animation: + // # Usage in AnimationProperty: // // Specifies the animation identifier. Used only for animation script. //