Added GTK+ implementation of ProgressBar and added a ProgressBar to the test program.

This commit is contained in:
Pietro Gagliardi 2014-02-25 00:48:23 -05:00
parent 23a40cae26
commit d8c0df7993
5 changed files with 88 additions and 42 deletions

View File

@ -189,3 +189,12 @@ func gtk_widget_get_preferred_size(w *gtkWidget) (minWidth int, minHeight int, n
return int(minimum.width), int(minimum.height),
int(natural.width), int(natural.height)
}
func gtk_progress_bar_new() *gtkWidget {
return fromgtkwidget(C.gtk_progress_bar_new())
}
func gtk_progress_bar_set_fraction(w *gtkWidget, percent int) {
p := C.gdouble(percent) / 100
C.gtk_progress_bar_set_fraction(togtkprogressbar(w), p)
}

View File

@ -107,3 +107,11 @@ func fromgtklabel(x *C.GtkLabel) *gtkWidget {
func togtklabel(what *gtkWidget) *C.GtkLabel {
return (*C.GtkLabel)(unsafe.Pointer(what))
}
func fromgtkprogressbar(x *C.GtkProgressBar) *gtkWidget {
return (*gtkWidget)(unsafe.Pointer(x))
}
func togtkprogressbar(what *gtkWidget) *C.GtkProgressBar {
return (*C.GtkProgressBar)(unsafe.Pointer(what))
}

View File

@ -21,7 +21,12 @@ func TestMain(t *testing.T) {
s3 := NewStack(Horizontal, l, b3)
s3.SetStretchy(0)
// s3.SetStretchy(1)
s0 := NewStack(Vertical, s2, c, cb1, cb2, e, s3)
pbar := NewProgressBar()
prog := 0
incButton := NewButton("Inc")
decButton := NewButton("Dec")
sincdec := NewStack(Horizontal, incButton, decButton)
s0 := NewStack(Vertical, s2, c, cb1, cb2, e, s3, pbar, sincdec)
lb1 := NewListbox(true, "Select One", "Or More", "To Continue")
lb2 := NewListbox(false, "Select", "Only", "One", "Please")
i := 0
@ -71,8 +76,19 @@ mainloop:
cb2.SelectedIndex(), cb2.Selection(),
lb1.SelectedIndices(), lb1.Selection(),
lb2.SelectedIndices(), lb2.Selection())
case <-incButton.Clicked:
prog++
if prog > 100 {
prog = 100
}
pbar.SetProgress(prog)
case <-decButton.Clicked:
prog--
if prog < 0 {
prog = 0
}
pbar.SetProgress(prog)
}
}
w.Hide()
}

View File

@ -2,7 +2,7 @@
package ui
import (
// ...
"sync"
)
// A ProgressBar is a horizontal rectangle that fills up from left to right to indicate the progress of a long-running task.

View File

@ -106,6 +106,9 @@ var classTypes = [nctypes]*classData{
smtexts: gListboxSelMultiTexts,
delete: gListboxDelete,
},
c_progressbar: &classData{
make: gtk_progress_bar_new,
},
}
func (s *sysData) make(initText string, window *sysData) error {
@ -287,3 +290,13 @@ func (s *sysData) delete(index int) error {
<-ret
return nil
}
func (s *sysData) setProgress(percent int) {
ret := make(chan struct{})
defer close(ret)
uitask <- func() {
gtk_progress_bar_set_fraction(s.widget, percent)
ret <- struct{}{}
}
<-ret
}