summaryrefslogtreecommitdiff
path: root/progressbar_unix.go
diff options
context:
space:
mode:
Diffstat (limited to 'progressbar_unix.go')
-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)
+}