Change various widget field names

This commit is contained in:
Caleb Bassi 2019-02-23 17:15:42 -08:00
parent fd5a830d7a
commit 3006e4efe4
12 changed files with 89 additions and 89 deletions

View File

@ -10,8 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Change various widget field names
- s/TextParse/ParseStyles
- Removed AddColorMap in place of modifying StyleParserColorMap directly
- Remove AddColorMap in place of modifying StyleParserColorMap directly
## 2019/01/31

View File

@ -36,8 +36,8 @@ func main() {
pc.Title = "Pie Chart"
pc.SetRect(5, 5, 70, 36)
pc.Data = []float64{.25, .25, .25, .25}
pc.Offset = -.5 * math.Pi
pc.Label = func(i int, v float64) string {
pc.AngleOffset = -.5 * math.Pi
pc.LabelFormatter = func(i int, v float64) string {
return fmt.Sprintf("%.02f", v)
}
@ -66,7 +66,7 @@ func main() {
}
case <-ticker:
if run {
pc.Data, pc.Offset = randomDataAndOffset()
pc.Data, pc.AngleOffset = randomDataAndOffset()
ui.Render(pc)
}
}

View File

@ -44,7 +44,7 @@ func main() {
p1.Marker = widgets.MarkerDot
p1.Data = [][]float64{[]float64{1, 2, 3, 4, 5}}
p1.SetRect(50, 0, 75, 10)
p1.DotRune = '+'
p1.DotMarkerRune = '+'
p1.AxesColor = ui.ColorWhite
p1.LineColors[0] = ui.ColorYellow
p1.DrawDirection = widgets.DrawLeft
@ -58,7 +58,7 @@ func main() {
p2.SetRect(0, 15, 50, 30)
p2.AxesColor = ui.ColorWhite
p2.LineColors[0] = ui.ColorCyan
p2.Type = widgets.ScatterPlot
p2.PlotType = widgets.ScatterPlot
p3 := widgets.NewPlot()
p3.Title = "braille-mode Scatter Plot"
@ -69,7 +69,7 @@ func main() {
p3.AxesColor = ui.ColorWhite
p3.LineColors[0] = ui.ColorCyan
p3.Marker = widgets.MarkerBraille
p3.Type = widgets.ScatterPlot
p3.PlotType = widgets.ScatterPlot
ui.Render(p0, p1, p2, p3)

View File

@ -37,7 +37,7 @@ func main() {
[]string{"2016", "11", "11"},
}
table2.TextStyle = ui.NewStyle(ui.ColorWhite)
table2.TextAlign = ui.AlignCenter
table2.TextAlignment = ui.AlignCenter
table2.RowSeparator = false
table2.SetRect(0, 10, 20, 20)

View File

@ -15,26 +15,26 @@ import (
type BarChart struct {
Block
BarColors []Color
LabelStyles []Style
NumStyles []Style // only Fg and Modifier are used
NumFmt func(float64) string
Data []float64
Labels []string
BarWidth int
BarGap int
MaxVal float64
BarColors []Color
LabelStyles []Style
NumStyles []Style // only Fg and Modifier are used
NumFormatter func(float64) string
Data []float64
Labels []string
BarWidth int
BarGap int
MaxVal float64
}
func NewBarChart() *BarChart {
return &BarChart{
Block: *NewBlock(),
BarColors: Theme.BarChart.Bars,
NumStyles: Theme.BarChart.Nums,
LabelStyles: Theme.BarChart.Labels,
NumFmt: func(n float64) string { return fmt.Sprint(n) },
BarGap: 1,
BarWidth: 3,
Block: *NewBlock(),
BarColors: Theme.BarChart.Bars,
NumStyles: Theme.BarChart.Nums,
LabelStyles: Theme.BarChart.Labels,
NumFormatter: func(n float64) string { return fmt.Sprint(n) },
BarGap: 1,
BarWidth: 3,
}
}
@ -74,7 +74,7 @@ func (self *BarChart) Draw(buf *Buffer) {
numberXCoordinate := barXCoordinate + int((float64(self.BarWidth) / 2))
if numberXCoordinate <= self.Inner.Max.X {
buf.SetString(
self.NumFmt(data),
self.NumFormatter(data),
NewStyle(
SelectStyle(self.NumStyles, i+1).Fg,
SelectColor(self.BarColors, i),

View File

@ -135,12 +135,11 @@ func (self colorAverager) add(col color.Color) colorAverager {
func (self colorAverager) RGBA() (uint32, uint32, uint32, uint32) {
if self.count == 0 {
return 0, 0, 0, 0
} else {
return uint32(self.rsum/self.count) & 0xffff,
uint32(self.gsum/self.count) & 0xffff,
uint32(self.bsum/self.count) & 0xffff,
uint32(self.asum/self.count) & 0xffff
}
return uint32(self.rsum/self.count) & 0xffff,
uint32(self.gsum/self.count) & 0xffff,
uint32(self.bsum/self.count) & 0xffff,
uint32(self.asum/self.count) & 0xffff
}
func (self colorAverager) fgColor() Color {

View File

@ -17,8 +17,8 @@ type List struct {
Rows []string
WrapText bool
TextStyle Style
SelectedRow uint
topRow uint
SelectedRow int
topRow int
SelectedRowStyle Style
}
@ -35,13 +35,13 @@ func (self *List) Draw(buf *Buffer) {
point := self.Inner.Min
if self.SelectedRow >= uint(self.Inner.Max.Y)+self.topRow-2 {
self.topRow = self.SelectedRow - uint(self.Inner.Max.Y) + 2
if self.SelectedRow >= self.Inner.Max.Y+self.topRow-2 {
self.topRow = self.SelectedRow - self.Inner.Max.Y + 2
} else if self.SelectedRow < self.topRow {
self.topRow = self.SelectedRow
}
for row := self.topRow; row < uint(len(self.Rows)) && point.Y < self.Inner.Max.Y; row++ {
for row := self.topRow; row < len(self.Rows) && point.Y < self.Inner.Max.Y; row++ {
cells := ParseStyles(self.Rows[row], self.TextStyle)
if self.WrapText {
cells = WrapCells(cells, uint(self.Inner.Dx()))
@ -85,11 +85,11 @@ func (self *List) Draw(buf *Buffer) {
// since if the selected item is off screen then the topRow variable will change accordingly.
func (self *List) ScrollAmount(amount int) {
if len(self.Rows)-int(self.SelectedRow) <= amount {
self.SelectedRow = uint(len(self.Rows) - 1)
self.SelectedRow = len(self.Rows) - 1
} else if int(self.SelectedRow)+amount < 0 {
self.SelectedRow = 0
} else {
self.SelectedRow += uint(amount)
self.SelectedRow += amount
}
}
@ -129,5 +129,5 @@ func (self *List) ScrollTop() {
}
func (self *List) ScrollBottom() {
self.SelectedRow = uint(len(self.Rows) - 1)
self.SelectedRow = len(self.Rows) - 1
}

View File

@ -19,18 +19,18 @@ type PieChartLabel func(dataIndex int, currentValue float64) string
type PieChart struct {
Block
Data []float64 // list of data items
Colors []Color // colors to by cycled through
Label PieChartLabel // callback function for labels
Offset float64 // which angle to start drawing at? (see piechartOffsetUp)
Data []float64 // list of data items
Colors []Color // colors to by cycled through
LabelFormatter PieChartLabel // callback function for labels
AngleOffset float64 // which angle to start drawing at? (see piechartOffsetUp)
}
// NewPieChart Creates a new pie chart with reasonable defaults and no labels.
func NewPieChart() *PieChart {
return &PieChart{
Block: *NewBlock(),
Colors: Theme.PieChart.Slices,
Offset: piechartOffsetUp,
Block: *NewBlock(),
Colors: Theme.PieChart.Slices,
AngleOffset: piechartOffsetUp,
}
}
@ -51,7 +51,7 @@ func (self *PieChart) Draw(buf *Buffer) {
middleCircle := circle{Point: center, radius: radius / 2.0}
// draw sectors
phi := self.Offset
phi := self.AngleOffset
for i, size := range sliceSizes {
for j := 0.0; j < size; j += resolutionFactor {
borderPoint := borderCircle.at(phi + j)
@ -62,15 +62,15 @@ func (self *PieChart) Draw(buf *Buffer) {
}
// draw labels
if self.Label != nil {
phi = self.Offset
if self.LabelFormatter != nil {
phi = self.AngleOffset
for i, size := range sliceSizes {
labelPoint := middleCircle.at(phi + size/2.0)
if len(self.Data) == 1 {
labelPoint = center
}
buf.SetString(
self.Label(i, self.Data[i]),
self.LabelFormatter(i, self.Data[i]),
NewStyle(SelectColor(self.Colors, i)),
image.Pt(labelPoint.X, labelPoint.Y),
)

View File

@ -27,8 +27,8 @@ type Plot struct {
ShowAxes bool
Marker PlotMarker
DotRune rune
Type PlotType
DotMarkerRune rune
PlotType PlotType
HorizontalScale int
DrawDirection DrawDirection // TODO
}
@ -67,12 +67,12 @@ func NewPlot() *Plot {
LineColors: Theme.Plot.Lines,
AxesColor: Theme.Plot.Axes,
Marker: MarkerBraille,
DotRune: DOT,
DotMarkerRune: DOT,
Data: [][]float64{},
HorizontalScale: 1,
DrawDirection: DrawRight,
ShowAxes: true,
Type: LineChart,
PlotType: LineChart,
}
}
@ -80,7 +80,7 @@ func (self *Plot) renderBraille(buf *Buffer, drawArea image.Rectangle, maxVal fl
canvas := NewCanvas()
canvas.Rectangle = drawArea
switch self.Type {
switch self.PlotType {
case ScatterPlot:
for i, line := range self.Data {
for j, val := range line {
@ -119,7 +119,7 @@ func (self *Plot) renderBraille(buf *Buffer, drawArea image.Rectangle, maxVal fl
}
func (self *Plot) renderDot(buf *Buffer, drawArea image.Rectangle, maxVal float64) {
switch self.Type {
switch self.PlotType {
case ScatterPlot:
for i, line := range self.Data {
for j, val := range line {
@ -127,7 +127,7 @@ func (self *Plot) renderDot(buf *Buffer, drawArea image.Rectangle, maxVal float6
point := image.Pt(drawArea.Min.X+(j*self.HorizontalScale), drawArea.Max.Y-1-height)
if point.In(drawArea) {
buf.SetCell(
NewCell(self.DotRune, NewStyle(SelectColor(self.LineColors, i))),
NewCell(self.DotMarkerRune, NewStyle(SelectColor(self.LineColors, i))),
point,
)
}
@ -139,7 +139,7 @@ func (self *Plot) renderDot(buf *Buffer, drawArea image.Rectangle, maxVal float6
val := line[j]
height := int((val / maxVal) * float64(drawArea.Dy()-1))
buf.SetCell(
NewCell(self.DotRune, NewStyle(SelectColor(self.LineColors, i))),
NewCell(self.DotMarkerRune, NewStyle(SelectColor(self.LineColors, i))),
image.Pt(drawArea.Min.X+(j*self.HorizontalScale), drawArea.Max.Y-1-height),
)
}

View File

@ -15,26 +15,26 @@ import (
type StackedBarChart struct {
Block
BarColors []Color
LabelStyles []Style
NumStyles []Style // only Fg and Modifier are used
NumFmt func(float64) string
Data [][]float64
Labels []string
BarWidth int
BarGap int
MaxVal float64
BarColors []Color
LabelStyles []Style
NumStyles []Style // only Fg and Modifier are used
NumFormatter func(float64) string
Data [][]float64
Labels []string
BarWidth int
BarGap int
MaxVal float64
}
func NewStackedBarChart() *StackedBarChart {
return &StackedBarChart{
Block: *NewBlock(),
BarColors: Theme.StackedBarChart.Bars,
LabelStyles: Theme.StackedBarChart.Labels,
NumStyles: Theme.StackedBarChart.Nums,
NumFmt: func(n float64) string { return fmt.Sprint(n) },
BarGap: 1,
BarWidth: 3,
Block: *NewBlock(),
BarColors: Theme.StackedBarChart.Bars,
LabelStyles: Theme.StackedBarChart.Labels,
NumStyles: Theme.StackedBarChart.Nums,
NumFormatter: func(n float64) string { return fmt.Sprint(n) },
BarGap: 1,
BarWidth: 3,
}
}
@ -66,7 +66,7 @@ func (self *StackedBarChart) Draw(buf *Buffer) {
// draw number
numberXCoordinate := barXCoordinate + int((float64(self.BarWidth) / 2)) - 1
buf.SetString(
self.NumFmt(data),
self.NumFormatter(data),
NewStyle(
SelectStyle(self.NumStyles, j+1).Fg,
SelectColor(self.BarColors, j),

View File

@ -21,13 +21,13 @@ import (
*/
type Table struct {
Block
Rows [][]string
ColumnWidths []int
TextStyle Style
RowSeparator bool
TextAlign Alignment
RowStyles map[int]Style
FillRow bool
Rows [][]string
ColumnWidths []int
TextStyle Style
RowSeparator bool
TextAlignment Alignment
RowStyles map[int]Style
FillRow bool
}
func NewTable() *Table {
@ -45,9 +45,9 @@ func (self *Table) Draw(buf *Buffer) {
columnWidths := self.ColumnWidths
if len(columnWidths) == 0 {
columnCount := len(self.Rows[0])
colWidth := self.Inner.Dx() / columnCount
columnWidth := self.Inner.Dx() / columnCount
for i := 0; i < columnCount; i++ {
columnWidths = append(columnWidths, colWidth)
columnWidths = append(columnWidths, columnWidth)
}
}
@ -73,7 +73,7 @@ func (self *Table) Draw(buf *Buffer) {
for j := 0; j < len(row); j++ {
col := ParseStyles(row[j], rowStyle)
// draw row cell
if len(col) > columnWidths[j] || self.TextAlign == AlignLeft {
if len(col) > columnWidths[j] || self.TextAlignment == AlignLeft {
for _, cx := range BuildCellWithXArray(col) {
k, cell := cx.X, cx.Cell
if k == columnWidths[j] || colXCoordinate+k == self.Inner.Max.X {
@ -84,14 +84,14 @@ func (self *Table) Draw(buf *Buffer) {
buf.SetCell(cell, image.Pt(colXCoordinate+k, yCoordinate))
}
}
} else if self.TextAlign == AlignCenter {
} else if self.TextAlignment == AlignCenter {
xCoordinateOffset := (columnWidths[j] - len(col)) / 2
stringXCoordinate := xCoordinateOffset + colXCoordinate
for _, cx := range BuildCellWithXArray(col) {
k, cell := cx.X, cx.Cell
buf.SetCell(cell, image.Pt(stringXCoordinate+k, yCoordinate))
}
} else if self.TextAlign == AlignRight {
} else if self.TextAlignment == AlignRight {
stringXCoordinate := MinInt(colXCoordinate+columnWidths[j], self.Inner.Max.X) - len(col)
for _, cx := range BuildCellWithXArray(col) {
k, cell := cx.X, cx.Cell

View File

@ -16,7 +16,7 @@ import (
type TabPane struct {
Block
TabNames []string
ActiveTabIndex uint
ActiveTabIndex int
ActiveTabStyle Style
InactiveTabStyle Style
}
@ -37,7 +37,7 @@ func (self *TabPane) FocusLeft() {
}
func (self *TabPane) FocusRight() {
if self.ActiveTabIndex < uint(len(self.TabNames)-1) {
if self.ActiveTabIndex < len(self.TabNames)-1 {
self.ActiveTabIndex++
}
}
@ -48,7 +48,7 @@ func (self *TabPane) Draw(buf *Buffer) {
xCoordinate := self.Inner.Min.X
for i, name := range self.TabNames {
ColorPair := self.InactiveTabStyle
if uint(i) == self.ActiveTabIndex {
if i == self.ActiveTabIndex {
ColorPair = self.ActiveTabStyle
}
buf.SetString(