-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom.go
88 lines (72 loc) · 1.95 KB
/
custom.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
package main
import (
"image/color"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"
// "fyne.io/fyne/v2/driver/desktop"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
// "math"
"time"
)
type CircularProgress struct {
widget.BaseWidget
progress float64
running bool
}
func NewCircularProgress() *CircularProgress {
c := &CircularProgress{}
c.ExtendBaseWidget(c)
return c
}
func (c *CircularProgress) CreateRenderer() fyne.WidgetRenderer {
circle := canvas.NewCircle(theme.PrimaryColor())
circle.StrokeWidth = 5
circle.StrokeColor = theme.PrimaryColor()
return &circularProgressRenderer{circle: circle, progress: c}
}
func (c *CircularProgress) Start() {
c.running = true
go func() {
for c.running {
c.progress += 0.01
if c.progress > 1 {
c.progress = 0
}
c.Refresh()
time.Sleep(50 * time.Millisecond)
}
}()
}
func (c *CircularProgress) Stop() {
c.running = false
}
type circularProgressRenderer struct {
circle *canvas.Circle
progress *CircularProgress
}
func (r *circularProgressRenderer) Layout(size fyne.Size) {
r.circle.Resize(size)
r.circle.Move(fyne.NewPos(0, 0))
}
func (r *circularProgressRenderer) MinSize() fyne.Size {
return fyne.NewSize(50, 50)
}
func (r *circularProgressRenderer) Refresh() {
_ = 360 * r.progress.progress
r.circle.StrokeWidth = 5
r.circle.StrokeColor = theme.PrimaryColor()
r.circle.FillColor = theme.BackgroundColor()
r.circle.Refresh()
r.circle.StrokeWidth = 5
r.circle.StrokeColor = theme.PrimaryColor()
r.circle.FillColor = theme.BackgroundColor()
r.circle.Refresh()
}
func (r *circularProgressRenderer) BackgroundColor() color.Color {
return theme.BackgroundColor()
}
func (r *circularProgressRenderer) Objects() []fyne.CanvasObject {
return []fyne.CanvasObject{r.circle}
}
func (r *circularProgressRenderer) Destroy() {}