mirror of https://github.com/anoshenko/rui.git
Added NewTransitionAnimation, NewAnimation
This commit is contained in:
parent
0c2bea9a75
commit
28881bac9a
|
@ -28,11 +28,12 @@
|
||||||
NewViewFilter function -> NewFilterProperty
|
NewViewFilter function -> NewFilterProperty
|
||||||
Animation interface -> AnimationProperty
|
Animation interface -> AnimationProperty
|
||||||
AnimationTag constant -> Animation
|
AnimationTag constant -> Animation
|
||||||
|
NewAnimation function -> NewAnimationProperty
|
||||||
|
|
||||||
* Added functions: NewBounds, NewEllipticRadius, NewRadii, NewLinearGradient, NewCircleRadialGradient,
|
* Added functions: NewBounds, NewEllipticRadius, NewRadii, NewLinearGradient, NewCircleRadialGradient,
|
||||||
NewEllipseRadialGradient, GetPushTransform, GetPushDuration, GetPushTiming, IsMoveToFrontAnimation,
|
NewEllipseRadialGradient, GetPushTransform, GetPushDuration, GetPushTiming, IsMoveToFrontAnimation,
|
||||||
GetBackground, GetMask, GetBackgroundClip,GetBackgroundOrigin, GetMaskClip, GetMaskOrigin, NewColumnSeparator,
|
GetBackground, GetMask, GetBackgroundClip,GetBackgroundOrigin, GetMaskClip, GetMaskOrigin, NewColumnSeparator,
|
||||||
NewClipShapeProperty.
|
NewClipShapeProperty, NewTransitionAnimation, NewAnimation.
|
||||||
|
|
||||||
* Added SetConicGradientFillStyle and SetConicGradientStrokeStyle methods to Canvas interface.
|
* Added SetConicGradientFillStyle and SetConicGradientStrokeStyle methods to Canvas interface.
|
||||||
|
|
||||||
|
|
14
README-ru.md
14
README-ru.md
|
@ -5043,7 +5043,7 @@ onNo или onCancel (если она не nil).
|
||||||
Для задания параметров анимации используется интерфейс AnimationProperty. Он расширяет интерфейс Properties.
|
Для задания параметров анимации используется интерфейс AnimationProperty. Он расширяет интерфейс Properties.
|
||||||
Интерфейс создается с помощью функции:
|
Интерфейс создается с помощью функции:
|
||||||
|
|
||||||
func NewAnimation(params Params) AnimationProperty
|
func NewAnimationProperty(params Params) AnimationProperty
|
||||||
|
|
||||||
Часть свойств интерфейса AnimationProperty используется в обоих типах анимации, остальные используются
|
Часть свойств интерфейса AnimationProperty используется в обоих типах анимации, остальные используются
|
||||||
только в сценариях анимации.
|
только в сценариях анимации.
|
||||||
|
@ -5082,13 +5082,13 @@ onNo или onCancel (если она не nil).
|
||||||
|
|
||||||
Например
|
Например
|
||||||
|
|
||||||
animation := rui.NewAnimation(rui.Params{
|
animation := rui.NewAnimationProperty(rui.Params{
|
||||||
rui.TimingFunction: rui.StepsTiming(10),
|
rui.TimingFunction: rui.StepsTiming(10),
|
||||||
})
|
})
|
||||||
|
|
||||||
эквивалентно
|
эквивалентно
|
||||||
|
|
||||||
animation := rui.NewAnimation(rui.Params{
|
animation := rui.NewAnimationProperty(rui.Params{
|
||||||
rui.TimingFunction: "steps(10)",
|
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.Duration: 0.75,
|
||||||
rui.TimingFunction: rui.EaseOutTiming,
|
rui.TimingFunction: rui.EaseOutTiming,
|
||||||
}))
|
}))
|
||||||
|
@ -5132,11 +5132,11 @@ x1 и x2 должны быть в диапазоне [0, 1]. Вы можете
|
||||||
Например,
|
Например,
|
||||||
|
|
||||||
view.Set(rui.Transition, rui.Params{
|
view.Set(rui.Transition, rui.Params{
|
||||||
rui.Height: rui.NewAnimation(rui.Params{
|
rui.Height: rui.NewAnimationProperty(rui.Params{
|
||||||
rui.Duration: 0.75,
|
rui.Duration: 0.75,
|
||||||
rui.TimingFunction: rui.EaseOutTiming,
|
rui.TimingFunction: rui.EaseOutTiming,
|
||||||
},
|
},
|
||||||
rui.BackgroundColor: rui.NewAnimation(rui.Params{
|
rui.BackgroundColor: rui.NewAnimationProperty(rui.Params{
|
||||||
rui.Duration: 1.5,
|
rui.Duration: 1.5,
|
||||||
rui.Delay: 0.5,
|
rui.Delay: 0.5,
|
||||||
rui.TimingFunction: rui.Linear,
|
rui.TimingFunction: rui.Linear,
|
||||||
|
@ -5273,7 +5273,7 @@ KeyFrames - промежуточные значения свойства (клю
|
||||||
90: rui.Px(220),
|
90: rui.Px(220),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
animation := rui.NewAnimation(rui.Params{
|
animation := rui.NewAnimationProperty(rui.Params{
|
||||||
rui.PropertyTag: []rui.AnimatedProperty{prop},
|
rui.PropertyTag: []rui.AnimatedProperty{prop},
|
||||||
rui.Duration: 2,
|
rui.Duration: 2,
|
||||||
rui.TimingFunction: LinearTiming,
|
rui.TimingFunction: LinearTiming,
|
||||||
|
|
14
README.md
14
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 AnimationProperty interface is used to set animation parameters. It extends the Properties interface.
|
||||||
The interface is created using the function:
|
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
|
Some of the properties of the AnimationProperty interface are used in both types of animation, the rest are used only
|
||||||
in animation scripts.
|
in animation scripts.
|
||||||
|
@ -5053,13 +5053,13 @@ You can specify this function either as text or using the function:
|
||||||
|
|
||||||
For example
|
For example
|
||||||
|
|
||||||
animation := rui.NewAnimation(rui.Params{
|
animation := rui.NewAnimationProperty(rui.Params{
|
||||||
rui.TimingFunction: rui.StepsTiming(10),
|
rui.TimingFunction: rui.StepsTiming(10),
|
||||||
})
|
})
|
||||||
|
|
||||||
equivalent to
|
equivalent to
|
||||||
|
|
||||||
animation := rui.NewAnimation(rui.Params{
|
animation := rui.NewAnimationProperty(rui.Params{
|
||||||
rui.TimingFunction: "steps(10)",
|
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.
|
It assigns a new value to the property, and the change occurs using the specified animation.
|
||||||
For example,
|
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.Duration: 0.75,
|
||||||
rui.TimingFunction: rui.EaseOutTiming,
|
rui.TimingFunction: rui.EaseOutTiming,
|
||||||
}))
|
}))
|
||||||
|
@ -5103,11 +5103,11 @@ and the value should be the AnimationProperty interface.
|
||||||
For example,
|
For example,
|
||||||
|
|
||||||
view.Set(rui.Transition, rui.Params{
|
view.Set(rui.Transition, rui.Params{
|
||||||
rui.Height: rui.NewAnimation(rui.Params{
|
rui.Height: rui.NewAnimationProperty(rui.Params{
|
||||||
rui.Duration: 0.75,
|
rui.Duration: 0.75,
|
||||||
rui.TimingFunction: rui.EaseOutTiming,
|
rui.TimingFunction: rui.EaseOutTiming,
|
||||||
},
|
},
|
||||||
rui.BackgroundColor: rui.NewAnimation(rui.Params{
|
rui.BackgroundColor: rui.NewAnimationProperty(rui.Params{
|
||||||
rui.Duration: 1.5,
|
rui.Duration: 1.5,
|
||||||
rui.Delay: 0.5,
|
rui.Delay: 0.5,
|
||||||
rui.TimingFunction: rui.Linear,
|
rui.TimingFunction: rui.Linear,
|
||||||
|
@ -5246,7 +5246,7 @@ Example,
|
||||||
90: rui.Px(220),
|
90: rui.Px(220),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
animation := rui.NewAnimation(rui.Params{
|
animation := rui.NewAnimationProperty(rui.Params{
|
||||||
rui.PropertyTag: []rui.AnimatedProperty{prop},
|
rui.PropertyTag: []rui.AnimatedProperty{prop},
|
||||||
rui.Duration: 2,
|
rui.Duration: 2,
|
||||||
rui.TimingFunction: LinearTiming,
|
rui.TimingFunction: LinearTiming,
|
||||||
|
|
97
animation.go
97
animation.go
|
@ -256,8 +256,19 @@ func parseAnimation(obj DataObject) AnimationProperty {
|
||||||
return animation
|
return animation
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewAnimation creates a new animation object and return its interface
|
// NewAnimationProperty creates a new animation object and return its interface
|
||||||
func NewAnimation(params Params) AnimationProperty {
|
//
|
||||||
|
// 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 := new(animationData)
|
||||||
animation.init()
|
animation.init()
|
||||||
|
|
||||||
|
@ -267,6 +278,88 @@ func NewAnimation(params Params) AnimationProperty {
|
||||||
return animation
|
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() {
|
func (animation *animationData) init() {
|
||||||
animation.dataProperty.init()
|
animation.dataProperty.init()
|
||||||
animation.normalize = normalizeAnimation
|
animation.normalize = normalizeAnimation
|
||||||
|
|
2
popup.go
2
popup.go
|
@ -797,7 +797,7 @@ func (popup *popupData) init(view View, popupParams Params) {
|
||||||
popup.layerView = NewGridLayout(session, layerParams)
|
popup.layerView = NewGridLayout(session, layerParams)
|
||||||
|
|
||||||
if popup.showOpacity != 1 || popup.showTransform != nil {
|
if popup.showOpacity != 1 || popup.showTransform != nil {
|
||||||
animation := NewAnimation(Params{
|
animation := NewAnimationProperty(Params{
|
||||||
Duration: popup.showDuration,
|
Duration: popup.showDuration,
|
||||||
TimingFunction: popup.showTiming,
|
TimingFunction: popup.showTiming,
|
||||||
})
|
})
|
||||||
|
|
|
@ -6,14 +6,14 @@ type PropertyName string
|
||||||
const (
|
const (
|
||||||
// ID is the constant for "id" property tag.
|
// ID is the constant for "id" property tag.
|
||||||
//
|
//
|
||||||
// # Used by View, Animation.
|
// # Used by View, AnimationProperty.
|
||||||
//
|
//
|
||||||
// Usage in View:
|
// Usage in View:
|
||||||
// Optional textual identifier for the view. Used to reference view from source code if needed.
|
// Optional textual identifier for the view. Used to reference view from source code if needed.
|
||||||
//
|
//
|
||||||
// Supported types: string.
|
// Supported types: string.
|
||||||
//
|
//
|
||||||
// # Usage in Animation:
|
// # Usage in AnimationProperty:
|
||||||
//
|
//
|
||||||
// Specifies the animation identifier. Used only for animation script.
|
// Specifies the animation identifier. Used only for animation script.
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in New Issue