Merge Pull #37 into Matt3o12-master

This commit is contained in:
gizak 2015-10-13 14:05:15 -04:00
commit 274f68b371
3 changed files with 29 additions and 11 deletions

View File

@ -56,7 +56,18 @@ func main() {
g3.Label = "{{percent}}% (100MBs free)" g3.Label = "{{percent}}% (100MBs free)"
g3.LabelAlign = termui.AlignRight g3.LabelAlign = termui.AlignRight
termui.Render(g0, g1, g2, g3) g4 := termui.NewGauge()
g4.Percent = 50
g4.Width = 50
g4.Height = 3
g4.Y = 14
g4.Border.Label = "Gauge"
g4.Label = "Gauge with custom highlighted label"
g4.PercentColor = termui.ColorYellow
g4.BarColor = termui.ColorGreen
g4.PercentColorHighlighted = termui.ColorBlack
termui.Render(g0, g1, g2, g3, g4)
<-termui.EventCh() <-termui.EventCh()
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 50 KiB

View File

@ -31,23 +31,27 @@ const (
AlignRight AlignRight
) )
const uint16max = ^uint16(0)
type Gauge struct { type Gauge struct {
Block Block
Percent int Percent int
BarColor Attribute BarColor Attribute
PercentColor Attribute PercentColor Attribute
Label string PercentColorHighlighted Attribute
LabelAlign Align Label string
LabelAlign Align
} }
// NewGauge return a new gauge with current theme. // NewGauge return a new gauge with current theme.
func NewGauge() *Gauge { func NewGauge() *Gauge {
g := &Gauge{ g := &Gauge{
Block: *NewBlock(), Block: *NewBlock(),
PercentColor: theme.GaugePercent, PercentColor: theme.GaugePercent,
BarColor: theme.GaugeBar, BarColor: theme.GaugeBar,
Label: "{{percent}}%", Label: "{{percent}}%",
LabelAlign: AlignCenter, LabelAlign: AlignCenter,
PercentColorHighlighted: Attribute(uint16max),
} }
g.Width = 12 g.Width = 12
@ -104,6 +108,9 @@ func (g *Gauge) Buffer() []Point {
p.Bg |= AttrReverse p.Bg |= AttrReverse
} }
if g.PercentColorHighlighted != Attribute(uint16max) {
p.Fg = g.PercentColorHighlighted
}
} else { } else {
p.Bg = g.Block.BgColor p.Bg = g.Block.BgColor
} }