-
Notifications
You must be signed in to change notification settings - Fork 1
/
progress_linux.go
68 lines (55 loc) · 1.3 KB
/
progress_linux.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
package goey
import (
"unsafe"
"bitbucket.org/rj/goey/base"
"github.com/gotk3/gotk3/gtk"
)
type progressElement struct {
Control
min, max int
}
func (w *Progress) mount(parent base.Control) (base.Element, error) {
control, err := gtk.ProgressBarNew()
if err != nil {
return nil, err
}
parent.Handle.Add(control)
control.SetFraction(float64(w.Value-w.Min) / float64(w.Max-w.Min))
retval := &progressElement{
Control: Control{&control.Widget},
min: w.Min,
max: w.Max,
}
control.Connect("destroy", progressOnDestroy, retval)
control.Show()
return retval, nil
}
func progressOnDestroy(widget *gtk.ProgressBar, mounted *progressElement) {
mounted.handle = nil
}
func (w *progressElement) progressbar() *gtk.ProgressBar {
return (*gtk.ProgressBar)(unsafe.Pointer(w.handle))
}
func (w *progressElement) Props() base.Widget {
if w.min == w.max {
return &Progress{
Value: w.min,
Min: w.min,
Max: w.max,
}
}
pb := w.progressbar()
value := pb.GetFraction()
return &Progress{
Value: w.min + int(float64(w.max-w.min)*value),
Min: w.min,
Max: w.max,
}
}
func (w *progressElement) updateProps(data *Progress) error {
pb := w.progressbar()
w.min = data.Min
w.max = data.Max
pb.SetFraction(float64(data.Value-data.Min) / float64(data.Max-data.Min))
return nil
}