forked from g45t345rt/g45w
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload_state.go
152 lines (132 loc) · 3.77 KB
/
load_state.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package main
import (
"time"
"gioui.org/app"
"gioui.org/font"
"gioui.org/layout"
"gioui.org/op"
"gioui.org/op/paint"
"gioui.org/text"
"gioui.org/unit"
"gioui.org/widget/material"
"github.com/g45t345rt/g45w/animation"
"github.com/g45t345rt/g45w/assets"
"github.com/g45t345rt/g45w/components"
"github.com/g45t345rt/g45w/settings"
"github.com/g45t345rt/g45w/theme"
"github.com/tanema/gween"
"github.com/tanema/gween/ease"
)
type LogoSplash struct {
animation *animation.Animation
image *components.Image
}
func NewLogoSplash() *LogoSplash {
animtation := animation.NewAnimation(false, gween.NewSequence(
gween.New(0, 1, 1, ease.InBack),
))
animtation.Sequence.SetLoop(-1)
src, _ := assets.GetImage("dero_polygon.png")
image := &components.Image{
Src: paint.NewImageOp(src),
Fit: components.Cover,
}
return &LogoSplash{
animation: animtation,
image: image,
}
}
func (l *LogoSplash) Layout(gtx layout.Context) layout.Dimensions {
r := op.Record(gtx.Ops)
dims := l.image.Layout(gtx, nil)
c := r.Stop()
gtx.Constraints.Min = dims.Size
{
state := l.animation.Update(gtx)
if state.Active {
defer animation.TransformRotate(gtx, state.Value).Push(gtx.Ops).Pop()
}
}
c.Add(gtx.Ops)
return dims
}
type LoadState struct {
status string
err error
window *app.Window
loaded bool
logoSplash *LogoSplash
}
func NewLoadState(window *app.Window) *LoadState {
logoSplash := NewLogoSplash()
return &LoadState{
logoSplash: logoSplash,
window: window,
}
}
func (l *LoadState) Complete() {
l.loaded = true
l.window.Invalidate()
time.Sleep(50 * time.Millisecond)
}
func (l *LoadState) SetStatus(status string, err error) {
if err != nil {
l.err = err
} else {
l.status = status
}
l.window.Invalidate()
time.Sleep(50 * time.Millisecond)
}
func (l *LoadState) Layout(gtx layout.Context, th *material.Theme) layout.Dimensions {
layout.Center.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
gtx.Constraints.Min.X = gtx.Constraints.Max.X
return layout.UniformInset(unit.Dp(30)).Layout(gtx, func(gtx layout.Context) layout.Dimensions {
if l.err != nil {
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
lbl := material.Label(th, unit.Sp(20), l.status)
lbl.Font.Weight = font.Bold
return lbl.Layout(gtx)
}),
layout.Rigid(layout.Spacer{Height: unit.Dp(5)}.Layout),
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
lbl := material.Label(th, unit.Sp(16), l.err.Error())
return lbl.Layout(gtx)
}),
)
} else {
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
return layout.Center.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
gtx.Constraints.Max.X = gtx.Dp(100)
gtx.Constraints.Max.Y = gtx.Dp(100)
return l.logoSplash.Layout(gtx)
})
}),
layout.Rigid(layout.Spacer{Height: unit.Dp(20)}.Layout),
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
return layout.Center.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
lbl := material.Label(th, unit.Sp(20), l.status)
lbl.Font.Weight = font.Bold
return lbl.Layout(gtx)
})
}),
)
}
})
})
layout.S.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
lbl := material.Label(th, unit.Sp(14), settings.Version)
lbl.Font.Weight = font.Bold
lbl.Alignment = text.Middle
lbl.Color = theme.Current.TextMuteColor
return lbl.Layout(gtx)
}),
layout.Rigid(layout.Spacer{Height: unit.Dp(15)}.Layout),
)
})
return layout.Dimensions{}
}