-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
animation.go
98 lines (86 loc) · 2.72 KB
/
animation.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package tutorials
import (
"image/color"
"time"
"fyne.io/fyne"
"fyne.io/fyne/canvas"
"fyne.io/fyne/theme"
"fyne.io/fyne/widget"
)
func makeAnimationScreen(_ fyne.Window) fyne.CanvasObject {
curves := makeAnimationCurves()
curves.Move(fyne.NewPos(0, 140+theme.Padding()))
return fyne.NewContainerWithoutLayout(makeAnimationCanvas(), curves)
}
func makeAnimationCanvas() fyne.CanvasObject {
rect := canvas.NewRectangle(color.Black)
rect.Resize(fyne.NewSize(410, 140))
a := canvas.NewColorRGBAAnimation(theme.PrimaryColorNamed(theme.ColorBlue), theme.PrimaryColorNamed(theme.ColorGreen),
time.Second*3, func(c color.Color) {
rect.FillColor = c
canvas.Refresh(rect)
})
a.Repeat = true
a.AutoReverse = true
a.Start()
var a2 *fyne.Animation
i := widget.NewIcon(theme.CheckButtonCheckedIcon())
a2 = canvas.NewPositionAnimation(fyne.NewPos(0, 0), fyne.NewPos(350, 80), time.Second*3, func(p fyne.Position) {
i.Move(p)
width := 10 + (p.X / 7)
i.Resize(fyne.NewSize(width, width))
})
a2.Repeat = true
a2.AutoReverse = true
a2.Curve = fyne.AnimationLinear
a2.Start()
running := true
var toggle *widget.Button
toggle = widget.NewButton("Stop", func() {
if running {
a.Stop()
a2.Stop()
toggle.SetText("Start")
} else {
a.Start()
a2.Start()
toggle.SetText("Stop")
}
running = !running
})
toggle.Resize(toggle.MinSize())
toggle.Move(fyne.NewPos(152, 54))
return fyne.NewContainerWithoutLayout(rect, i, toggle)
}
func makeAnimationCurves() fyne.CanvasObject {
label1, box1, a1 := makeAnimationCurveItem("EaseInOut", fyne.AnimationEaseInOut, 0)
label2, box2, a2 := makeAnimationCurveItem("EaseIn", fyne.AnimationEaseIn, 30+theme.Padding())
label3, box3, a3 := makeAnimationCurveItem("EaseOut", fyne.AnimationEaseOut, 60+theme.Padding()*2)
label4, box4, a4 := makeAnimationCurveItem("Linear", fyne.AnimationLinear, 90+theme.Padding()*3)
start := widget.NewButton("Compare", func() {
a1.Start()
a2.Start()
a3.Start()
a4.Start()
})
start.Resize(start.MinSize())
start.Move(fyne.NewPos(0, 120+theme.Padding()*4))
return fyne.NewContainerWithoutLayout(label1, label2, label3, label4, box1, box2, box3, box4, start)
}
func makeAnimationCurveItem(label string, curve fyne.AnimationCurve, yOff float32) (
text *widget.Label, box fyne.CanvasObject, anim *fyne.Animation) {
text = widget.NewLabel(label)
text.Alignment = fyne.TextAlignCenter
text.Resize(fyne.NewSize(380, 30))
text.Move(fyne.NewPos(0, yOff))
box = canvas.NewRectangle(theme.TextColor())
box.Resize(fyne.NewSize(30, 30))
box.Move(fyne.NewPos(0, yOff))
anim = canvas.NewPositionAnimation(
fyne.NewPos(0, yOff), fyne.NewPos(380, yOff), time.Second, func(p fyne.Position) {
box.Move(p)
box.Refresh()
})
anim.Curve = curve
return
}