-
Notifications
You must be signed in to change notification settings - Fork 3
/
opacity_gauge.go
80 lines (68 loc) 路 1.7 KB
/
opacity_gauge.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
package ui
import (
"github.com/solidiquis/alacpretty/internal/yamlconf"
ui "github.com/gizak/termui/v3"
"github.com/gizak/termui/v3/widgets"
)
type OpacityGauge struct {
// public
Widget *widgets.Gauge
// private
x1, y1, x2, y2 int
yamlConfig *string
}
func NewOpacityGauge(x1, y1, x2, y2 int) *OpacityGauge {
return &OpacityGauge{
Widget: widgets.NewGauge(),
x1: x1,
y1: y1,
x2: x2,
y2: y2,
}
}
func (og *OpacityGauge) GetWidget() ui.Drawable {
var widget ui.Drawable = og.Widget
return widget
}
func (og *OpacityGauge) ToggleActive() {
if fgColor := og.Widget.BorderStyle.Fg; fgColor == ui.ColorYellow {
og.Widget.BorderStyle.Fg = ui.ColorWhite
} else {
og.Widget.BorderStyle.Fg = ui.ColorYellow
}
ui.Render(og.Widget)
}
func (og *OpacityGauge) InitWidget(fileContent *string) {
og.yamlConfig = fileContent
og.Widget.Title = "Opacity"
og.Widget.SetRect(og.x1, og.y1, og.x2, og.y2)
og.Widget.Percent = int(yamlconf.CurrentOpacity(fileContent) * 100)
og.Widget.BarColor = ui.ColorYellow
og.Widget.LabelStyle = ui.NewStyle(ui.ColorBlue)
og.Widget.BorderStyle.Fg = ui.ColorWhite
}
func (og *OpacityGauge) SetState() string {
for {
uiEvents := ui.PollEvents()
e := <-uiEvents
var newOpacity float64
var tmp int
switch e.ID {
case "<C-c>", "q", "H", "J", "K", "L":
return e.ID
case "l", "<Left>":
tmp = og.Widget.Percent + 10
case "h", "<Right>":
tmp = og.Widget.Percent - 10
default:
tmp = 1925 // Cthulhu Fhtagn
}
if tmp >= 0 && tmp <= 100 {
newOpacity = float64(tmp) / 100
og.Widget.Percent = tmp
yamlconf.ChangeOpacity(og.yamlConfig, newOpacity)
yamlconf.ApplyChanges(*(og.yamlConfig))
ui.Render(og.Widget)
}
}
}