github.com/wtfutil/wtf@v0.43.0/app/display.go (about) 1 package app 2 3 import ( 4 "github.com/olebedev/config" 5 "github.com/rivo/tview" 6 "github.com/wtfutil/wtf/utils" 7 "github.com/wtfutil/wtf/wtf" 8 ) 9 10 // Display is the container for the onscreen representation of a WtfApp 11 type Display struct { 12 Grid *tview.Grid 13 config *config.Config 14 } 15 16 // NewDisplay creates and returns a Display 17 func NewDisplay(widgets []wtf.Wtfable, config *config.Config) *Display { 18 display := Display{ 19 Grid: tview.NewGrid(), 20 config: config, 21 } 22 23 firstWidget := widgets[0] 24 display.Grid.SetBackgroundColor( 25 wtf.ColorFor( 26 firstWidget.CommonSettings().Colors.WidgetTheme.Background, 27 ), 28 ) 29 30 display.build(widgets) 31 32 return &display 33 } 34 35 /* -------------------- Unexported Functions -------------------- */ 36 37 func (display *Display) add(widget wtf.Wtfable) { 38 if widget.Disabled() { 39 return 40 } 41 42 display.Grid.AddItem( 43 widget.TextView(), 44 widget.CommonSettings().Top, 45 widget.CommonSettings().Left, 46 widget.CommonSettings().Height, 47 widget.CommonSettings().Width, 48 0, 49 0, 50 false, 51 ) 52 } 53 54 func (display *Display) build(widgets []wtf.Wtfable) *tview.Grid { 55 cols := utils.ToInts(display.config.UList("wtf.grid.columns")) 56 rows := utils.ToInts(display.config.UList("wtf.grid.rows")) 57 58 display.Grid.SetColumns(cols...) 59 display.Grid.SetRows(rows...) 60 display.Grid.SetBorder(false) 61 62 for _, widget := range widgets { 63 display.add(widget) 64 } 65 66 return display.Grid 67 }