forked from wtfutil/wtf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay.go
67 lines (54 loc) · 1.36 KB
/
display.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
package app
import (
"github.com/olebedev/config"
"github.com/rivo/tview"
"github.com/wtfutil/wtf/utils"
"github.com/wtfutil/wtf/wtf"
)
// Display is the container for the onscreen representation of a WtfApp
type Display struct {
Grid *tview.Grid
config *config.Config
}
// NewDisplay creates and returns a Display
func NewDisplay(widgets []wtf.Wtfable, config *config.Config) *Display {
display := Display{
Grid: tview.NewGrid(),
config: config,
}
firstWidget := widgets[0]
display.Grid.SetBackgroundColor(
wtf.ColorFor(
firstWidget.CommonSettings().Colors.WidgetTheme.Background,
),
)
display.build(widgets)
return &display
}
/* -------------------- Unexported Functions -------------------- */
func (display *Display) add(widget wtf.Wtfable) {
if widget.Disabled() {
return
}
display.Grid.AddItem(
widget.TextView(),
widget.CommonSettings().Top,
widget.CommonSettings().Left,
widget.CommonSettings().Height,
widget.CommonSettings().Width,
0,
0,
false,
)
}
func (display *Display) build(widgets []wtf.Wtfable) *tview.Grid {
cols := utils.ToInts(display.config.UList("wtf.grid.columns"))
rows := utils.ToInts(display.config.UList("wtf.grid.rows"))
display.Grid.SetColumns(cols...)
display.Grid.SetRows(rows...)
display.Grid.SetBorder(false)
for _, widget := range widgets {
display.add(widget)
}
return display.Grid
}