1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Rename addView() to createView()

This commit is contained in:
Chris Cummer 2019-08-04 23:21:46 -07:00
parent 787d1a3ba9
commit d372e1029f
2 changed files with 9 additions and 9 deletions

View File

@ -10,7 +10,7 @@ import (
"github.com/wtfutil/wtf/wtf" "github.com/wtfutil/wtf/wtf"
) )
//BarGraph lets make graphs //BarGraph defines the data required to make a bar graph
type BarGraph struct { type BarGraph struct {
maxStars int maxStars int
starChar string starChar string
@ -19,13 +19,14 @@ type BarGraph struct {
View *tview.TextView View *tview.TextView
} }
// Bar defines a single row in the bar graph
type Bar struct { type Bar struct {
Label string Label string
Percent int Percent int
ValueLabel string ValueLabel string
} }
// NewBarGraph initialize your fancy new graph // NewBarGraph creates and returns an instance of BarGraph
func NewBarGraph(app *tview.Application, name string, commonSettings *cfg.Common, focusable bool) BarGraph { func NewBarGraph(app *tview.Application, name string, commonSettings *cfg.Common, focusable bool) BarGraph {
widget := BarGraph{ widget := BarGraph{
Base: NewBase(app, commonSettings, focusable), Base: NewBase(app, commonSettings, focusable),
@ -34,7 +35,7 @@ func NewBarGraph(app *tview.Application, name string, commonSettings *cfg.Common
starChar: commonSettings.Config.UString("graphIcon", "|"), starChar: commonSettings.Config.UString("graphIcon", "|"),
} }
widget.View = widget.addView(widget.bordered) widget.View = widget.createView(widget.bordered)
return widget return widget
} }
@ -56,11 +57,9 @@ func BuildStars(data []Bar, maxStars int, starChar string) string {
//just getting min and max values //just getting min and max values
for _, bar := range data { for _, bar := range data {
if len(bar.Label) > longestLabel { if len(bar.Label) > longestLabel {
longestLabel = len(bar.Label) longestLabel = len(bar.Label)
} }
} }
// each number = how many stars? // each number = how many stars?
@ -68,7 +67,6 @@ func BuildStars(data []Bar, maxStars int, starChar string) string {
//build the stars //build the stars
for _, bar := range data { for _, bar := range data {
//how many stars for this one? //how many stars for this one?
var starCount = int(float64(bar.Percent) * starRatio) var starCount = int(float64(bar.Percent) * starRatio)
@ -99,7 +97,7 @@ func (widget *BarGraph) TextView() *tview.TextView {
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */
func (widget *BarGraph) addView(bordered bool) *tview.TextView { func (widget *BarGraph) createView(bordered bool) *tview.TextView {
view := tview.NewTextView() view := tview.NewTextView()
view.SetBackgroundColor(wtf.ColorFor(widget.commonSettings.Colors.Background)) view.SetBackgroundColor(wtf.ColorFor(widget.commonSettings.Colors.Background))

View File

@ -6,17 +6,19 @@ import (
"github.com/wtfutil/wtf/wtf" "github.com/wtfutil/wtf/wtf"
) )
// TextWidget defines the data necessary to make a text widget
type TextWidget struct { type TextWidget struct {
Base Base
View *tview.TextView View *tview.TextView
} }
// NewTextWidget creates and returns an instance of TextWidget
func NewTextWidget(app *tview.Application, commonSettings *cfg.Common, focusable bool) TextWidget { func NewTextWidget(app *tview.Application, commonSettings *cfg.Common, focusable bool) TextWidget {
widget := TextWidget{ widget := TextWidget{
Base: NewBase(app, commonSettings, focusable), Base: NewBase(app, commonSettings, focusable),
} }
widget.View = widget.addView(widget.bordered) widget.View = widget.createView(widget.bordered)
return widget return widget
} }
@ -38,7 +40,7 @@ func (widget *TextWidget) Redraw(title, text string, wrap bool) {
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */
func (widget *TextWidget) addView(bordered bool) *tview.TextView { func (widget *TextWidget) createView(bordered bool) *tview.TextView {
view := tview.NewTextView() view := tview.NewTextView()
view.SetBackgroundColor(wtf.ColorFor(widget.commonSettings.Colors.Background)) view.SetBackgroundColor(wtf.ColorFor(widget.commonSettings.Colors.Background))