Added support for label align in gauges.

This commit is contained in:
Matteo Kloiber 2015-04-21 17:41:52 +02:00
parent 3968b02432
commit 137d2a7eb2
4 changed files with 29 additions and 4 deletions

View File

@ -1,4 +1,4 @@
# termui [![Build Status](https://travis-ci.org/gizak/termui.svg)](https://travis-ci.org/gizak/termui) [![Doc Status](https://godoc.org/github.com/gizak/termui?status.png)](https://godoc.org/github.com/gizak/termui) # termui [![Build Status](https://travis-ci.org/gizak/termui.svg?branch=master)](https://travis-ci.org/gizak/termui) [![Doc Status](https://godoc.org/github.com/gizak/termui?status.png)](https://godoc.org/github.com/gizak/termui)
--- ---

View File

@ -54,6 +54,7 @@ func main() {
g3.Y = 11 g3.Y = 11
g3.Border.Label = "Gauge with custom label" g3.Border.Label = "Gauge with custom label"
g3.Label = "{{percent}}% (100MBs free)" g3.Label = "{{percent}}% (100MBs free)"
g3.Align = termui.AlignRight
termui.Render(g0, g1, g2, g3) termui.Render(g0, g1, g2, g3)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 32 KiB

View File

@ -20,12 +20,24 @@ import (
g.BarColor = termui.ColorRed g.BarColor = termui.ColorRed
g.PercentColor = termui.ColorBlue g.PercentColor = termui.ColorBlue
*/ */
// Align is the position of the gauge's label.
type Align int
// All supported positions.
const (
AlignLeft Align = iota
AlignCenter
AlignRight
)
type Gauge struct { type Gauge struct {
Block Block
Percent int Percent int
BarColor Attribute BarColor Attribute
PercentColor Attribute PercentColor Attribute
Label string Label string
Align Align
} }
// NewGauge return a new gauge with current theme. // NewGauge return a new gauge with current theme.