summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--basicctrls_darwin.m29
-rw-r--r--objc_darwin.h3
-rw-r--r--progressbar_darwin.go31
3 files changed, 63 insertions, 0 deletions
diff --git a/basicctrls_darwin.m b/basicctrls_darwin.m
index c4b90c6..873882e 100644
--- a/basicctrls_darwin.m
+++ b/basicctrls_darwin.m
@@ -10,6 +10,7 @@
#define toNSWindow(x) ((NSWindow *) (x))
#define toNSBox(x) ((NSBox *) (x))
#define toNSTextView(x) ((NSTextView *) (x))
+#define toNSProgressIndicator(x) ((NSProgressIndicator *) (x))
@interface goControlDelegate : NSObject <NSTextFieldDelegate> {
@public
@@ -271,3 +272,31 @@ void textboxSetText(id tv, char *text)
{
[toNSTextView(tv) setString:[NSString stringWithUTF8String:text]];
}
+
+id newProgressBar(void)
+{
+ NSProgressIndicator *pi;
+
+ pi = [[NSProgressIndicator alloc] initWithFrame:NSZeroRect];
+ [pi setStyle:NSProgressIndicatorBarStyle];
+ [pi setControlSize:NSRegularControlSize];
+ [pi setControlTint:NSDefaultControlTint];
+ [pi setBezeled:YES];
+ [pi setDisplayedWhenStopped:YES];
+ [pi setUsesThreadedAnimation:YES];
+ [pi setIndeterminate:NO];
+ [pi setMinValue:0];
+ [pi setMaxValue:100];
+ [pi setDoubleValue:0];
+ return (id) pi;
+}
+
+intmax_t progressbarPercent(id pbar)
+{
+ return (intmax_t) [toNSProgressIndicator(pbar) doubleValue];
+}
+
+void progressbarSetPercent(id pbar, intmax_t percent)
+{
+ [toNSProgressIndicator(pbar) setDoubleValue:((double) percent)];
+}
diff --git a/objc_darwin.h b/objc_darwin.h
index 596a83c..7ed69d1 100644
--- a/objc_darwin.h
+++ b/objc_darwin.h
@@ -82,6 +82,9 @@ extern void groupSetText(id, char *);
extern id newTextbox(void);
extern char *textboxText(id);
extern void textboxSetText(id, char *);
+extern id newProgressBar(void);
+extern intmax_t progressbarPercent(id);
+extern void progressbarSetPercent(id, intmax_t);
/* container_darwin.m */
extern id newContainerView(void *);
diff --git a/progressbar_darwin.go b/progressbar_darwin.go
new file mode 100644
index 0000000..51fd41a
--- /dev/null
+++ b/progressbar_darwin.go
@@ -0,0 +1,31 @@
+// 4 november 2014
+
+package ui
+
+import (
+ "fmt"
+)
+
+// #include "objc_darwin.h"
+import "C"
+
+type progressbar struct {
+ *controlSingleObject
+}
+
+func newProgressBar() ProgressBar {
+ return &progressbar{
+ controlSingleObject: newControlSingleObject(C.newProgressBar()),
+ }
+}
+
+func (p *progressbar) Percent() int {
+ return int(C.progressbarPercent(p.id))
+}
+
+func (p *progressbar) SetPercent(percent int) {
+ if percent < 0 || percent > 100 {
+ panic(fmt.Errorf("given ProgressBar percentage %d out of range", percent))
+ }
+ C.progressbarSetPercent(p.id, C.intmax_t(percent))
+}