Added ProgressBar and implemented it on GTK+.

This commit is contained in:
Pietro Gagliardi 2014-11-04 08:48:36 -05:00
parent 4333a1221b
commit 47600ec087
2 changed files with 19 additions and 4 deletions

View File

@ -147,7 +147,6 @@ func NewTextbox() Textbox {
// - TODO set page step? // - TODO set page step?
// - TODO wrapping // - TODO wrapping
// - TODO negative values // - TODO negative values
// - TODO ensuring values entered in text box stay within bounds (OS X seems to take care of this automatically; not sure about Windows or GTK+...)
type Spinbox interface { type Spinbox interface {
Control Control
@ -170,3 +169,19 @@ func NewSpinbox(min int, max int) Spinbox {
} }
return newSpinbox(min, max) return newSpinbox(min, max)
} }
// ProgressBar is a Control that displays a horizontal bar which shows the level of completion of an operation.
type ProgressBar interface {
Control
// Percent and SetPrecent get and set the current percentage indicated by the ProgressBar, respectively.
// This value must be between 0 and 100; all other values cause SetPercent to panic.
Percent() int
SetPercent(percent int)
}
// NewProgressBar creates a new ProgressBar.
// It will initially show a progress of 0%.
func NewProgressBar() ProgressBar {
return newProgressBar()
}

View File

@ -150,11 +150,11 @@ func (tw *testwin) addfe() {
tw.festack.SetStretchy(4) tw.festack.SetStretchy(4)
tw.festack.SetStretchy(6) tw.festack.SetStretchy(6)
sb := NewSpinbox(0, 100) sb := NewSpinbox(0, 100)
sl := NewLabel("") sp := NewProgressBar()
sb.OnChanged(func() { sb.OnChanged(func() {
sl.SetText(fmt.Sprintf("%d", sb.Value())) sp.SetPercent(sb.Value())
}) })
tw.festack2 = newVerticalStack(sb, sl, Space(), Space(), NewTextbox()) tw.festack2 = newVerticalStack(sb, sp, Space(), Space(), NewTextbox())
tw.festack2.SetStretchy(3) tw.festack2.SetStretchy(3)
tw.festack2.SetStretchy(4) tw.festack2.SetStretchy(4)
tw.festack = newHorizontalStack(tw.festack, tw.festack2) tw.festack = newHorizontalStack(tw.festack, tw.festack2)