2021-09-09 12:08:31 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/anoshenko/rui"
|
|
|
|
)
|
|
|
|
|
|
|
|
const transitionDemoText = `
|
|
|
|
ListLayout {
|
|
|
|
width = 100%, height = 100%, orientation = vertical, padding = 12px,
|
|
|
|
content = [
|
|
|
|
"ease",
|
|
|
|
View { id = bar1, width = 20%, style = transitionBar },
|
|
|
|
"ease-in",
|
|
|
|
View { id = bar2, width = 20%, style = transitionBar },
|
|
|
|
"ease-out",
|
|
|
|
View { id = bar3, width = 20%, style = transitionBar },
|
|
|
|
"ease-in-out",
|
|
|
|
View { id = bar4, width = 20%, style = transitionBar },
|
|
|
|
"linear",
|
|
|
|
View { id = bar5, width = 20%, style = transitionBar },
|
|
|
|
"steps(5)",
|
|
|
|
View { id = bar6, width = 20%, style = transitionBar },
|
|
|
|
"cubic-bezier(0.1, -0.6, 0.2, 0)",
|
|
|
|
View { id = bar7, width = 20%, style = transitionBar },
|
|
|
|
Button { id = startTransition, content = "Start" }
|
|
|
|
]
|
|
|
|
}`
|
|
|
|
|
|
|
|
func createTransitionDemo(session rui.Session) rui.View {
|
|
|
|
view := rui.CreateViewFromText(session, transitionDemoText)
|
|
|
|
if view == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
bars := map[string]string{
|
|
|
|
"bar1": rui.EaseTiming,
|
|
|
|
"bar2": rui.EaseInTiming,
|
|
|
|
"bar3": rui.EaseOutTiming,
|
|
|
|
"bar4": rui.EaseInOutTiming,
|
|
|
|
"bar5": rui.LinearTiming,
|
|
|
|
"bar6": rui.StepsTiming(5),
|
|
|
|
"bar7": rui.CubicBezierTiming(0.1, -0.6, 0.2, 0),
|
|
|
|
}
|
|
|
|
|
|
|
|
rui.Set(view, "startTransition", rui.ClickEvent, func(button rui.View) {
|
2021-10-04 17:58:17 +03:00
|
|
|
|
2021-09-09 12:08:31 +03:00
|
|
|
for id, timing := range bars {
|
2021-10-04 17:58:17 +03:00
|
|
|
animation := rui.NewAnimation(rui.Params{
|
|
|
|
rui.Duration: 2,
|
|
|
|
rui.TimingFunction: timing,
|
|
|
|
})
|
|
|
|
|
2021-09-09 12:08:31 +03:00
|
|
|
if bar := rui.ViewByID(view, id); bar != nil {
|
|
|
|
if rui.GetWidth(bar, "").Value == 100 {
|
2021-10-04 17:58:17 +03:00
|
|
|
bar.Remove(rui.TransitionEndEvent)
|
|
|
|
bar.SetAnimated(rui.Width, rui.Percent(20), animation)
|
2021-09-09 12:08:31 +03:00
|
|
|
} else {
|
2021-10-04 17:58:17 +03:00
|
|
|
bar.Set(rui.TransitionEndEvent, func(v rui.View, tag string) {
|
|
|
|
bar.Remove(rui.TransitionEndEvent)
|
|
|
|
bar.SetAnimated(rui.Width, rui.Percent(20), animation)
|
2021-09-09 12:08:31 +03:00
|
|
|
})
|
2021-10-04 17:58:17 +03:00
|
|
|
bar.SetAnimated(rui.Width, rui.Percent(100), animation)
|
2021-09-09 12:08:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return view
|
|
|
|
}
|