-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtransition.go
59 lines (48 loc) · 1.41 KB
/
transition.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package animations
import (
"github.com/AllenDang/cimgui-go/imgui"
)
var _ Animation = &TransitionAnimation{}
// TransitionAnimation is a smooth transition between two renderers.
// It may apply to Windows (giu.WindowWidget) as well as to particular widgets/layouts.
type TransitionAnimation struct {
renderers []func(starterFunc StarterFunc)
}
// Transition creates a new TransitionAnimation.
func Transition(renderers ...func(starter StarterFunc)) *TransitionAnimation {
return &TransitionAnimation{
renderers: renderers,
}
}
// KeyFramesCount implements Animation interface.
func (t *TransitionAnimation) KeyFramesCount() int {
return len(t.renderers)
}
// Reset implements Animation interface.
func (t *TransitionAnimation) Reset() {
// noop
}
// Init implements Animation interface.
func (t *TransitionAnimation) Init() {
// noop
}
// BuildNormal implements Animation interface.
func (t *TransitionAnimation) BuildNormal(f KeyFrame, starter StarterFunc) {
t.renderers[f](starter)
}
// BuildAnimation implements Animation interface.
func (t *TransitionAnimation) BuildAnimation(
percentage, _ float32,
bf, df KeyFrame,
_ PlayMode,
starter StarterFunc,
) {
layout1 := t.renderers[bf]
layout2 := t.renderers[df]
imgui.PushStyleVarFloat(imgui.StyleVarAlpha, percentage)
layout2(starter)
imgui.PopStyleVar()
imgui.PushStyleVarFloat(imgui.StyleVarAlpha, 1-percentage)
layout1(starter)
imgui.PopStyleVar()
}