-
Notifications
You must be signed in to change notification settings - Fork 0
/
statusbar.go
63 lines (52 loc) · 1.44 KB
/
statusbar.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
package main
import (
"fmt"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/data/binding"
"fyne.io/fyne/v2/widget"
memory "github.com/BieHDC/fic/memquery"
)
type Statusbar struct {
statusbar binding.String
currentfilename binding.String
xoutofy binding.String
memusage binding.String
}
func (v *Viewer) setFileNumber(cf, sum int) {
v.xoutofy.Set(fmt.Sprintf("(%d/%d)", cf+1, sum))
}
func (v *Viewer) setStatus(s string) {
v.statusbar.Set(s)
}
func (v *Viewer) refreshMemoryUsage() uint {
mi := memory.GetMemInfo()
if mi == nil {
v.memusage.Set("Failed to get Memory Info")
return 0
}
rampc := (float64(mi.MemoryTotal-mi.MemoryFree) / float64(mi.MemoryTotal)) * 100
swappc := (float64(mi.SwapTotal-mi.SwapFree) / float64(mi.SwapTotal)) * 100
v.memusage.Set(fmt.Sprintf("Ram%%: %0.0f | Swap%%: %0.0f", rampc, swappc))
return uint(rampc)
}
func (v *Viewer) makeStatusbar() fyne.CanvasObject {
v.currentfilename = binding.NewString()
v.currentfilename.Set("None Selected")
v.xoutofy = binding.NewString()
v.xoutofy.Set("0/0")
v.memusage = binding.NewString()
v.refreshMemoryUsage()
v.statusbar = binding.NewString()
v.statusbar.Set("Ready")
return container.NewBorder(
nil,
nil,
container.NewHBox(
widget.NewLabelWithData(v.xoutofy),
widget.NewLabelWithData(v.currentfilename),
),
widget.NewLabelWithData(v.memusage),
container.NewHScroll(widget.NewLabelWithData(v.statusbar)),
)
}