github.com/wtfutil/wtf@v0.43.0/modules/clocks/widget.go (about) 1 package clocks 2 3 import ( 4 "github.com/rivo/tview" 5 "github.com/wtfutil/wtf/view" 6 ) 7 8 type Widget struct { 9 view.TextWidget 10 11 clockColl ClockCollection 12 dateFormat string 13 timeFormat string 14 settings *Settings 15 } 16 17 func NewWidget(tviewApp *tview.Application, redrawChan chan bool, settings *Settings) *Widget { 18 widget := Widget{ 19 TextWidget: view.NewTextWidget(tviewApp, redrawChan, nil, settings.Common), 20 21 settings: settings, 22 dateFormat: settings.dateFormat, 23 timeFormat: settings.timeFormat, 24 } 25 26 widget.clockColl = widget.buildClockCollection() 27 28 return &widget 29 } 30 31 /* -------------------- Exported Functions -------------------- */ 32 33 // Refresh updates the onscreen contents of the widget 34 func (widget *Widget) Refresh() { 35 sortedClocks := widget.clockColl.Sorted(widget.settings.sort) 36 widget.display(sortedClocks, widget.dateFormat, widget.timeFormat) 37 } 38 39 /* -------------------- Unexported Functions -------------------- */ 40 41 func (widget *Widget) buildClockCollection() ClockCollection { 42 clockColl := ClockCollection{} 43 44 clockColl.Clocks = widget.settings.locations 45 46 return clockColl 47 }