From 47600ec08712b6bebeea65270be7067f7bc56882 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 4 Nov 2014 08:48:36 -0500 Subject: [PATCH] Added ProgressBar and implemented it on GTK+. --- basicctrls.go | 17 ++++++++++++++++- zz_test.go | 6 +++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/basicctrls.go b/basicctrls.go index bd82849..dbe9190 100644 --- a/basicctrls.go +++ b/basicctrls.go @@ -147,7 +147,6 @@ func NewTextbox() Textbox { // - TODO set page step? // - TODO wrapping // - 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 { Control @@ -170,3 +169,19 @@ func NewSpinbox(min int, max int) Spinbox { } 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() +} diff --git a/zz_test.go b/zz_test.go index bf11488..bc2865f 100644 --- a/zz_test.go +++ b/zz_test.go @@ -150,11 +150,11 @@ func (tw *testwin) addfe() { tw.festack.SetStretchy(4) tw.festack.SetStretchy(6) sb := NewSpinbox(0, 100) - sl := NewLabel("") + sp := NewProgressBar() 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(4) tw.festack = newHorizontalStack(tw.festack, tw.festack2)