summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-11-04 08:49:10 -0500
committerPietro Gagliardi <[email protected]>2014-11-04 08:49:10 -0500
commitc5aa4bc964c4c33dd846c932ae0f2b6e4d2413eb (patch)
tree98368bad052ba2dd53fd39f4ac954a9b4e24be9f
parent47600ec08712b6bebeea65270be7067f7bc56882 (diff)
Actually added GTK+ ProgressBar this time.
-rw-r--r--progressbar_unix.go38
1 files changed, 38 insertions, 0 deletions
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)
+}