Renamed Animation interface -> AnimationProperty

This commit is contained in:
Alexei Anoshenko 2024-12-06 19:15:23 +03:00
parent 1a60488537
commit 0c2bea9a75
9 changed files with 112 additions and 110 deletions

View File

@ -26,6 +26,8 @@
PolygonPointsClip function -> NewPolygonPointsClip PolygonPointsClip function -> NewPolygonPointsClip
ViewFilter interface -> FilterProperty ViewFilter interface -> FilterProperty
NewViewFilter function -> NewFilterProperty NewViewFilter function -> NewFilterProperty
Animation interface -> AnimationProperty
AnimationTag constant -> Animation
* Added functions: NewBounds, NewEllipticRadius, NewRadii, NewLinearGradient, NewCircleRadialGradient, * Added functions: NewBounds, NewEllipticRadius, NewRadii, NewLinearGradient, NewCircleRadialGradient,
NewEllipseRadialGradient, GetPushTransform, GetPushDuration, GetPushTiming, IsMoveToFrontAnimation, NewEllipseRadialGradient, GetPushTransform, GetPushDuration, GetPushTiming, IsMoveToFrontAnimation,

View File

@ -5038,14 +5038,14 @@ onNo или onCancel (если она не nil).
* Анимированное изменения значения свойства (далее "анимация перехода") * Анимированное изменения значения свойства (далее "анимация перехода")
* Сценарий анимированного изменения одного или нескольких свойств (далее просто "сценарий анимации") * Сценарий анимированного изменения одного или нескольких свойств (далее просто "сценарий анимации")
### Интерфейс Animation ### Интерфейс AnimationProperty
Для задания параметров анимации используется интерфейс Animation. Он расширяет интерфейс Properties. Для задания параметров анимации используется интерфейс AnimationProperty. Он расширяет интерфейс Properties.
Интерфейс создается с помощью функции: Интерфейс создается с помощью функции:
func NewAnimation(params Params) Animation func NewAnimation(params Params) AnimationProperty
Часть свойств интерфейса Animation используется в обоих типах анимации, остальные используются Часть свойств интерфейса AnimationProperty используется в обоих типах анимации, остальные используются
только в сценариях анимации. только в сценариях анимации.
Общими свойствами являются Общими свойствами являются
@ -5112,7 +5112,7 @@ x1 и x2 должны быть в диапазоне [0, 1]. Вы можете
Однократная анимация запускается с помощью функции SetAnimated интерфейса View. Данная функция имеет следующее Однократная анимация запускается с помощью функции SetAnimated интерфейса View. Данная функция имеет следующее
описание: описание:
SetAnimated(tag string, value any, animation Animation) bool SetAnimated(tag string, value any, animation AnimationProperty) bool
Она присваивает свойству новое значение, при этом изменение происходит с использованием заданной анимации. Она присваивает свойству новое значение, при этом изменение происходит с использованием заданной анимации.
Например, Например,
@ -5124,11 +5124,11 @@ x1 и x2 должны быть в диапазоне [0, 1]. Вы можете
Есть также глобальная функция для анимированного однократного изменения значения свойства дочернего View Есть также глобальная функция для анимированного однократного изменения значения свойства дочернего View
func SetAnimated(rootView View, viewID, tag string, value any, animation Animation) bool func SetAnimated(rootView View, viewID, tag string, value any, animation AnimationProperty) bool
Постоянная анимация запускается каждый раз когда изменяется значение свойства. Для задания постоянной Постоянная анимация запускается каждый раз когда изменяется значение свойства. Для задания постоянной
анимации перехода используется свойство "transition" (константа Transition). В качества значения данному анимации перехода используется свойство "transition" (константа Transition). В качества значения данному
Свойству присваивается rui.Params, где в качестве ключа должно быть имя свойства, а значение - интерфейс Animation. Свойству присваивается rui.Params, где в качестве ключа должно быть имя свойства, а значение - интерфейс AnimationProperty.
Например, Например,
view.Set(rui.Transition, rui.Params{ view.Set(rui.Transition, rui.Params{
@ -5151,7 +5151,7 @@ x1 и x2 должны быть в диапазоне [0, 1]. Вы можете
Добавлять новые анимации перехода рекомендуется с помощью функции Добавлять новые анимации перехода рекомендуется с помощью функции
func AddTransition(view View, subviewID, tag string, animation Animation) bool func AddTransition(view View, subviewID, tag string, animation AnimationProperty) bool
Вызов данной функции эквивалентен следующему коду Вызов данной функции эквивалентен следующему коду
@ -5192,7 +5192,7 @@ x1 и x2 должны быть в диапазоне [0, 1]. Вы можете
### Сценарий анимации ### Сценарий анимации
Сценарий анимации описывает более сложную анимацию, по сравнению с анимацией перехода. Для этого Сценарий анимации описывает более сложную анимацию, по сравнению с анимацией перехода. Для этого
в Animation добавляются дополнительные свойства: в AnimationProperty добавляются дополнительные свойства:
#### Свойство "property" #### Свойство "property"
@ -5256,11 +5256,11 @@ KeyFrames - промежуточные значения свойства (клю
#### Запуск анимации #### Запуск анимации
Для запуска сценария анимации необходимо созданный Animation интерфейс присвоить свойству "animation" Для запуска сценария анимации необходимо созданный AnimationProperty интерфейс присвоить свойству "animation"
(константа AnimationTag). Если View уже отображается на экране, то анимация запускается сразу (с учетом (константа Animation). Если View уже отображается на экране, то анимация запускается сразу (с учетом
заданной задержки), в противоположном случае анимация запускается как только View отобразится на экране. заданной задержки), в противоположном случае анимация запускается как только View отобразится на экране.
Свойству "animation" можно присваивать Animation и []Animation, т.е. можно запускать несколько анимаций Свойству "animation" можно присваивать AnimationProperty и []AnimationProperty, т.е. можно запускать несколько анимаций
одновременно для одного View одновременно для одного View
Пример, Пример,
@ -5278,7 +5278,7 @@ KeyFrames - промежуточные значения свойства (клю
rui.Duration: 2, rui.Duration: 2,
rui.TimingFunction: LinearTiming, rui.TimingFunction: LinearTiming,
}) })
rui.Set(view, "subview", rui.AnimationTag, animation) rui.Set(view, "subview", rui.Animation, animation)
#### Свойство "animation-paused" #### Свойство "animation-paused"

View File

@ -5009,14 +5009,14 @@ The library supports two types of animation:
* Animated property value changes (hereinafter "transition animation") * Animated property value changes (hereinafter "transition animation")
* Script animated change of one or more properties (hereinafter simply "animation script") * Script animated change of one or more properties (hereinafter simply "animation script")
### Animation interface ### AnimationProperty interface
The Animation 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) Animation func NewAnimation(params Params) AnimationProperty
Some of the properties of the Animation 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.
Common properties are Common properties are
@ -5082,7 +5082,7 @@ There are two types of transition animations:
A one-time animation is triggered using the SetAnimated function of the View interface. A one-time animation is triggered using the SetAnimated function of the View interface.
This function has the following description: This function has the following description:
SetAnimated(tag string, value any, animation Animation) bool SetAnimated(tag string, value any, animation AnimationProperty) bool
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,
@ -5094,12 +5094,12 @@ For example,
There is also a global function for animated one-time change of the property value of the child View There is also a global function for animated one-time change of the property value of the child View
func SetAnimated(rootView View, viewID, tag string, value any, animation Animation) bool func SetAnimated(rootView View, viewID, tag string, value any, animation AnimationProperty) bool
A persistent animation runs every time the property value changes. A persistent animation runs every time the property value changes.
To set the constant animation of the transition, use the "transition" property (the Transition constant). To set the constant animation of the transition, use the "transition" property (the Transition constant).
As a value, this property is assigned rui.Params, where the property name should be the key, As a value, this property is assigned rui.Params, where the property name should be the key,
and the value should be the Animation interface. and the value should be the AnimationProperty interface.
For example, For example,
view.Set(rui.Transition, rui.Params{ view.Set(rui.Transition, rui.Params{
@ -5122,7 +5122,7 @@ To get the current list of permanent transition animations, use the function
It is recommended to add new transition animations using the function It is recommended to add new transition animations using the function
func AddTransition(view View, subviewID, tag string, animation Animation) bool func AddTransition(view View, subviewID, tag string, animation AnimationProperty) bool
Calling this function is equivalent to the following code Calling this function is equivalent to the following code
@ -5162,7 +5162,7 @@ Get lists of listeners for transition animation events using functions:
### Animation script ### Animation script
An animation script describes a more complex animation than a transition animation. To do this, additional properties are added to Animation: An animation script describes a more complex animation than a transition animation. To do this, additional properties are added to AnimationProperty:
#### "property" property #### "property" property
@ -5228,12 +5228,12 @@ backward playback of the sequence. It can take the following values:
#### Animation start #### Animation start
To start the animation script, you must assign the interface created by Animation to the "animation" property To start the animation script, you must assign the interface created by AnimationProperty to the "animation" property
(the AnimationTag constant). If the View is already displayed on the screen, then the animation starts immediately (the Animation constant). If the View is already displayed on the screen, then the animation starts immediately
(taking into account the specified delay), otherwise the animation starts as soon as the View is displayed (taking into account the specified delay), otherwise the animation starts as soon as the View is displayed
on the screen. on the screen.
The "animation" property can be assigned Animation and [] Animation, ie. you can run several animations The "animation" property can be assigned AnimationProperty and [] AnimationProperty, ie. you can run several animations
at the same time for one View at the same time for one View
Example, Example,
@ -5251,7 +5251,7 @@ Example,
rui.Duration: 2, rui.Duration: 2,
rui.TimingFunction: LinearTiming, rui.TimingFunction: LinearTiming,
}) })
rui.Set(view, "subview", rui.AnimationTag, animation) rui.Set(view, "subview", rui.Animation, animation)
#### "animation-paused" property #### "animation-paused" property

View File

@ -9,20 +9,20 @@ import (
// Constants which related to view's animation // Constants which related to view's animation
const ( const (
// AnimationTag is the constant for "animation" property tag. // Animation is the constant for "animation" property tag.
// //
// Used by View. // Used by View.
// Sets and starts animations. // Sets and starts animations.
// //
// Supported types: Animation, []Animation. // Supported types: AnimationProperty, []AnimationProperty.
// //
// Internal type is []Animation, other types converted to it during assignment. // Internal type is []AnimationProperty, other types converted to it during assignment.
// See Animation description for more details. // See AnimationProperty description for more details.
AnimationTag PropertyName = "animation" Animation PropertyName = "animation"
// AnimationPaused is the constant for "animation-paused" property tag. // AnimationPaused is the constant for "animation-paused" property tag.
// //
// Used by Animation. // Used by AnimationProperty.
// Controls whether the animation is running or paused. // Controls whether the animation is running or paused.
// //
// Supported types: bool, int, string. // Supported types: bool, int, string.
@ -36,7 +36,7 @@ const (
// //
// Used by View. // Used by View.
// //
// Sets transition animation of view properties. Each provided property must contain Animation which describe how // Sets transition animation of view properties. Each provided property must contain AnimationProperty which describe how
// particular property will be animated on property value change. Transition animation can be applied to properties of the // particular property will be animated on property value change. Transition animation can be applied to properties of the
// type SizeUnit, Color, AngleUnit, float64 and composite properties that contain elements of the listed types(for // type SizeUnit, Color, AngleUnit, float64 and composite properties that contain elements of the listed types(for
// example, "shadow", "border", etc.). If we'll try to animate other properties with internal type like bool or // example, "shadow", "border", etc.). If we'll try to animate other properties with internal type like bool or
@ -49,7 +49,7 @@ const (
// PropertyTag is the constant for "property" property tag. // PropertyTag is the constant for "property" property tag.
// //
// Used by Animation. // Used by AnimationProperty.
// //
// Describes a scenario for changing a View's property. Used only for animation script. // Describes a scenario for changing a View's property. Used only for animation script.
// //
@ -61,7 +61,7 @@ const (
// Duration is the constant for "duration" property tag. // Duration is the constant for "duration" property tag.
// //
// Used by Animation. // Used by AnimationProperty.
// //
// Sets the length of time in seconds that an animation takes to complete one cycle. // Sets the length of time in seconds that an animation takes to complete one cycle.
// //
@ -72,7 +72,7 @@ const (
// Delay is the constant for "delay" property tag. // Delay is the constant for "delay" property tag.
// //
// Used by Animation. // Used by AnimationProperty.
// //
// Specifies the amount of time in seconds to wait from applying the animation to an element before beginning to perform // 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 // the animation. The animation can start later, immediately from its beginning or immediately and partway through the
@ -85,7 +85,7 @@ const (
// TimingFunction is the constant for "timing-function" property tag. // TimingFunction is the constant for "timing-function" property tag.
// //
// Used by Animation. // Used by AnimationProperty.
// //
// Set how an animation progresses through the duration of each cycle. // Set how an animation progresses through the duration of each cycle.
// //
@ -103,7 +103,7 @@ const (
// IterationCount is the constant for "iteration-count" property tag. // IterationCount is the constant for "iteration-count" property tag.
// //
// Used by Animation. // Used by AnimationProperty.
// //
// Sets the number of times an animation sequence should be played before stopping. Used only for animation script. // Sets the number of times an animation sequence should be played before stopping. Used only for animation script.
// //
@ -114,7 +114,7 @@ const (
// AnimationDirection is the constant for "animation-direction" property tag. // AnimationDirection is the constant for "animation-direction" property tag.
// //
// Used by Animation. // Used by AnimationProperty.
// //
// Whether an animation should play forward, backward, or alternate back and forth between playing the sequence forward // Whether an animation should play forward, backward, or alternate back and forth between playing the sequence forward
// and backward. Used only for animation script. // and backward. Used only for animation script.
@ -208,21 +208,21 @@ type animationData struct {
keyFramesName string keyFramesName string
usageCounter int usageCounter int
view View view View
listener func(view View, animation Animation, event PropertyName) listener func(view View, animation AnimationProperty, event PropertyName)
oldListeners map[PropertyName][]func(View, PropertyName) oldListeners map[PropertyName][]func(View, PropertyName)
oldAnimation []Animation oldAnimation []AnimationProperty
} }
// Animation interface is used to set animation parameters. Used properties: // AnimationProperty interface is used to set animation parameters. Used properties:
// //
// "property", "id", "duration", "delay", "timing-function", "iteration-count", and "animation-direction" // "property", "id", "duration", "delay", "timing-function", "iteration-count", and "animation-direction"
type Animation interface { type AnimationProperty interface {
Properties Properties
fmt.Stringer fmt.Stringer
// Start starts the animation for the view specified by the first argument. // Start starts the animation for the view specified by the first argument.
// The second argument specifies the animation event listener (can be nil) // The second argument specifies the animation event listener (can be nil)
Start(view View, listener func(view View, animation Animation, event PropertyName)) bool Start(view View, listener func(view View, animation AnimationProperty, event PropertyName)) bool
// Stop stops the animation // Stop stops the animation
Stop() Stop()
// Pause pauses the animation // Pause pauses the animation
@ -239,7 +239,7 @@ type Animation interface {
unused(session Session) unused(session Session)
} }
func parseAnimation(obj DataObject) Animation { func parseAnimation(obj DataObject) AnimationProperty {
animation := new(animationData) animation := new(animationData)
animation.init() animation.init()
@ -257,7 +257,7 @@ func parseAnimation(obj DataObject) Animation {
} }
// NewAnimation creates a new animation object and return its interface // NewAnimation creates a new animation object and return its interface
func NewAnimation(params Params) Animation { func NewAnimation(params Params) AnimationProperty {
animation := new(animationData) animation := new(animationData)
animation.init() animation.init()
@ -269,7 +269,7 @@ func NewAnimation(params Params) Animation {
func (animation *animationData) init() { func (animation *animationData) init() {
animation.dataProperty.init() animation.dataProperty.init()
animation.normalize = normalizeAnimationTag animation.normalize = normalizeAnimation
animation.set = animationSet animation.set = animationSet
animation.supportedProperties = []PropertyName{ID, PropertyTag, Duration, Delay, TimingFunction, IterationCount, AnimationDirection} animation.supportedProperties = []PropertyName{ID, PropertyTag, Duration, Delay, TimingFunction, IterationCount, AnimationDirection}
} }
@ -314,7 +314,7 @@ func (animation *animationData) unused(session Session) {
} }
} }
func normalizeAnimationTag(tag PropertyName) PropertyName { func normalizeAnimation(tag PropertyName) PropertyName {
tag = defaultNormalize(tag) tag = defaultNormalize(tag)
if tag == Direction { if tag == Direction {
return AnimationDirection return AnimationDirection
@ -777,7 +777,7 @@ func (session *sessionData) registerAnimation(props []AnimatedProperty) string {
return name return name
} }
func (view *viewData) SetAnimated(tag PropertyName, value any, animation Animation) bool { func (view *viewData) SetAnimated(tag PropertyName, value any, animation AnimationProperty) bool {
if animation == nil { if animation == nil {
return view.Set(tag, value) return view.Set(tag, value)
} }
@ -790,7 +790,7 @@ func (view *viewData) SetAnimated(tag PropertyName, value any, animation Animati
session.updateProperty(htmlID, "ontransitioncancel", "transitionCancelEvent(this, event)") session.updateProperty(htmlID, "ontransitioncancel", "transitionCancelEvent(this, event)")
transitions := getTransitionProperty(view) transitions := getTransitionProperty(view)
var prevAnimation Animation = nil var prevAnimation AnimationProperty = nil
if transitions != nil { if transitions != nil {
if prev, ok := transitions[tag]; ok { if prev, ok := transitions[tag]; ok {
prevAnimation = prev prevAnimation = prev
@ -812,8 +812,8 @@ func (view *viewData) SetAnimated(tag PropertyName, value any, animation Animati
} }
func animationCSS(properties Properties, session Session) string { func animationCSS(properties Properties, session Session) string {
if value := properties.getRaw(AnimationTag); value != nil { if value := properties.getRaw(Animation); value != nil {
if animations, ok := value.([]Animation); ok { if animations, ok := value.([]AnimationProperty); ok {
buffer := allocStringBuilder() buffer := allocStringBuilder()
defer freeStringBuilder(buffer) defer freeStringBuilder(buffer)
@ -874,7 +874,7 @@ func (view *viewData) updateTransitionCSS() {
} }
*/ */
func (style *viewStyle) Transition(tag PropertyName) Animation { func (style *viewStyle) Transition(tag PropertyName) AnimationProperty {
if transitions := getTransitionProperty(style); transitions != nil { if transitions := getTransitionProperty(style); transitions != nil {
if anim, ok := transitions[tag]; ok { if anim, ok := transitions[tag]; ok {
return anim return anim
@ -883,26 +883,26 @@ func (style *viewStyle) Transition(tag PropertyName) Animation {
return nil return nil
} }
func (style *viewStyle) Transitions() map[PropertyName]Animation { func (style *viewStyle) Transitions() map[PropertyName]AnimationProperty {
result := map[PropertyName]Animation{} result := map[PropertyName]AnimationProperty{}
for tag, animation := range getTransitionProperty(style) { for tag, animation := range getTransitionProperty(style) {
result[tag] = animation result[tag] = animation
} }
return result return result
} }
func (style *viewStyle) SetTransition(tag PropertyName, animation Animation) { func (style *viewStyle) SetTransition(tag PropertyName, animation AnimationProperty) {
setTransition(style, style.normalize(tag), animation) setTransition(style, style.normalize(tag), animation)
} }
func (view *viewData) SetTransition(tag PropertyName, animation Animation) { func (view *viewData) SetTransition(tag PropertyName, animation AnimationProperty) {
setTransition(view, view.normalize(tag), animation) setTransition(view, view.normalize(tag), animation)
if view.created { if view.created {
view.session.updateCSSProperty(view.htmlID(), "transition", transitionCSS(view, view.session)) view.session.updateCSSProperty(view.htmlID(), "transition", transitionCSS(view, view.session))
} }
} }
func setTransition(properties Properties, tag PropertyName, animation Animation) { func setTransition(properties Properties, tag PropertyName, animation AnimationProperty) {
transitions := getTransitionProperty(properties) transitions := getTransitionProperty(properties)
if animation == nil { if animation == nil {
@ -915,13 +915,13 @@ func setTransition(properties Properties, tag PropertyName, animation Animation)
} else if transitions != nil { } else if transitions != nil {
transitions[tag] = animation transitions[tag] = animation
} else { } else {
properties.setRaw(Transition, map[PropertyName]Animation{tag: animation}) properties.setRaw(Transition, map[PropertyName]AnimationProperty{tag: animation})
} }
} }
func getTransitionProperty(properties Properties) map[PropertyName]Animation { func getTransitionProperty(properties Properties) map[PropertyName]AnimationProperty {
if value := properties.getRaw(Transition); value != nil { if value := properties.getRaw(Transition); value != nil {
if transitions, ok := value.(map[PropertyName]Animation); ok { if transitions, ok := value.(map[PropertyName]AnimationProperty); ok {
return transitions return transitions
} }
} }
@ -930,7 +930,7 @@ func getTransitionProperty(properties Properties) map[PropertyName]Animation {
func setAnimationProperty(properties Properties, tag PropertyName, value any) bool { func setAnimationProperty(properties Properties, tag PropertyName, value any) bool {
set := func(animations []Animation) { set := func(animations []AnimationProperty) {
properties.setRaw(tag, animations) properties.setRaw(tag, animations)
for _, animation := range animations { for _, animation := range animations {
animation.used() animation.used()
@ -938,22 +938,22 @@ func setAnimationProperty(properties Properties, tag PropertyName, value any) bo
} }
switch value := value.(type) { switch value := value.(type) {
case Animation: case AnimationProperty:
set([]Animation{value}) set([]AnimationProperty{value})
return true return true
case []Animation: case []AnimationProperty:
set(value) set(value)
return true return true
case DataObject: case DataObject:
if animation := parseAnimation(value); animation.hasAnimatedProperty() { if animation := parseAnimation(value); animation.hasAnimatedProperty() {
set([]Animation{animation}) set([]AnimationProperty{animation})
return true return true
} }
case DataNode: case DataNode:
animations := []Animation{} animations := []AnimationProperty{}
result := true result := true
for i := 0; i < value.ArraySize(); i++ { for i := 0; i < value.ArraySize(); i++ {
if obj := value.ArrayElement(i).Object(); obj != nil { if obj := value.ArrayElement(i).Object(); obj != nil {
@ -980,7 +980,7 @@ func setAnimationProperty(properties Properties, tag PropertyName, value any) bo
// SetAnimated sets the property with name "tag" of the "rootView" subview with "viewID" id by value. Result: // SetAnimated sets the property with name "tag" of the "rootView" subview with "viewID" id by value. Result:
// true - success, // true - success,
// false - error (incompatible type or invalid format of a string value, see AppLog). // false - error (incompatible type or invalid format of a string value, see AppLog).
func SetAnimated(rootView View, viewID string, tag PropertyName, value any, animation Animation) bool { func SetAnimated(rootView View, viewID string, tag PropertyName, value any, animation AnimationProperty) bool {
if view := ViewByID(rootView, viewID); view != nil { if view := ViewByID(rootView, viewID); view != nil {
return view.SetAnimated(tag, value, animation) return view.SetAnimated(tag, value, animation)
} }
@ -995,17 +995,17 @@ func IsAnimationPaused(view View, subviewID ...string) bool {
// GetTransitions returns the subview transitions. The result is always non-nil. // GetTransitions returns the subview transitions. The result is always non-nil.
// If the second argument (subviewID) is not specified or it is "" then transitions of the first argument (view) is returned // If the second argument (subviewID) is not specified or it is "" then transitions of the first argument (view) is returned
func GetTransitions(view View, subviewID ...string) map[PropertyName]Animation { func GetTransitions(view View, subviewID ...string) map[PropertyName]AnimationProperty {
if view = getSubview(view, subviewID); view != nil { if view = getSubview(view, subviewID); view != nil {
return view.Transitions() return view.Transitions()
} }
return map[PropertyName]Animation{} return map[PropertyName]AnimationProperty{}
} }
// GetTransition returns the subview property transition. If there is no transition for the given property then nil is returned. // GetTransition returns the subview property transition. If there is no transition for the given property then nil is returned.
// If the second argument (subviewID) is not specified or it is "" then transitions of the first argument (view) is returned // If the second argument (subviewID) is not specified or it is "" then transitions of the first argument (view) is returned
func GetTransition(view View, subviewID string, tag PropertyName) Animation { func GetTransition(view View, subviewID string, tag PropertyName) AnimationProperty {
if subviewID != "" { if subviewID != "" {
view = ViewByID(view, subviewID) view = ViewByID(view, subviewID)
} }
@ -1019,7 +1019,7 @@ func GetTransition(view View, subviewID string, tag PropertyName) Animation {
// AddTransition adds the transition for the subview property. // AddTransition adds the transition for the subview property.
// If the second argument (subviewID) is not specified or it is "" then the transition is added to the first argument (view) // If the second argument (subviewID) is not specified or it is "" then the transition is added to the first argument (view)
func AddTransition(view View, subviewID string, tag PropertyName, animation Animation) bool { func AddTransition(view View, subviewID string, tag PropertyName, animation AnimationProperty) bool {
if tag != "" { if tag != "" {
if subviewID != "" { if subviewID != "" {
view = ViewByID(view, subviewID) view = ViewByID(view, subviewID)
@ -1035,14 +1035,14 @@ func AddTransition(view View, subviewID string, tag PropertyName, animation Anim
// GetAnimation returns the subview animations. The result is always non-nil. // GetAnimation returns the subview animations. The result is always non-nil.
// If the second argument (subviewID) is not specified or it is "" then transitions of the first argument (view) is returned // If the second argument (subviewID) is not specified or it is "" then transitions of the first argument (view) is returned
func GetAnimation(view View, subviewID ...string) []Animation { func GetAnimation(view View, subviewID ...string) []AnimationProperty {
if view = getSubview(view, subviewID); view != nil { if view = getSubview(view, subviewID); view != nil {
if value := view.getRaw(AnimationTag); value != nil { if value := view.getRaw(Animation); value != nil {
if animations, ok := value.([]Animation); ok && animations != nil { if animations, ok := value.([]AnimationProperty); ok && animations != nil {
return animations return animations
} }
} }
} }
return []Animation{} return []AnimationProperty{}
} }

View File

@ -1,6 +1,6 @@
package rui package rui
func (animation *animationData) Start(view View, listener func(view View, animation Animation, event PropertyName)) bool { func (animation *animationData) Start(view View, listener func(view View, animation AnimationProperty, event PropertyName)) bool {
if view == nil { if view == nil {
ErrorLog("nil View in animation.Start() function") ErrorLog("nil View in animation.Start() function")
return false return false
@ -13,8 +13,8 @@ func (animation *animationData) Start(view View, listener func(view View, animat
animation.listener = listener animation.listener = listener
animation.oldAnimation = nil animation.oldAnimation = nil
if value := view.Get(AnimationTag); value != nil { if value := view.Get(Animation); value != nil {
if oldAnimation, ok := value.([]Animation); ok && len(oldAnimation) > 0 { if oldAnimation, ok := value.([]AnimationProperty); ok && len(oldAnimation) > 0 {
animation.oldAnimation = oldAnimation animation.oldAnimation = oldAnimation
} }
} }
@ -42,7 +42,7 @@ func (animation *animationData) Start(view View, listener func(view View, animat
setListeners(AnimationCancelEvent, animation.onAnimationCancel) setListeners(AnimationCancelEvent, animation.onAnimationCancel)
setListeners(AnimationIterationEvent, animation.onAnimationIteration) setListeners(AnimationIterationEvent, animation.onAnimationIteration)
view.Set(AnimationTag, animation) view.Set(Animation, animation)
return true return true
} }
@ -57,10 +57,10 @@ func (animation *animationData) finish() {
} }
if animation.oldAnimation != nil { if animation.oldAnimation != nil {
animation.view.Set(AnimationTag, animation.oldAnimation) animation.view.Set(Animation, animation.oldAnimation)
animation.oldAnimation = nil animation.oldAnimation = nil
} else { } else {
animation.view.Set(AnimationTag, "") animation.view.Set(Animation, "")
} }
animation.oldListeners = map[PropertyName][]func(View, PropertyName){} animation.oldListeners = map[PropertyName][]func(View, PropertyName){}

View File

@ -89,7 +89,7 @@ func (customView *CustomViewData) Set(tag PropertyName, value any) bool {
// SetAnimated sets the value (second argument) of the property with name defined by the first argument. // SetAnimated sets the value (second argument) of the property with name defined by the first argument.
// Return "true" if the value has been set, in the opposite case "false" are returned and // Return "true" if the value has been set, in the opposite case "false" are returned and
// a description of the error is written to the log // a description of the error is written to the log
func (customView *CustomViewData) SetAnimated(tag PropertyName, value any, animation Animation) bool { func (customView *CustomViewData) SetAnimated(tag PropertyName, value any, animation AnimationProperty) bool {
return customView.superView.SetAnimated(tag, value, animation) return customView.superView.SetAnimated(tag, value, animation)
} }
@ -323,7 +323,7 @@ func (customView *CustomViewData) setScroll(x, y, width, height float64) {
} }
// Transition returns the transition animation of the property(tag). Returns nil is there is no transition animation. // Transition returns the transition animation of the property(tag). Returns nil is there is no transition animation.
func (customView *CustomViewData) Transition(tag PropertyName) Animation { func (customView *CustomViewData) Transition(tag PropertyName) AnimationProperty {
if customView.superView != nil { if customView.superView != nil {
return customView.superView.Transition(tag) return customView.superView.Transition(tag)
} }
@ -331,17 +331,17 @@ func (customView *CustomViewData) Transition(tag PropertyName) Animation {
} }
// Transitions returns a map of transition animations. The result is always non-nil. // Transitions returns a map of transition animations. The result is always non-nil.
func (customView *CustomViewData) Transitions() map[PropertyName]Animation { func (customView *CustomViewData) Transitions() map[PropertyName]AnimationProperty {
if customView.superView != nil { if customView.superView != nil {
return customView.superView.Transitions() return customView.superView.Transitions()
} }
return map[PropertyName]Animation{} return map[PropertyName]AnimationProperty{}
} }
// SetTransition sets the transition animation for the property if "animation" argument is not nil, and // SetTransition sets the transition animation for the property if "animation" argument is not nil, and
// removes the transition animation of the property if "animation" argument is nil. // removes the transition animation of the property if "animation" argument is nil.
// The "tag" argument is the property name. // The "tag" argument is the property name.
func (customView *CustomViewData) SetTransition(tag PropertyName, animation Animation) { func (customView *CustomViewData) SetTransition(tag PropertyName, animation AnimationProperty) {
if customView.superView != nil { if customView.superView != nil {
customView.superView.SetTransition(tag, animation) customView.superView.SetTransition(tag, animation)
} }

28
view.go
View File

@ -62,7 +62,7 @@ type View interface {
// SetAnimated sets the value (second argument) of the property with name defined by the first argument. // SetAnimated sets the value (second argument) of the property with name defined by the first argument.
// Return "true" if the value has been set, in the opposite case "false" are returned and // Return "true" if the value has been set, in the opposite case "false" are returned and
// a description of the error is written to the log // a description of the error is written to the log
SetAnimated(tag PropertyName, value any, animation Animation) bool SetAnimated(tag PropertyName, value any, animation AnimationProperty) bool
// SetChangeListener set the function to track the change of the View property // SetChangeListener set the function to track the change of the View property
SetChangeListener(tag PropertyName, listener func(View, PropertyName)) SetChangeListener(tag PropertyName, listener func(View, PropertyName))
@ -102,7 +102,7 @@ type viewData struct {
parentID string parentID string
systemClass string systemClass string
changeListener map[PropertyName]func(View, PropertyName) changeListener map[PropertyName]func(View, PropertyName)
singleTransition map[PropertyName]Animation singleTransition map[PropertyName]AnimationProperty
addCSS map[string]string addCSS map[string]string
frame Frame frame Frame
scroll Frame scroll Frame
@ -155,7 +155,7 @@ func (view *viewData) init(session Session) {
view.changeListener = map[PropertyName]func(View, PropertyName){} view.changeListener = map[PropertyName]func(View, PropertyName){}
view.addCSS = map[string]string{} view.addCSS = map[string]string{}
//view.animation = map[string]AnimationEndListener{} //view.animation = map[string]AnimationEndListener{}
view.singleTransition = map[PropertyName]Animation{} view.singleTransition = map[PropertyName]AnimationProperty{}
view.noResizeEvent = false view.noResizeEvent = false
view.created = false view.created = false
view.hasHtmlDisabled = false view.hasHtmlDisabled = false
@ -294,16 +294,16 @@ func (view *viewData) removeFunc(tag PropertyName) []PropertyName {
changedTags = []PropertyName{} changedTags = []PropertyName{}
} }
case AnimationTag: case Animation:
if val := view.getRaw(AnimationTag); val != nil { if val := view.getRaw(Animation); val != nil {
if animations, ok := val.([]Animation); ok { if animations, ok := val.([]AnimationProperty); ok {
for _, animation := range animations { for _, animation := range animations {
animation.unused(view.session) animation.unused(view.session)
} }
} }
view.setRaw(AnimationTag, nil) view.setRaw(Animation, nil)
changedTags = []PropertyName{AnimationTag} changedTags = []PropertyName{Animation}
} }
default: default:
@ -326,10 +326,10 @@ func (view *viewData) setFunc(tag PropertyName, value any) []PropertyName {
notCompatibleType(ID, value) notCompatibleType(ID, value)
return nil return nil
case AnimationTag: case Animation:
oldAnimations := []Animation{} oldAnimations := []AnimationProperty{}
if val := view.getRaw(AnimationTag); val != nil { if val := view.getRaw(Animation); val != nil {
if animation, ok := val.([]Animation); ok { if animation, ok := val.([]AnimationProperty); ok {
oldAnimations = animation oldAnimations = animation
} }
} }
@ -341,7 +341,7 @@ func (view *viewData) setFunc(tag PropertyName, value any) []PropertyName {
for _, animation := range oldAnimations { for _, animation := range oldAnimations {
animation.unused(view.session) animation.unused(view.session)
} }
return []PropertyName{AnimationTag} return []PropertyName{Animation}
case TabIndex, "tab-index": case TabIndex, "tab-index":
return setIntProperty(view, TabIndex, value) return setIntProperty(view, TabIndex, value)
@ -635,7 +635,7 @@ func (view *viewData) propertyChanged(tag PropertyName) {
case Transition: case Transition:
session.updateCSSProperty(htmlID, "transition", transitionCSS(view, session)) session.updateCSSProperty(htmlID, "transition", transitionCSS(view, session))
case AnimationTag: case Animation:
session.updateCSSProperty(htmlID, "animation", animationCSS(view, session)) session.updateCSSProperty(htmlID, "animation", animationCSS(view, session))
case AnimationPaused: case AnimationPaused:

View File

@ -12,15 +12,15 @@ type ViewStyle interface {
Properties Properties
// Transition returns the transition animation of the property. Returns nil is there is no transition animation. // Transition returns the transition animation of the property. Returns nil is there is no transition animation.
Transition(tag PropertyName) Animation Transition(tag PropertyName) AnimationProperty
// Transitions returns the map of transition animations. The result is always non-nil. // Transitions returns the map of transition animations. The result is always non-nil.
Transitions() map[PropertyName]Animation Transitions() map[PropertyName]AnimationProperty
// SetTransition sets the transition animation for the property if "animation" argument is not nil, and // SetTransition sets the transition animation for the property if "animation" argument is not nil, and
// removes the transition animation of the property if "animation" argument is nil. // removes the transition animation of the property if "animation" argument is nil.
// The "tag" argument is the property name. // The "tag" argument is the property name.
SetTransition(tag PropertyName, animation Animation) SetTransition(tag PropertyName, animation AnimationProperty)
cssViewStyle(buffer cssBuilder, session Session) cssViewStyle(buffer cssBuilder, session Session)
} }
@ -412,7 +412,7 @@ func (style *viewStyle) cssViewStyle(builder cssBuilder, session Session) {
} }
if animation := animationCSS(style, session); animation != "" { if animation := animationCSS(style, session); animation != "" {
builder.add(string(AnimationTag), animation) builder.add(string(Animation), animation)
} }
if pause, ok := boolProperty(style, AnimationPaused, session); ok { if pause, ok := boolProperty(style, AnimationPaused, session); ok {
@ -566,7 +566,7 @@ func supportedPropertyValue(value any) bool {
case []BackgroundElement: case []BackgroundElement:
case []BackgroundGradientPoint: case []BackgroundGradientPoint:
case []BackgroundGradientAngle: case []BackgroundGradientAngle:
case map[PropertyName]Animation: case map[PropertyName]AnimationProperty:
default: default:
return false return false
} }
@ -775,7 +775,7 @@ func writePropertyValue(buffer *strings.Builder, tag PropertyName, value any, in
} }
buffer.WriteRune('"') buffer.WriteRune('"')
case map[PropertyName]Animation: case map[PropertyName]AnimationProperty:
switch count := len(value); count { switch count := len(value); count {
case 0: case 0:
buffer.WriteString("[]") buffer.WriteString("[]")

View File

@ -6,7 +6,7 @@ import (
func setTransitionProperty(properties Properties, value any) bool { func setTransitionProperty(properties Properties, value any) bool {
transitions := map[PropertyName]Animation{} transitions := map[PropertyName]AnimationProperty{}
setObject := func(obj DataObject) bool { setObject := func(obj DataObject) bool {
if obj != nil { if obj != nil {
@ -33,7 +33,7 @@ func setTransitionProperty(properties Properties, value any) bool {
} }
if val != nil { if val != nil {
if animation, ok := val.(Animation); ok { if animation, ok := val.(AnimationProperty); ok {
transitions[PropertyName(tag)] = animation transitions[PropertyName(tag)] = animation
} else { } else {
notCompatibleType(Transition, val) notCompatibleType(Transition, val)
@ -424,7 +424,7 @@ func viewStyleSet(style Properties, tag PropertyName, value any) []PropertyName
return nil return nil
} }
case AnimationTag: case Animation:
if setAnimationProperty(style, tag, value) { if setAnimationProperty(style, tag, value) {
return []PropertyName{tag} return []PropertyName{tag}
} else { } else {