Actually added GTK+ ProgressBar this time.

This commit is contained in:
Pietro Gagliardi 2014-11-04 08:49:10 -05:00
parent 47600ec087
commit c5aa4bc964
1 changed files with 38 additions and 0 deletions

38
progressbar_unix.go Normal file
View File

@ -0,0 +1,38 @@
// +build !windows,!darwin
// 4 november 2014
package ui
import (
"fmt"
"unsafe"
)
// #include "gtk_unix.h"
import "C"
type progressbar struct {
*controlSingleWidget
pbar *C.GtkProgressBar
}
func newProgressBar() ProgressBar {
widget := C.gtk_progress_bar_new();
p := &progressbar{
controlSingleWidget: newControlSingleWidget(widget),
pbar: (*C.GtkProgressBar)(unsafe.Pointer(widget)),
}
return p
}
func (p *progressbar) Percent() int {
return int(C.gtk_progress_bar_get_fraction(p.pbar) * 100)
}
func (p *progressbar) SetPercent(percent int) {
if percent < 0 || percent > 100 {
panic(fmt.Errorf("given ProgressBar percentage %d out of range", percent))
}
C.gtk_progress_bar_set_fraction(p.pbar, C.gdouble(percent) / 100)
}