From c5aa4bc964c4c33dd846c932ae0f2b6e4d2413eb Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 4 Nov 2014 08:49:10 -0500 Subject: [PATCH] Actually added GTK+ ProgressBar this time. --- progressbar_unix.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 progressbar_unix.go diff --git a/progressbar_unix.go b/progressbar_unix.go new file mode 100644 index 0000000..5cd785a --- /dev/null +++ b/progressbar_unix.go @@ -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) +}