Change various widget field names
This commit is contained in:
		
							parent
							
								
									fd5a830d7a
								
							
						
					
					
						commit
						3006e4efe4
					
				| @ -10,8 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |||||||
| 
 | 
 | ||||||
| ### Changed | ### Changed | ||||||
| 
 | 
 | ||||||
|  | - Change various widget field names | ||||||
| - s/TextParse/ParseStyles | - s/TextParse/ParseStyles | ||||||
| - Removed AddColorMap in place of modifying StyleParserColorMap directly | - Remove AddColorMap in place of modifying StyleParserColorMap directly | ||||||
| 
 | 
 | ||||||
| ## 2019/01/31 | ## 2019/01/31 | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -36,8 +36,8 @@ func main() { | |||||||
| 	pc.Title = "Pie Chart" | 	pc.Title = "Pie Chart" | ||||||
| 	pc.SetRect(5, 5, 70, 36) | 	pc.SetRect(5, 5, 70, 36) | ||||||
| 	pc.Data = []float64{.25, .25, .25, .25} | 	pc.Data = []float64{.25, .25, .25, .25} | ||||||
| 	pc.Offset = -.5 * math.Pi | 	pc.AngleOffset = -.5 * math.Pi | ||||||
| 	pc.Label = func(i int, v float64) string { | 	pc.LabelFormatter = func(i int, v float64) string { | ||||||
| 		return fmt.Sprintf("%.02f", v) | 		return fmt.Sprintf("%.02f", v) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| @ -66,7 +66,7 @@ func main() { | |||||||
| 			} | 			} | ||||||
| 		case <-ticker: | 		case <-ticker: | ||||||
| 			if run { | 			if run { | ||||||
| 				pc.Data, pc.Offset = randomDataAndOffset() | 				pc.Data, pc.AngleOffset = randomDataAndOffset() | ||||||
| 				ui.Render(pc) | 				ui.Render(pc) | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  | |||||||
| @ -44,7 +44,7 @@ func main() { | |||||||
| 	p1.Marker = widgets.MarkerDot | 	p1.Marker = widgets.MarkerDot | ||||||
| 	p1.Data = [][]float64{[]float64{1, 2, 3, 4, 5}} | 	p1.Data = [][]float64{[]float64{1, 2, 3, 4, 5}} | ||||||
| 	p1.SetRect(50, 0, 75, 10) | 	p1.SetRect(50, 0, 75, 10) | ||||||
| 	p1.DotRune = '+' | 	p1.DotMarkerRune = '+' | ||||||
| 	p1.AxesColor = ui.ColorWhite | 	p1.AxesColor = ui.ColorWhite | ||||||
| 	p1.LineColors[0] = ui.ColorYellow | 	p1.LineColors[0] = ui.ColorYellow | ||||||
| 	p1.DrawDirection = widgets.DrawLeft | 	p1.DrawDirection = widgets.DrawLeft | ||||||
| @ -58,7 +58,7 @@ func main() { | |||||||
| 	p2.SetRect(0, 15, 50, 30) | 	p2.SetRect(0, 15, 50, 30) | ||||||
| 	p2.AxesColor = ui.ColorWhite | 	p2.AxesColor = ui.ColorWhite | ||||||
| 	p2.LineColors[0] = ui.ColorCyan | 	p2.LineColors[0] = ui.ColorCyan | ||||||
| 	p2.Type = widgets.ScatterPlot | 	p2.PlotType = widgets.ScatterPlot | ||||||
| 
 | 
 | ||||||
| 	p3 := widgets.NewPlot() | 	p3 := widgets.NewPlot() | ||||||
| 	p3.Title = "braille-mode Scatter Plot" | 	p3.Title = "braille-mode Scatter Plot" | ||||||
| @ -69,7 +69,7 @@ func main() { | |||||||
| 	p3.AxesColor = ui.ColorWhite | 	p3.AxesColor = ui.ColorWhite | ||||||
| 	p3.LineColors[0] = ui.ColorCyan | 	p3.LineColors[0] = ui.ColorCyan | ||||||
| 	p3.Marker = widgets.MarkerBraille | 	p3.Marker = widgets.MarkerBraille | ||||||
| 	p3.Type = widgets.ScatterPlot | 	p3.PlotType = widgets.ScatterPlot | ||||||
| 
 | 
 | ||||||
| 	ui.Render(p0, p1, p2, p3) | 	ui.Render(p0, p1, p2, p3) | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -37,7 +37,7 @@ func main() { | |||||||
| 		[]string{"2016", "11", "11"}, | 		[]string{"2016", "11", "11"}, | ||||||
| 	} | 	} | ||||||
| 	table2.TextStyle = ui.NewStyle(ui.ColorWhite) | 	table2.TextStyle = ui.NewStyle(ui.ColorWhite) | ||||||
| 	table2.TextAlign = ui.AlignCenter | 	table2.TextAlignment = ui.AlignCenter | ||||||
| 	table2.RowSeparator = false | 	table2.RowSeparator = false | ||||||
| 	table2.SetRect(0, 10, 20, 20) | 	table2.SetRect(0, 10, 20, 20) | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -15,26 +15,26 @@ import ( | |||||||
| 
 | 
 | ||||||
| type BarChart struct { | type BarChart struct { | ||||||
| 	Block | 	Block | ||||||
| 	BarColors   []Color | 	BarColors    []Color | ||||||
| 	LabelStyles []Style | 	LabelStyles  []Style | ||||||
| 	NumStyles   []Style // only Fg and Modifier are used | 	NumStyles    []Style // only Fg and Modifier are used | ||||||
| 	NumFmt      func(float64) string | 	NumFormatter func(float64) string | ||||||
| 	Data        []float64 | 	Data         []float64 | ||||||
| 	Labels      []string | 	Labels       []string | ||||||
| 	BarWidth    int | 	BarWidth     int | ||||||
| 	BarGap      int | 	BarGap       int | ||||||
| 	MaxVal      float64 | 	MaxVal       float64 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func NewBarChart() *BarChart { | func NewBarChart() *BarChart { | ||||||
| 	return &BarChart{ | 	return &BarChart{ | ||||||
| 		Block:       *NewBlock(), | 		Block:        *NewBlock(), | ||||||
| 		BarColors:   Theme.BarChart.Bars, | 		BarColors:    Theme.BarChart.Bars, | ||||||
| 		NumStyles:   Theme.BarChart.Nums, | 		NumStyles:    Theme.BarChart.Nums, | ||||||
| 		LabelStyles: Theme.BarChart.Labels, | 		LabelStyles:  Theme.BarChart.Labels, | ||||||
| 		NumFmt:      func(n float64) string { return fmt.Sprint(n) }, | 		NumFormatter: func(n float64) string { return fmt.Sprint(n) }, | ||||||
| 		BarGap:      1, | 		BarGap:       1, | ||||||
| 		BarWidth:    3, | 		BarWidth:     3, | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -74,7 +74,7 @@ func (self *BarChart) Draw(buf *Buffer) { | |||||||
| 		numberXCoordinate := barXCoordinate + int((float64(self.BarWidth) / 2)) | 		numberXCoordinate := barXCoordinate + int((float64(self.BarWidth) / 2)) | ||||||
| 		if numberXCoordinate <= self.Inner.Max.X { | 		if numberXCoordinate <= self.Inner.Max.X { | ||||||
| 			buf.SetString( | 			buf.SetString( | ||||||
| 				self.NumFmt(data), | 				self.NumFormatter(data), | ||||||
| 				NewStyle( | 				NewStyle( | ||||||
| 					SelectStyle(self.NumStyles, i+1).Fg, | 					SelectStyle(self.NumStyles, i+1).Fg, | ||||||
| 					SelectColor(self.BarColors, i), | 					SelectColor(self.BarColors, i), | ||||||
|  | |||||||
| @ -135,12 +135,11 @@ func (self colorAverager) add(col color.Color) colorAverager { | |||||||
| func (self colorAverager) RGBA() (uint32, uint32, uint32, uint32) { | func (self colorAverager) RGBA() (uint32, uint32, uint32, uint32) { | ||||||
| 	if self.count == 0 { | 	if self.count == 0 { | ||||||
| 		return 0, 0, 0, 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 { | func (self colorAverager) fgColor() Color { | ||||||
|  | |||||||
| @ -17,8 +17,8 @@ type List struct { | |||||||
| 	Rows             []string | 	Rows             []string | ||||||
| 	WrapText         bool | 	WrapText         bool | ||||||
| 	TextStyle        Style | 	TextStyle        Style | ||||||
| 	SelectedRow      uint | 	SelectedRow      int | ||||||
| 	topRow           uint | 	topRow           int | ||||||
| 	SelectedRowStyle Style | 	SelectedRowStyle Style | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -35,13 +35,13 @@ func (self *List) Draw(buf *Buffer) { | |||||||
| 
 | 
 | ||||||
| 	point := self.Inner.Min | 	point := self.Inner.Min | ||||||
| 
 | 
 | ||||||
| 	if self.SelectedRow >= uint(self.Inner.Max.Y)+self.topRow-2 { | 	if self.SelectedRow >= self.Inner.Max.Y+self.topRow-2 { | ||||||
| 		self.topRow = self.SelectedRow - uint(self.Inner.Max.Y) + 2 | 		self.topRow = self.SelectedRow - self.Inner.Max.Y + 2 | ||||||
| 	} else if self.SelectedRow < self.topRow { | 	} else if self.SelectedRow < self.topRow { | ||||||
| 		self.topRow = self.SelectedRow | 		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) | 		cells := ParseStyles(self.Rows[row], self.TextStyle) | ||||||
| 		if self.WrapText { | 		if self.WrapText { | ||||||
| 			cells = WrapCells(cells, uint(self.Inner.Dx())) | 			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. | // since if the selected item is off screen then the topRow variable will change accordingly. | ||||||
| func (self *List) ScrollAmount(amount int) { | func (self *List) ScrollAmount(amount int) { | ||||||
| 	if len(self.Rows)-int(self.SelectedRow) <= amount { | 	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 { | 	} else if int(self.SelectedRow)+amount < 0 { | ||||||
| 		self.SelectedRow = 0 | 		self.SelectedRow = 0 | ||||||
| 	} else { | 	} else { | ||||||
| 		self.SelectedRow += uint(amount) | 		self.SelectedRow += amount | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -129,5 +129,5 @@ func (self *List) ScrollTop() { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (self *List) ScrollBottom() { | func (self *List) ScrollBottom() { | ||||||
| 	self.SelectedRow = uint(len(self.Rows) - 1) | 	self.SelectedRow = len(self.Rows) - 1 | ||||||
| } | } | ||||||
|  | |||||||
| @ -19,18 +19,18 @@ type PieChartLabel func(dataIndex int, currentValue float64) string | |||||||
| 
 | 
 | ||||||
| type PieChart struct { | type PieChart struct { | ||||||
| 	Block | 	Block | ||||||
| 	Data   []float64     // list of data items | 	Data           []float64     // list of data items | ||||||
| 	Colors []Color       // colors to by cycled through | 	Colors         []Color       // colors to by cycled through | ||||||
| 	Label  PieChartLabel // callback function for labels | 	LabelFormatter PieChartLabel // callback function for labels | ||||||
| 	Offset float64       // which angle to start drawing at? (see piechartOffsetUp) | 	AngleOffset    float64       // which angle to start drawing at? (see piechartOffsetUp) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // NewPieChart Creates a new pie chart with reasonable defaults and no labels. | // NewPieChart Creates a new pie chart with reasonable defaults and no labels. | ||||||
| func NewPieChart() *PieChart { | func NewPieChart() *PieChart { | ||||||
| 	return &PieChart{ | 	return &PieChart{ | ||||||
| 		Block:  *NewBlock(), | 		Block:       *NewBlock(), | ||||||
| 		Colors: Theme.PieChart.Slices, | 		Colors:      Theme.PieChart.Slices, | ||||||
| 		Offset: piechartOffsetUp, | 		AngleOffset: piechartOffsetUp, | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -51,7 +51,7 @@ func (self *PieChart) Draw(buf *Buffer) { | |||||||
| 	middleCircle := circle{Point: center, radius: radius / 2.0} | 	middleCircle := circle{Point: center, radius: radius / 2.0} | ||||||
| 
 | 
 | ||||||
| 	// draw sectors | 	// draw sectors | ||||||
| 	phi := self.Offset | 	phi := self.AngleOffset | ||||||
| 	for i, size := range sliceSizes { | 	for i, size := range sliceSizes { | ||||||
| 		for j := 0.0; j < size; j += resolutionFactor { | 		for j := 0.0; j < size; j += resolutionFactor { | ||||||
| 			borderPoint := borderCircle.at(phi + j) | 			borderPoint := borderCircle.at(phi + j) | ||||||
| @ -62,15 +62,15 @@ func (self *PieChart) Draw(buf *Buffer) { | |||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// draw labels | 	// draw labels | ||||||
| 	if self.Label != nil { | 	if self.LabelFormatter != nil { | ||||||
| 		phi = self.Offset | 		phi = self.AngleOffset | ||||||
| 		for i, size := range sliceSizes { | 		for i, size := range sliceSizes { | ||||||
| 			labelPoint := middleCircle.at(phi + size/2.0) | 			labelPoint := middleCircle.at(phi + size/2.0) | ||||||
| 			if len(self.Data) == 1 { | 			if len(self.Data) == 1 { | ||||||
| 				labelPoint = center | 				labelPoint = center | ||||||
| 			} | 			} | ||||||
| 			buf.SetString( | 			buf.SetString( | ||||||
| 				self.Label(i, self.Data[i]), | 				self.LabelFormatter(i, self.Data[i]), | ||||||
| 				NewStyle(SelectColor(self.Colors, i)), | 				NewStyle(SelectColor(self.Colors, i)), | ||||||
| 				image.Pt(labelPoint.X, labelPoint.Y), | 				image.Pt(labelPoint.X, labelPoint.Y), | ||||||
| 			) | 			) | ||||||
|  | |||||||
| @ -27,8 +27,8 @@ type Plot struct { | |||||||
| 	ShowAxes   bool | 	ShowAxes   bool | ||||||
| 
 | 
 | ||||||
| 	Marker          PlotMarker | 	Marker          PlotMarker | ||||||
| 	DotRune         rune | 	DotMarkerRune   rune | ||||||
| 	Type            PlotType | 	PlotType        PlotType | ||||||
| 	HorizontalScale int | 	HorizontalScale int | ||||||
| 	DrawDirection   DrawDirection // TODO | 	DrawDirection   DrawDirection // TODO | ||||||
| } | } | ||||||
| @ -67,12 +67,12 @@ func NewPlot() *Plot { | |||||||
| 		LineColors:      Theme.Plot.Lines, | 		LineColors:      Theme.Plot.Lines, | ||||||
| 		AxesColor:       Theme.Plot.Axes, | 		AxesColor:       Theme.Plot.Axes, | ||||||
| 		Marker:          MarkerBraille, | 		Marker:          MarkerBraille, | ||||||
| 		DotRune:         DOT, | 		DotMarkerRune:   DOT, | ||||||
| 		Data:            [][]float64{}, | 		Data:            [][]float64{}, | ||||||
| 		HorizontalScale: 1, | 		HorizontalScale: 1, | ||||||
| 		DrawDirection:   DrawRight, | 		DrawDirection:   DrawRight, | ||||||
| 		ShowAxes:        true, | 		ShowAxes:        true, | ||||||
| 		Type:            LineChart, | 		PlotType:        LineChart, | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -80,7 +80,7 @@ func (self *Plot) renderBraille(buf *Buffer, drawArea image.Rectangle, maxVal fl | |||||||
| 	canvas := NewCanvas() | 	canvas := NewCanvas() | ||||||
| 	canvas.Rectangle = drawArea | 	canvas.Rectangle = drawArea | ||||||
| 
 | 
 | ||||||
| 	switch self.Type { | 	switch self.PlotType { | ||||||
| 	case ScatterPlot: | 	case ScatterPlot: | ||||||
| 		for i, line := range self.Data { | 		for i, line := range self.Data { | ||||||
| 			for j, val := range line { | 			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) { | func (self *Plot) renderDot(buf *Buffer, drawArea image.Rectangle, maxVal float64) { | ||||||
| 	switch self.Type { | 	switch self.PlotType { | ||||||
| 	case ScatterPlot: | 	case ScatterPlot: | ||||||
| 		for i, line := range self.Data { | 		for i, line := range self.Data { | ||||||
| 			for j, val := range line { | 			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) | 				point := image.Pt(drawArea.Min.X+(j*self.HorizontalScale), drawArea.Max.Y-1-height) | ||||||
| 				if point.In(drawArea) { | 				if point.In(drawArea) { | ||||||
| 					buf.SetCell( | 					buf.SetCell( | ||||||
| 						NewCell(self.DotRune, NewStyle(SelectColor(self.LineColors, i))), | 						NewCell(self.DotMarkerRune, NewStyle(SelectColor(self.LineColors, i))), | ||||||
| 						point, | 						point, | ||||||
| 					) | 					) | ||||||
| 				} | 				} | ||||||
| @ -139,7 +139,7 @@ func (self *Plot) renderDot(buf *Buffer, drawArea image.Rectangle, maxVal float6 | |||||||
| 				val := line[j] | 				val := line[j] | ||||||
| 				height := int((val / maxVal) * float64(drawArea.Dy()-1)) | 				height := int((val / maxVal) * float64(drawArea.Dy()-1)) | ||||||
| 				buf.SetCell( | 				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), | 					image.Pt(drawArea.Min.X+(j*self.HorizontalScale), drawArea.Max.Y-1-height), | ||||||
| 				) | 				) | ||||||
| 			} | 			} | ||||||
|  | |||||||
| @ -15,26 +15,26 @@ import ( | |||||||
| 
 | 
 | ||||||
| type StackedBarChart struct { | type StackedBarChart struct { | ||||||
| 	Block | 	Block | ||||||
| 	BarColors   []Color | 	BarColors    []Color | ||||||
| 	LabelStyles []Style | 	LabelStyles  []Style | ||||||
| 	NumStyles   []Style // only Fg and Modifier are used | 	NumStyles    []Style // only Fg and Modifier are used | ||||||
| 	NumFmt      func(float64) string | 	NumFormatter func(float64) string | ||||||
| 	Data        [][]float64 | 	Data         [][]float64 | ||||||
| 	Labels      []string | 	Labels       []string | ||||||
| 	BarWidth    int | 	BarWidth     int | ||||||
| 	BarGap      int | 	BarGap       int | ||||||
| 	MaxVal      float64 | 	MaxVal       float64 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func NewStackedBarChart() *StackedBarChart { | func NewStackedBarChart() *StackedBarChart { | ||||||
| 	return &StackedBarChart{ | 	return &StackedBarChart{ | ||||||
| 		Block:       *NewBlock(), | 		Block:        *NewBlock(), | ||||||
| 		BarColors:   Theme.StackedBarChart.Bars, | 		BarColors:    Theme.StackedBarChart.Bars, | ||||||
| 		LabelStyles: Theme.StackedBarChart.Labels, | 		LabelStyles:  Theme.StackedBarChart.Labels, | ||||||
| 		NumStyles:   Theme.StackedBarChart.Nums, | 		NumStyles:    Theme.StackedBarChart.Nums, | ||||||
| 		NumFmt:      func(n float64) string { return fmt.Sprint(n) }, | 		NumFormatter: func(n float64) string { return fmt.Sprint(n) }, | ||||||
| 		BarGap:      1, | 		BarGap:       1, | ||||||
| 		BarWidth:    3, | 		BarWidth:     3, | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -66,7 +66,7 @@ func (self *StackedBarChart) Draw(buf *Buffer) { | |||||||
| 			// draw number | 			// draw number | ||||||
| 			numberXCoordinate := barXCoordinate + int((float64(self.BarWidth) / 2)) - 1 | 			numberXCoordinate := barXCoordinate + int((float64(self.BarWidth) / 2)) - 1 | ||||||
| 			buf.SetString( | 			buf.SetString( | ||||||
| 				self.NumFmt(data), | 				self.NumFormatter(data), | ||||||
| 				NewStyle( | 				NewStyle( | ||||||
| 					SelectStyle(self.NumStyles, j+1).Fg, | 					SelectStyle(self.NumStyles, j+1).Fg, | ||||||
| 					SelectColor(self.BarColors, j), | 					SelectColor(self.BarColors, j), | ||||||
|  | |||||||
| @ -21,13 +21,13 @@ import ( | |||||||
| */ | */ | ||||||
| type Table struct { | type Table struct { | ||||||
| 	Block | 	Block | ||||||
| 	Rows         [][]string | 	Rows          [][]string | ||||||
| 	ColumnWidths []int | 	ColumnWidths  []int | ||||||
| 	TextStyle    Style | 	TextStyle     Style | ||||||
| 	RowSeparator bool | 	RowSeparator  bool | ||||||
| 	TextAlign    Alignment | 	TextAlignment Alignment | ||||||
| 	RowStyles    map[int]Style | 	RowStyles     map[int]Style | ||||||
| 	FillRow      bool | 	FillRow       bool | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func NewTable() *Table { | func NewTable() *Table { | ||||||
| @ -45,9 +45,9 @@ func (self *Table) Draw(buf *Buffer) { | |||||||
| 	columnWidths := self.ColumnWidths | 	columnWidths := self.ColumnWidths | ||||||
| 	if len(columnWidths) == 0 { | 	if len(columnWidths) == 0 { | ||||||
| 		columnCount := len(self.Rows[0]) | 		columnCount := len(self.Rows[0]) | ||||||
| 		colWidth := self.Inner.Dx() / columnCount | 		columnWidth := self.Inner.Dx() / columnCount | ||||||
| 		for i := 0; i < columnCount; i++ { | 		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++ { | 		for j := 0; j < len(row); j++ { | ||||||
| 			col := ParseStyles(row[j], rowStyle) | 			col := ParseStyles(row[j], rowStyle) | ||||||
| 			// draw row cell | 			// draw row cell | ||||||
| 			if len(col) > columnWidths[j] || self.TextAlign == AlignLeft { | 			if len(col) > columnWidths[j] || self.TextAlignment == AlignLeft { | ||||||
| 				for _, cx := range BuildCellWithXArray(col) { | 				for _, cx := range BuildCellWithXArray(col) { | ||||||
| 					k, cell := cx.X, cx.Cell | 					k, cell := cx.X, cx.Cell | ||||||
| 					if k == columnWidths[j] || colXCoordinate+k == self.Inner.Max.X { | 					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)) | 						buf.SetCell(cell, image.Pt(colXCoordinate+k, yCoordinate)) | ||||||
| 					} | 					} | ||||||
| 				} | 				} | ||||||
| 			} else if self.TextAlign == AlignCenter { | 			} else if self.TextAlignment == AlignCenter { | ||||||
| 				xCoordinateOffset := (columnWidths[j] - len(col)) / 2 | 				xCoordinateOffset := (columnWidths[j] - len(col)) / 2 | ||||||
| 				stringXCoordinate := xCoordinateOffset + colXCoordinate | 				stringXCoordinate := xCoordinateOffset + colXCoordinate | ||||||
| 				for _, cx := range BuildCellWithXArray(col) { | 				for _, cx := range BuildCellWithXArray(col) { | ||||||
| 					k, cell := cx.X, cx.Cell | 					k, cell := cx.X, cx.Cell | ||||||
| 					buf.SetCell(cell, image.Pt(stringXCoordinate+k, yCoordinate)) | 					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) | 				stringXCoordinate := MinInt(colXCoordinate+columnWidths[j], self.Inner.Max.X) - len(col) | ||||||
| 				for _, cx := range BuildCellWithXArray(col) { | 				for _, cx := range BuildCellWithXArray(col) { | ||||||
| 					k, cell := cx.X, cx.Cell | 					k, cell := cx.X, cx.Cell | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ import ( | |||||||
| type TabPane struct { | type TabPane struct { | ||||||
| 	Block | 	Block | ||||||
| 	TabNames         []string | 	TabNames         []string | ||||||
| 	ActiveTabIndex   uint | 	ActiveTabIndex   int | ||||||
| 	ActiveTabStyle   Style | 	ActiveTabStyle   Style | ||||||
| 	InactiveTabStyle Style | 	InactiveTabStyle Style | ||||||
| } | } | ||||||
| @ -37,7 +37,7 @@ func (self *TabPane) FocusLeft() { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (self *TabPane) FocusRight() { | func (self *TabPane) FocusRight() { | ||||||
| 	if self.ActiveTabIndex < uint(len(self.TabNames)-1) { | 	if self.ActiveTabIndex < len(self.TabNames)-1 { | ||||||
| 		self.ActiveTabIndex++ | 		self.ActiveTabIndex++ | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| @ -48,7 +48,7 @@ func (self *TabPane) Draw(buf *Buffer) { | |||||||
| 	xCoordinate := self.Inner.Min.X | 	xCoordinate := self.Inner.Min.X | ||||||
| 	for i, name := range self.TabNames { | 	for i, name := range self.TabNames { | ||||||
| 		ColorPair := self.InactiveTabStyle | 		ColorPair := self.InactiveTabStyle | ||||||
| 		if uint(i) == self.ActiveTabIndex { | 		if i == self.ActiveTabIndex { | ||||||
| 			ColorPair = self.ActiveTabStyle | 			ColorPair = self.ActiveTabStyle | ||||||
| 		} | 		} | ||||||
| 		buf.SetString( | 		buf.SetString( | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user