forked from mbk-lab/rui_orig
Updated transition
This commit is contained in:
parent
9af68bc5f3
commit
f3f3ddb084
|
@ -4,7 +4,9 @@
|
||||||
* The "interface{}" type replaced by "any"
|
* The "interface{}" type replaced by "any"
|
||||||
* Added "overflow", "arrow", "arrow-align", "arrow-size", "arrow-width", and "arrow-offset" properties
|
* Added "overflow", "arrow", "arrow-align", "arrow-size", "arrow-width", and "arrow-offset" properties
|
||||||
* Added "@ruiArrowSize" and "@ruiArrowWidth" constants to the default theme
|
* Added "@ruiArrowSize" and "@ruiArrowWidth" constants to the default theme
|
||||||
* Added the GetOverflow function
|
* Added Transition, Transitions, and SetTransition functions to the ViewStyle interface
|
||||||
|
* Added GetOverflow, and GetTransitions functions
|
||||||
|
* Changed GetTransition functions
|
||||||
|
|
||||||
# v0.8.0
|
# v0.8.0
|
||||||
|
|
||||||
|
|
77
animation.go
77
animation.go
|
@ -55,16 +55,19 @@ const (
|
||||||
// The animation plays forwards each cycle. In other words, each time the animation cycles,
|
// The animation plays forwards each cycle. In other words, each time the animation cycles,
|
||||||
// the animation will reset to the beginning state and start over again. This is the default value.
|
// the animation will reset to the beginning state and start over again. This is the default value.
|
||||||
NormalAnimation = 0
|
NormalAnimation = 0
|
||||||
|
|
||||||
// ReverseAnimation is value of the "animation-direction" property.
|
// ReverseAnimation is value of the "animation-direction" property.
|
||||||
// The animation plays backwards each cycle. In other words, each time the animation cycles,
|
// The animation plays backwards each cycle. In other words, each time the animation cycles,
|
||||||
// the animation will reset to the end state and start over again. Animation steps are performed
|
// the animation will reset to the end state and start over again. Animation steps are performed
|
||||||
// backwards, and timing functions are also reversed.
|
// backwards, and timing functions are also reversed.
|
||||||
// For example, an "ease-in" timing function becomes "ease-out".
|
// For example, an "ease-in" timing function becomes "ease-out".
|
||||||
ReverseAnimation = 1
|
ReverseAnimation = 1
|
||||||
|
|
||||||
// AlternateAnimation is value of the "animation-direction" property.
|
// AlternateAnimation is value of the "animation-direction" property.
|
||||||
// The animation reverses direction each cycle, with the first iteration being played forwards.
|
// The animation reverses direction each cycle, with the first iteration being played forwards.
|
||||||
// The count to determine if a cycle is even or odd starts at one.
|
// The count to determine if a cycle is even or odd starts at one.
|
||||||
AlternateAnimation = 2
|
AlternateAnimation = 2
|
||||||
|
|
||||||
// AlternateReverseAnimation is value of the "animation-direction" property.
|
// AlternateReverseAnimation is value of the "animation-direction" property.
|
||||||
// The animation reverses direction each cycle, with the first iteration being played backwards.
|
// The animation reverses direction each cycle, with the first iteration being played backwards.
|
||||||
// The count to determine if a cycle is even or odd starts at one.
|
// The count to determine if a cycle is even or odd starts at one.
|
||||||
|
@ -673,14 +676,38 @@ func (view *viewData) updateTransitionCSS() {
|
||||||
updateCSSProperty(view.htmlID(), "transition", view.transitionCSS(view.Session()), view.Session())
|
updateCSSProperty(view.htmlID(), "transition", view.transitionCSS(view.Session()), view.Session())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (view *viewData) getTransitions() Params {
|
func (style *viewStyle) Transition(tag string) Animation {
|
||||||
result := Params{}
|
if style.transitions != nil {
|
||||||
for tag, animation := range view.transitions {
|
if anim, ok := style.transitions[tag]; ok {
|
||||||
|
return anim
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (style *viewStyle) Transitions() map[string]Animation {
|
||||||
|
result := map[string]Animation{}
|
||||||
|
for tag, animation := range style.transitions {
|
||||||
result[tag] = animation
|
result[tag] = animation
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (style *viewStyle) SetTransition(tag string, animation Animation) {
|
||||||
|
if animation == nil {
|
||||||
|
delete(style.transitions, tag)
|
||||||
|
} else {
|
||||||
|
style.transitions[tag] = animation
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (view *viewData) SetTransition(tag string, animation Animation) {
|
||||||
|
view.viewStyle.SetTransition(tag, animation)
|
||||||
|
if view.created {
|
||||||
|
updateCSSProperty(view.htmlID(), "transition", view.transitionCSS(view.Session()), view.Session())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 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).
|
||||||
|
@ -697,38 +724,48 @@ func IsAnimationPaused(view View, subviewID string) bool {
|
||||||
return boolStyledProperty(view, subviewID, AnimationPaused, false)
|
return boolStyledProperty(view, subviewID, AnimationPaused, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetTransition 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 "" then transitions of the first argument (view) is returned
|
// If the second argument (subviewID) is "" then transitions of the first argument (view) is returned
|
||||||
func GetTransition(view View, subviewID string) Params {
|
func GetTransitions(view View, subviewID string) map[string]Animation {
|
||||||
if subviewID != "" {
|
if subviewID != "" {
|
||||||
view = ViewByID(view, subviewID)
|
view = ViewByID(view, subviewID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if view != nil {
|
if view != nil {
|
||||||
return view.getTransitions()
|
return view.Transitions()
|
||||||
}
|
}
|
||||||
|
|
||||||
return Params{}
|
return map[string]Animation{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 "" then transitions of the first argument (view) is returned
|
||||||
|
func GetTransition(view View, subviewID, tag string) Animation {
|
||||||
|
if subviewID != "" {
|
||||||
|
view = ViewByID(view, subviewID)
|
||||||
|
}
|
||||||
|
|
||||||
|
if view != nil {
|
||||||
|
return view.Transition(tag)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddTransition adds the transition for the subview property.
|
// AddTransition adds the transition for the subview property.
|
||||||
// If the second argument (subviewID) is "" then the transition is added to the first argument (view)
|
// If the second argument (subviewID) is "" then the transition is added to the first argument (view)
|
||||||
func AddTransition(view View, subviewID, tag string, animation Animation) bool {
|
func AddTransition(view View, subviewID, tag string, animation Animation) bool {
|
||||||
if tag == "" {
|
if tag != "" {
|
||||||
return false
|
if subviewID != "" {
|
||||||
}
|
view = ViewByID(view, subviewID)
|
||||||
|
}
|
||||||
|
|
||||||
if subviewID != "" {
|
if view != nil {
|
||||||
view = ViewByID(view, subviewID)
|
view.SetTransition(tag, animation)
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
if view == nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
transitions := view.getTransitions()
|
|
||||||
transitions[tag] = animation
|
|
||||||
return view.Set(Transition, transitions)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAnimation returns the subview animations. The result is always non-nil.
|
// GetAnimation returns the subview animations. The result is always non-nil.
|
||||||
|
|
|
@ -264,9 +264,22 @@ func (customView *CustomViewData) setScroll(x, y, width, height float64) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (customView *CustomViewData) getTransitions() Params {
|
func (customView *CustomViewData) Transition(tag string) Animation {
|
||||||
if customView.superView != nil {
|
if customView.superView != nil {
|
||||||
return customView.superView.getTransitions()
|
return customView.superView.Transition(tag)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (customView *CustomViewData) Transitions() map[string]Animation {
|
||||||
|
if customView.superView != nil {
|
||||||
|
return customView.superView.Transitions()
|
||||||
|
}
|
||||||
|
return map[string]Animation{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (customView *CustomViewData) SetTransition(tag string, animation Animation) {
|
||||||
|
if customView.superView != nil {
|
||||||
|
customView.superView.SetTransition(tag, animation)
|
||||||
}
|
}
|
||||||
return Params{}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,8 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
var stopTestLogFlag = false
|
// var stopTestLogFlag = false
|
||||||
var testLogDone chan int
|
// var testLogDone chan int
|
||||||
var ignoreTestLog = false
|
var ignoreTestLog = false
|
||||||
|
|
||||||
func createTestLog(t *testing.T, ignore bool) {
|
func createTestLog(t *testing.T, ignore bool) {
|
||||||
|
|
2
view.go
2
view.go
|
@ -71,8 +71,6 @@ type View interface {
|
||||||
cssStyle(self View, builder cssBuilder)
|
cssStyle(self View, builder cssBuilder)
|
||||||
addToCSSStyle(addCSS map[string]string)
|
addToCSSStyle(addCSS map[string]string)
|
||||||
|
|
||||||
getTransitions() Params
|
|
||||||
|
|
||||||
onResize(self View, x, y, width, height float64)
|
onResize(self View, x, y, width, height float64)
|
||||||
onItemResize(self View, index string, x, y, width, height float64)
|
onItemResize(self View, index string, x, y, width, height float64)
|
||||||
setNoResizeEvent()
|
setNoResizeEvent()
|
||||||
|
|
16
viewStyle.go
16
viewStyle.go
|
@ -10,6 +10,16 @@ import (
|
||||||
// ViewStyle interface of the style of view
|
// ViewStyle interface of the style of view
|
||||||
type ViewStyle interface {
|
type ViewStyle interface {
|
||||||
Properties
|
Properties
|
||||||
|
|
||||||
|
// Transition returns the transition animation of the property. Returns nil is there is no transition animation.
|
||||||
|
Transition(tag string) Animation
|
||||||
|
// Transitions returns the map of transition animations. The result is always non-nil.
|
||||||
|
Transitions() map[string]Animation
|
||||||
|
// 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.
|
||||||
|
// The "tag" argument is the property name.
|
||||||
|
SetTransition(tag string, animation Animation)
|
||||||
|
|
||||||
cssViewStyle(buffer cssBuilder, session Session)
|
cssViewStyle(buffer cssBuilder, session Session)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -741,7 +751,7 @@ func writePropertyValue(buffer *strings.Builder, tag string, value any, indent s
|
||||||
if animation := value[tag]; animation != nil {
|
if animation := value[tag]; animation != nil {
|
||||||
buffer.WriteString(indent2)
|
buffer.WriteString(indent2)
|
||||||
animation.writeTransitionString(tag, buffer)
|
animation.writeTransitionString(tag, buffer)
|
||||||
buffer.WriteString("\n")
|
buffer.WriteString(",\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buffer.WriteString(indent)
|
buffer.WriteString(indent)
|
||||||
|
@ -822,6 +832,10 @@ func writeViewStyle(name string, view ViewStyle, buffer *strings.Builder, indent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if transitions := view.Transitions(); len(transitions) > 0 {
|
||||||
|
writeProperty(Transition, transitions)
|
||||||
|
}
|
||||||
|
|
||||||
indent = indent[:len(indent)-1]
|
indent = indent[:len(indent)-1]
|
||||||
buffer.WriteString(indent)
|
buffer.WriteString(indent)
|
||||||
buffer.WriteString("}")
|
buffer.WriteString("}")
|
||||||
|
|
|
@ -47,8 +47,7 @@ func (container *viewsContainerData) setParentID(parentID string) {
|
||||||
func (container *viewsContainerData) Views() []View {
|
func (container *viewsContainerData) Views() []View {
|
||||||
if container.views == nil {
|
if container.views == nil {
|
||||||
container.views = []View{}
|
container.views = []View{}
|
||||||
}
|
} else if count := len(container.views); count > 0 {
|
||||||
if count := len(container.views); count > 0 {
|
|
||||||
views := make([]View, count)
|
views := make([]View, count)
|
||||||
copy(views, container.views)
|
copy(views, container.views)
|
||||||
return views
|
return views
|
||||||
|
|
Loading…
Reference in New Issue